Sync parameter to settings

This commit is contained in:
Andre Basche 2023-07-01 16:04:34 +02:00
parent a10ab4423e
commit 17d73cdeb8
3 changed files with 26 additions and 5 deletions

View File

@ -103,7 +103,8 @@ class HonAppliance:
@property @property
def brand(self) -> str: def brand(self) -> str:
return self._check_name_zone("brand") brand = self._check_name_zone("brand")
return brand[0].upper() + brand[1:]
@property @property
def nick_name(self) -> str: def nick_name(self) -> str:
@ -165,6 +166,7 @@ class HonAppliance:
self._commands = command_loader.commands self._commands = command_loader.commands
self._additional_data = command_loader.additional_data self._additional_data = command_loader.additional_data
self._appliance_model = command_loader.appliance_data self._appliance_model = command_loader.appliance_data
self.sync_params_to_command("settings")
async def load_attributes(self) -> None: async def load_attributes(self) -> None:
self._attributes = await self.api.load_attributes(self) self._attributes = await self.api.load_attributes(self)
@ -194,6 +196,7 @@ class HonAppliance:
): ):
self._last_update = now self._last_update = now
await self.load_attributes() await self.load_attributes()
self.sync_params_to_command("settings")
@property @property
def command_parameters(self) -> Dict[str, Dict[str, str | float]]: def command_parameters(self) -> Dict[str, Dict[str, str | float]]:
@ -237,15 +240,31 @@ class HonAppliance:
async def data_archive(self, path: Path) -> str: async def data_archive(self, path: Path) -> str:
return await diagnose.zip_archive(self, path, anonymous=True) return await diagnose.zip_archive(self, path, anonymous=True)
def sync_to_params(self, command_name: str) -> None: def sync_command_to_params(self, command_name: str) -> None:
if not (command := self.commands.get(command_name)): if not (command := self.commands.get(command_name)):
return return
for key, value in self.attributes.get("parameters", {}).items(): for key in self.attributes.get("parameters", {}):
if new := command.parameters.get(key): if new := command.parameters.get(key):
self.attributes["parameters"][key].update( self.attributes["parameters"][key].update(
str(new.intern_value), shield=True str(new.intern_value), shield=True
) )
def sync_params_to_command(self, command_name: str) -> None:
if not (command := self.commands.get(command_name)):
return
for key in command.setting_keys:
if (new := self.attributes.get("parameters", {}).get(key)) is None:
continue
setting = command.settings[key]
try:
if not isinstance(setting, HonParameterRange):
command.settings[key].value = str(new.value)
else:
command.settings[key].value = float(new.value)
except ValueError as error:
_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) -> None:
base: Optional[HonCommand] = self.commands.get(main) base: Optional[HonCommand] = self.commands.get(main)
if not base: if not base:

View File

@ -115,7 +115,7 @@ class HonCommand:
params = self.parameter_groups.get("parameters", {}) params = self.parameter_groups.get("parameters", {})
ancillary_params = self.parameter_groups.get("ancillaryParameters", {}) ancillary_params = self.parameter_groups.get("ancillaryParameters", {})
ancillary_params.pop("programRules", None) ancillary_params.pop("programRules", None)
self.appliance.sync_to_params(self.name) self.appliance.sync_command_to_params(self.name)
try: try:
result = await self.api.send_command( result = await self.api.send_command(
self._appliance, self._name, params, ancillary_params self._appliance, self._name, params, ancillary_params

View File

@ -49,7 +49,9 @@ class HonParameterRange(HonParameter):
@value.setter @value.setter
def value(self, value: str | float) -> None: def value(self, value: str | float) -> None:
value = str_to_float(value) value = str_to_float(value)
if self.min <= value <= self.max and not (value - self.min) % self.step: if self.min <= value <= self.max and not ((value - self.min) * 100) % (
self.step * 100
):
self._value = value self._value = value
self.check_trigger(value) self.check_trigger(value)
else: else: