mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-11-13 18:00:47 +01:00
Sync parameter to settings
This commit is contained in:
parent
a10ab4423e
commit
17d73cdeb8
@ -103,7 +103,8 @@ class HonAppliance:
|
||||
|
||||
@property
|
||||
def brand(self) -> str:
|
||||
return self._check_name_zone("brand")
|
||||
brand = self._check_name_zone("brand")
|
||||
return brand[0].upper() + brand[1:]
|
||||
|
||||
@property
|
||||
def nick_name(self) -> str:
|
||||
@ -165,6 +166,7 @@ class HonAppliance:
|
||||
self._commands = command_loader.commands
|
||||
self._additional_data = command_loader.additional_data
|
||||
self._appliance_model = command_loader.appliance_data
|
||||
self.sync_params_to_command("settings")
|
||||
|
||||
async def load_attributes(self) -> None:
|
||||
self._attributes = await self.api.load_attributes(self)
|
||||
@ -194,6 +196,7 @@ class HonAppliance:
|
||||
):
|
||||
self._last_update = now
|
||||
await self.load_attributes()
|
||||
self.sync_params_to_command("settings")
|
||||
|
||||
@property
|
||||
def command_parameters(self) -> Dict[str, Dict[str, str | float]]:
|
||||
@ -237,15 +240,31 @@ class HonAppliance:
|
||||
async def data_archive(self, path: Path) -> str:
|
||||
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)):
|
||||
return
|
||||
for key, value in self.attributes.get("parameters", {}).items():
|
||||
for key in self.attributes.get("parameters", {}):
|
||||
if new := command.parameters.get(key):
|
||||
self.attributes["parameters"][key].update(
|
||||
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:
|
||||
base: Optional[HonCommand] = self.commands.get(main)
|
||||
if not base:
|
||||
|
@ -115,7 +115,7 @@ class HonCommand:
|
||||
params = self.parameter_groups.get("parameters", {})
|
||||
ancillary_params = self.parameter_groups.get("ancillaryParameters", {})
|
||||
ancillary_params.pop("programRules", None)
|
||||
self.appliance.sync_to_params(self.name)
|
||||
self.appliance.sync_command_to_params(self.name)
|
||||
try:
|
||||
result = await self.api.send_command(
|
||||
self._appliance, self._name, params, ancillary_params
|
||||
|
@ -49,7 +49,9 @@ class HonParameterRange(HonParameter):
|
||||
@value.setter
|
||||
def value(self, value: str | float) -> None:
|
||||
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.check_trigger(value)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user