mirror of
https://github.com/Andre0512/pyhOn.git
synced 2025-05-16 08:04:25 -04:00
Restore last command parameters
This commit is contained in:
parent
fc8c92d538
commit
ef4f7f7398
3 changed files with 24 additions and 1 deletions
|
@ -81,6 +81,20 @@ class HonDevice:
|
|||
def appliance(self):
|
||||
return self._appliance
|
||||
|
||||
async def _recover_last_command_states(self, commands):
|
||||
command_history = await self._connector.command_history(self)
|
||||
for name, command in commands.items():
|
||||
last = next((index for (index, d) in enumerate(command_history) if d.get("command", {}).get("commandName") == name), None)
|
||||
if last is None:
|
||||
continue
|
||||
parameters = command_history[last].get("command", {}).get("parameters", {})
|
||||
if command._multi and parameters.get("program"):
|
||||
command.set_program(parameters.pop("program").split(".")[-1].lower())
|
||||
command = self.commands[name]
|
||||
for key, data in command.settings.items():
|
||||
if parameters.get(key) is not None:
|
||||
data.value = parameters.get(key)
|
||||
|
||||
async def load_commands(self):
|
||||
raw = await self._connector.load_commands(self)
|
||||
self._appliance_model = raw.pop("applianceModel")
|
||||
|
@ -98,6 +112,7 @@ class HonDevice:
|
|||
multi[program] = cmd
|
||||
commands[command] = cmd
|
||||
self._commands = commands
|
||||
await self._recover_last_command_states(commands)
|
||||
|
||||
@property
|
||||
def settings(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue