Restore last command parameters
This commit is contained in:
parent
fc8c92d538
commit
ef4f7f7398
3 changed files with 24 additions and 1 deletions
|
@ -84,6 +84,14 @@ class HonConnection:
|
|||
return {}
|
||||
return result
|
||||
|
||||
async def command_history(self, device: HonDevice):
|
||||
url = f"{const.API_URL}/commands/v1/appliance/{device.mac_address}/history"
|
||||
async with self._session.get(url, headers=await self._headers) as response:
|
||||
result = await response.json()
|
||||
if not result or not result.get("payload"):
|
||||
return {}
|
||||
return result["payload"]["history"]
|
||||
|
||||
async def load_attributes(self, device: HonDevice, loop=False):
|
||||
params = {
|
||||
"macAddress": device.mac_address,
|
||||
|
|
|
@ -3,7 +3,7 @@ API_URL = "https://api-iot.he.services"
|
|||
APP = "hon"
|
||||
# All seen id's (different accounts, different devices) are the same, so I guess this hash is static
|
||||
CLIENT_ID = "3MVG9QDx8IX8nP5T2Ha8ofvlmjLZl5L_gvfbT9.HJvpHGKoAS_dcMN8LYpTSYeVFCraUnV.2Ag1Ki7m4znVO6"
|
||||
APP_VERSION = "1.51.9"
|
||||
APP_VERSION = "1.53.7"
|
||||
OS_VERSION = 31
|
||||
OS = "android"
|
||||
DEVICE_MODEL = "exynos9820"
|
||||
|
|
|
@ -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…
Reference in a new issue