From 71cf7a1b8a4c3322955e13ab55fa63b02c7f622e Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Tue, 11 Jul 2023 17:13:22 +0300 Subject: [PATCH 1/9] Added water heater appliance. Added ability to send only mandatory parameters --- pyhon/appliances/wh.py | 8 ++++++++ pyhon/commands.py | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 pyhon/appliances/wh.py diff --git a/pyhon/appliances/wh.py b/pyhon/appliances/wh.py new file mode 100644 index 0000000..cc54f29 --- /dev/null +++ b/pyhon/appliances/wh.py @@ -0,0 +1,8 @@ +from typing import Any, Dict + +from pyhon.appliances.base import ApplianceBase + +class Appliance(ApplianceBase): + def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]: + data = super().attributes(data) + data["active"] = data.get("onOffStatus") == 1 \ No newline at end of file diff --git a/pyhon/commands.py b/pyhon/commands.py index a00b123..897d4b4 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -75,6 +75,14 @@ class HonCommand: for name, parameter in self._parameters.items(): result.setdefault(parameter.group, {})[name] = parameter.intern_value return result + + @property + def mandatory_parameter_groups(self) -> Dict[str, Dict[str, Union[str, float]]]: + result: Dict[str, Dict[str, Union[str, float]]] = {} + for name, parameter in self._parameters.items(): + if parameter.mandatory: + result.setdefault(parameter.group, {})[name] = parameter.intern_value + return result @property def parameter_value(self) -> Dict[str, Union[str, float]]: @@ -111,8 +119,9 @@ class HonCommand: name = "program" if "PROGRAM" in self._category_name else "category" self._parameters[name] = HonParameterProgram(name, self, "custom") - async def send(self) -> bool: - params = self.parameter_groups.get("parameters", {}) + async def send(self, onlyMandatory: bool = False) -> bool: + grouped_params = self.mandatory_parameter_groups if onlyMandatory else self.parameter_groups + params = grouped_params.get("parameters", {}) ancillary_params = self.parameter_groups.get("ancillaryParameters", {}) ancillary_params.pop("programRules", None) self.appliance.sync_command_to_params(self.name) -- 2.39.2 From a9fd05f3f5874d1fcbb2b5e38f06bd521ca9d9b1 Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Tue, 11 Jul 2023 17:40:04 +0300 Subject: [PATCH 2/9] fixed build --- pyhon/appliances/wh.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyhon/appliances/wh.py b/pyhon/appliances/wh.py index cc54f29..9016646 100644 --- a/pyhon/appliances/wh.py +++ b/pyhon/appliances/wh.py @@ -5,4 +5,6 @@ from pyhon.appliances.base import ApplianceBase class Appliance(ApplianceBase): def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]: data = super().attributes(data) - data["active"] = data.get("onOffStatus") == 1 \ No newline at end of file + data["active"] = data["parameters"]["onOffStatus"] == "1" + + return data \ No newline at end of file -- 2.39.2 From 7ac2908671f8552b4292696be3908132b90c74c1 Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Tue, 11 Jul 2023 17:49:49 +0300 Subject: [PATCH 3/9] formatting --- pyhon/appliances/wh.py | 2 +- pyhon/commands.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyhon/appliances/wh.py b/pyhon/appliances/wh.py index 9016646..3af1bd0 100644 --- a/pyhon/appliances/wh.py +++ b/pyhon/appliances/wh.py @@ -7,4 +7,4 @@ class Appliance(ApplianceBase): data = super().attributes(data) data["active"] = data["parameters"]["onOffStatus"] == "1" - return data \ No newline at end of file + return data diff --git a/pyhon/commands.py b/pyhon/commands.py index 897d4b4..2132705 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -75,14 +75,14 @@ class HonCommand: for name, parameter in self._parameters.items(): result.setdefault(parameter.group, {})[name] = parameter.intern_value return result - + @property def mandatory_parameter_groups(self) -> Dict[str, Dict[str, Union[str, float]]]: result: Dict[str, Dict[str, Union[str, float]]] = {} for name, parameter in self._parameters.items(): if parameter.mandatory: result.setdefault(parameter.group, {})[name] = parameter.intern_value - return result + return result @property def parameter_value(self) -> Dict[str, Union[str, float]]: -- 2.39.2 From a17692940b4c6fbfd9359dd8bfc438e81b61c470 Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Tue, 11 Jul 2023 18:38:49 +0300 Subject: [PATCH 4/9] cleanup --- pyhon/appliances/wh.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyhon/appliances/wh.py b/pyhon/appliances/wh.py index 3af1bd0..4aa1a3c 100644 --- a/pyhon/appliances/wh.py +++ b/pyhon/appliances/wh.py @@ -2,6 +2,7 @@ from typing import Any, Dict from pyhon.appliances.base import ApplianceBase + class Appliance(ApplianceBase): def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]: data = super().attributes(data) -- 2.39.2 From ecdb976c412bb0fa9b65f90e410ab54308dad874 Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Tue, 11 Jul 2023 18:47:01 +0300 Subject: [PATCH 5/9] cleanup --- pyhon/commands.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyhon/commands.py b/pyhon/commands.py index 2132705..dcc3192 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -82,7 +82,7 @@ class HonCommand: for name, parameter in self._parameters.items(): if parameter.mandatory: result.setdefault(parameter.group, {})[name] = parameter.intern_value - return result + return result @property def parameter_value(self) -> Dict[str, Union[str, float]]: @@ -120,7 +120,8 @@ class HonCommand: self._parameters[name] = HonParameterProgram(name, self, "custom") async def send(self, onlyMandatory: bool = False) -> bool: - grouped_params = self.mandatory_parameter_groups if onlyMandatory else self.parameter_groups + grouped_params = self.mandatory_parameter_groups \ + if onlyMandatory else self.parameter_groups params = grouped_params.get("parameters", {}) ancillary_params = self.parameter_groups.get("ancillaryParameters", {}) ancillary_params.pop("programRules", None) -- 2.39.2 From 68b6b7b24d494f787f05fb436252b0404b077933 Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Wed, 12 Jul 2023 09:47:53 +0300 Subject: [PATCH 6/9] reformatting --- pyhon/commands.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyhon/commands.py b/pyhon/commands.py index dcc3192..85e0988 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -82,7 +82,7 @@ class HonCommand: for name, parameter in self._parameters.items(): if parameter.mandatory: result.setdefault(parameter.group, {})[name] = parameter.intern_value - return result + return result @property def parameter_value(self) -> Dict[str, Union[str, float]]: @@ -120,8 +120,9 @@ class HonCommand: self._parameters[name] = HonParameterProgram(name, self, "custom") async def send(self, onlyMandatory: bool = False) -> bool: - grouped_params = self.mandatory_parameter_groups \ - if onlyMandatory else self.parameter_groups + grouped_params = ( + self.mandatory_parameter_groups if onlyMandatory else self.parameter_groups + ) params = grouped_params.get("parameters", {}) ancillary_params = self.parameter_groups.get("ancillaryParameters", {}) ancillary_params.pop("programRules", None) -- 2.39.2 From 25fa89552deb7e9154f5c5b705668d6601005774 Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Thu, 13 Jul 2023 19:34:49 +0300 Subject: [PATCH 7/9] Added ability to send specific parameters. Useful in case the command has many not mandatory parameters and you want to send only one/few --- pyhon/commands.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyhon/commands.py b/pyhon/commands.py index 85e0988..99c3818 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -124,6 +124,18 @@ class HonCommand: self.mandatory_parameter_groups if onlyMandatory else self.parameter_groups ) params = grouped_params.get("parameters", {}) + return await self.send_parameters(params) + + async def send_specific(self, param_names: List[str]) -> bool: + params: Dict[str, str | float] = {} + + for key, parameter in self._parameters: + if key in param_names: + params[key] = parameter.value + + return await self.send_parameters(params) + + async def send_parameters(self, params: Dict[str, str | float]) -> bool: ancillary_params = self.parameter_groups.get("ancillaryParameters", {}) ancillary_params.pop("programRules", None) self.appliance.sync_command_to_params(self.name) -- 2.39.2 From e575722dd324b3d8dbd8f7721b63328221ffab4f Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Fri, 14 Jul 2023 11:30:17 +0300 Subject: [PATCH 8/9] cleanup --- pyhon/commands.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyhon/commands.py b/pyhon/commands.py index 123362a..fe61129 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -128,11 +128,9 @@ class HonCommand: async def send_specific(self, param_names: List[str]) -> bool: params: Dict[str, str | float] = {} - - for key, parameter in self._parameters: + for key, parameter in self._parameters.items(): if key in param_names: params[key] = parameter.value - return await self.send_parameters(params) async def send_parameters(self, params: Dict[str, str | float]) -> bool: -- 2.39.2 From e2e2fcb6e5615b5f540f40a02611ff00503a56c2 Mon Sep 17 00:00:00 2001 From: Vadym Melnychuk Date: Mon, 17 Jul 2023 10:00:50 +0300 Subject: [PATCH 9/9] Fixed code style --- pyhon/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyhon/commands.py b/pyhon/commands.py index fe61129..cea218b 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -119,9 +119,9 @@ class HonCommand: name = "program" if "PROGRAM" in self._category_name else "category" self._parameters[name] = HonParameterProgram(name, self, "custom") - async def send(self, onlyMandatory: bool = False) -> bool: + async def send(self, only_mandatory: bool = False) -> bool: grouped_params = ( - self.mandatory_parameter_groups if onlyMandatory else self.parameter_groups + self.mandatory_parameter_groups if only_mandatory else self.parameter_groups ) params = grouped_params.get("parameters", {}) return await self.send_parameters(params) -- 2.39.2