From 6ae40481e32ed8f76f20d5115237e00e9a49f51c Mon Sep 17 00:00:00 2001 From: Vadym Date: Thu, 12 Oct 2023 17:43:41 +0300 Subject: [PATCH] Issue with sync_command (#16) * Added water heater appliance. Added ability to send only mandatory parameters * fixed build * formatting * cleanup * cleanup * reformatting * Added ability to send specific parameters. Useful in case the command has many not mandatory parameters and you want to send only one/few * cleanup * Fixed code style * sync_command - fixed typos, skip to sync(actually reset) parameters of different types. Improved WaterHeater appliance * cleanup * cleanup * clean code style * check if base parameter is mandatory * Reverted back sync_command, send mandatory parameters beside with specified --------- Co-authored-by: Vadym Melnychuk --- pyhon/appliance.py | 14 ++++++++++++-- pyhon/appliances/wh.py | 9 +++++++-- pyhon/commands.py | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pyhon/appliance.py b/pyhon/appliance.py index 996c463..4a2d07c 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -277,7 +277,12 @@ class HonAppliance: _LOGGER.info("Can't set %s - %s", key, error) continue - def sync_command(self, main: str, target: Optional[List[str] | str] = None) -> None: + def sync_command( + self, + main: str, + target: Optional[List[str] | str] = None, + to_sync: Optional[List[str] | bool] = None, + ) -> None: base: Optional[HonCommand] = self.commands.get(main) if not base: return @@ -287,7 +292,12 @@ class HonAppliance: for name, target_param in data.parameters.items(): if not (base_param := base.parameters.get(name)): - return + continue + if to_sync and ( + (isinstance(to_sync, list) and name not in to_sync) + or not base_param.mandatory + ): + continue self.sync_parameter(base_param, target_param) def sync_parameter(self, main: Parameter, target: Parameter) -> None: diff --git a/pyhon/appliances/wh.py b/pyhon/appliances/wh.py index 4aa1a3c..7e92ca8 100644 --- a/pyhon/appliances/wh.py +++ b/pyhon/appliances/wh.py @@ -1,11 +1,16 @@ from typing import Any, Dict from pyhon.appliances.base import ApplianceBase +from pyhon.parameter.base import HonParameter class Appliance(ApplianceBase): def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]: data = super().attributes(data) - data["active"] = data["parameters"]["onOffStatus"] == "1" - + parameter = data["parameters"]["onOffStatus"] + is_class = isinstance(parameter, HonParameter) + data["active"] = parameter.value == 1 if is_class else parameter == 1 return data + + def settings(self, settings: Dict[str, Any]) -> Dict[str, Any]: + return settings diff --git a/pyhon/commands.py b/pyhon/commands.py index 68df63a..8c0275a 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -132,7 +132,7 @@ class HonCommand: async def send_specific(self, param_names: List[str]) -> bool: params: Dict[str, str | float] = {} for key, parameter in self._parameters.items(): - if key in param_names: + if key in param_names or parameter.mandatory: params[key] = parameter.value return await self.send_parameters(params)