From 36079c3c77bbf51b71a7114be5f26082519040e4 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sat, 8 Apr 2023 04:06:36 +0200 Subject: [PATCH] Add oven and program filter --- pyhon/appliances/ov.py | 16 ++++++++++++++++ pyhon/appliances/td.py | 16 ++++++++-------- pyhon/appliances/wd.py | 16 ++++++++-------- pyhon/appliances/wm.py | 16 ++++++++-------- pyhon/device.py | 6 ++++-- pyhon/parameter.py | 15 ++++++++++++++- setup.py | 2 +- 7 files changed, 59 insertions(+), 28 deletions(-) create mode 100644 pyhon/appliances/ov.py diff --git a/pyhon/appliances/ov.py b/pyhon/appliances/ov.py new file mode 100644 index 0000000..0d3fe18 --- /dev/null +++ b/pyhon/appliances/ov.py @@ -0,0 +1,16 @@ +from pyhon.parameter import HonParameterEnum + + +class Appliance: + def __init__(self): + filters = ["receipt", "standard, special"] + data = {'defaultValue': filters[0], 'enumValues': filters} + self._program_filter = HonParameterEnum("program_filter", data) + + def data(self, data): + return data + + def settings(self, settings): + settings["program_filter"] = self._program_filter + settings["startProgram.program"].filter = self._program_filter.value + return settings diff --git a/pyhon/appliances/td.py b/pyhon/appliances/td.py index be2ce18..8aac4fd 100644 --- a/pyhon/appliances/td.py +++ b/pyhon/appliances/td.py @@ -1,10 +1,10 @@ class Appliance: - def __init__(self, data): - self._data = data + def data(self, data): + if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": + data["attributes"]["parameters"]["machMode"] = "0" + data["active"] = bool(data.get("attributes", {}).get("activity")) + data["pause"] = data["attributes"]["parameters"]["machMode"] == "3" + return data - def get(self): - if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": - self._data["attributes"]["parameters"]["machMode"] = "0" - self._data["active"] = bool(self._data.get("attributes", {}).get("activity")) - self._data["pause"] = self._data["attributes"]["parameters"]["machMode"] == "3" - return self._data + def settings(self, settings): + return settings diff --git a/pyhon/appliances/wd.py b/pyhon/appliances/wd.py index be2ce18..8aac4fd 100644 --- a/pyhon/appliances/wd.py +++ b/pyhon/appliances/wd.py @@ -1,10 +1,10 @@ class Appliance: - def __init__(self, data): - self._data = data + def data(self, data): + if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": + data["attributes"]["parameters"]["machMode"] = "0" + data["active"] = bool(data.get("attributes", {}).get("activity")) + data["pause"] = data["attributes"]["parameters"]["machMode"] == "3" + return data - def get(self): - if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": - self._data["attributes"]["parameters"]["machMode"] = "0" - self._data["active"] = bool(self._data.get("attributes", {}).get("activity")) - self._data["pause"] = self._data["attributes"]["parameters"]["machMode"] == "3" - return self._data + def settings(self, settings): + return settings diff --git a/pyhon/appliances/wm.py b/pyhon/appliances/wm.py index be2ce18..8aac4fd 100644 --- a/pyhon/appliances/wm.py +++ b/pyhon/appliances/wm.py @@ -1,10 +1,10 @@ class Appliance: - def __init__(self, data): - self._data = data + def data(self, data): + if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": + data["attributes"]["parameters"]["machMode"] = "0" + data["active"] = bool(data.get("attributes", {}).get("activity")) + data["pause"] = data["attributes"]["parameters"]["machMode"] == "3" + return data - def get(self): - if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": - self._data["attributes"]["parameters"]["machMode"] = "0" - self._data["active"] = bool(self._data.get("attributes", {}).get("activity")) - self._data["pause"] = self._data["attributes"]["parameters"]["machMode"] == "3" - return self._data + def settings(self, settings): + return settings diff --git a/pyhon/device.py b/pyhon/device.py index 3ee62b5..711b7e1 100644 --- a/pyhon/device.py +++ b/pyhon/device.py @@ -18,7 +18,7 @@ class HonDevice: self._attributes = {} try: - self._extra = importlib.import_module(f'pyhon.appliances.{self.appliance_type.lower()}') + self._extra = importlib.import_module(f'pyhon.appliances.{self.appliance_type.lower()}').Appliance() except ModuleNotFoundError: self._extra = None @@ -124,6 +124,8 @@ class HonDevice: for name, command in self._commands.items(): for key, setting in command.settings.items(): result[f"{name}.{key}"] = setting + if self._extra: + return self._extra.settings(result) return result @property @@ -150,5 +152,5 @@ class HonDevice: result = {"attributes": self.attributes, "appliance": self.appliance, "statistics": self.statistics, **self.parameters} if self._extra: - return result | self._extra.Appliance(result).get() + return self._extra.data(result) return result diff --git a/pyhon/parameter.py b/pyhon/parameter.py index 7f4e1f7..647fb5d 100644 --- a/pyhon/parameter.py +++ b/pyhon/parameter.py @@ -94,7 +94,7 @@ class HonParameterEnum(HonParameter): @property def values(self): - return sorted([str(value) for value in self._values]) + return [str(value) for value in self._values] @property def value(self): @@ -115,6 +115,7 @@ class HonParameterProgram(HonParameterEnum): self._value = command._program self._values = command._multi self._typology = "enum" + self._filter = "" @property def value(self): @@ -126,3 +127,15 @@ class HonParameterProgram(HonParameterEnum): self._command.set_program(value) else: raise ValueError(f"Allowed values {self._values}") + + @property + def filter(self): + return self._filter + + @filter.setter + def filter(self, filter): + self._filter = filter + + @property + def values(self): + return sorted([str(value) for value in self._values if not self._filter or self._filter in str(value)]) diff --git a/setup.py b/setup.py index 47057ea..df6672c 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.4.1", + version="0.5.0", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,