Issue with sync_command #16

Merged
VadymMelnychuk merged 20 commits from main into main 2023-10-12 16:43:41 +02:00
3 changed files with 20 additions and 5 deletions

View File

@ -277,7 +277,12 @@ class HonAppliance:
_LOGGER.info("Can't set %s - %s", key, error) _LOGGER.info("Can't set %s - %s", key, error)
continue 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) base: Optional[HonCommand] = self.commands.get(main)
if not base: if not base:
return return
@ -287,7 +292,12 @@ class HonAppliance:
for name, target_param in data.parameters.items(): for name, target_param in data.parameters.items():
if not (base_param := base.parameters.get(name)): 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) self.sync_parameter(base_param, target_param)
def sync_parameter(self, main: Parameter, target: Parameter) -> None: def sync_parameter(self, main: Parameter, target: Parameter) -> None:

View File

@ -1,11 +1,16 @@
from typing import Any, Dict from typing import Any, Dict
from pyhon.appliances.base import ApplianceBase from pyhon.appliances.base import ApplianceBase
from pyhon.parameter.base import HonParameter
class Appliance(ApplianceBase): class Appliance(ApplianceBase):
def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]: def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]:
data = super().attributes(data) 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 return data
def settings(self, settings: Dict[str, Any]) -> Dict[str, Any]:
return settings

View File

@ -132,7 +132,7 @@ class HonCommand:
async def send_specific(self, param_names: List[str]) -> bool: async def send_specific(self, param_names: List[str]) -> bool:
params: Dict[str, str | float] = {} params: Dict[str, str | float] = {}
for key, parameter in self._parameters.items(): for key, parameter in self._parameters.items():
if key in param_names: if key in param_names or parameter.mandatory:
params[key] = parameter.value params[key] = parameter.value
return await self.send_parameters(params) return await self.send_parameters(params)