sync_command - fixed typos, skip to sync(actually reset) parameters of different types. Improved WaterHeater appliance

This commit is contained in:
Vadym Melnychuk 2023-07-24 16:16:07 +03:00
parent 3d8011deea
commit 8a876d953a
2 changed files with 8 additions and 7 deletions

View File

@ -13,6 +13,7 @@ from pyhon.commands import HonCommand
from pyhon.parameter.base import HonParameter
from pyhon.parameter.enum import HonParameterEnum
from pyhon.parameter.range import HonParameterRange
from pyhon.parameter.fixed import HonParameterFixed
from pyhon.typedefs import Parameter
if TYPE_CHECKING:
@ -287,7 +288,7 @@ class HonAppliance:
for name, target_param in data.parameters.items():
if not (base_param := base.parameters.get(name)):
return
continue
self.sync_parameter(base_param, target_param)
def sync_parameter(self, main: Parameter, target: Parameter) -> None:
@ -297,10 +298,6 @@ class HonAppliance:
target.max = main.max
target.min = main.min
target.step = main.step
elif isinstance(target, HonParameterRange):
target.max = int(main.value)
target.min = int(main.value)
target.step = 1
elif isinstance(target, HonParameterEnum):
target.values = main.values
target.value = main.value

View File

@ -1,11 +1,15 @@
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"]
data["active"] = parameter.value == 1 if isinstance(parameter, HonParameter) else parameter == 1
return data
def settings(self, settings: Dict[str, Any]) -> Dict[str, Any]:
return settings