mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-01-19 02:50:44 +00:00
Restore last command parameters
This commit is contained in:
parent
fc8c92d538
commit
ef4f7f7398
|
@ -84,6 +84,14 @@ class HonConnection:
|
||||||
return {}
|
return {}
|
||||||
return result
|
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):
|
async def load_attributes(self, device: HonDevice, loop=False):
|
||||||
params = {
|
params = {
|
||||||
"macAddress": device.mac_address,
|
"macAddress": device.mac_address,
|
||||||
|
|
|
@ -3,7 +3,7 @@ API_URL = "https://api-iot.he.services"
|
||||||
APP = "hon"
|
APP = "hon"
|
||||||
# All seen id's (different accounts, different devices) are the same, so I guess this hash is static
|
# 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"
|
CLIENT_ID = "3MVG9QDx8IX8nP5T2Ha8ofvlmjLZl5L_gvfbT9.HJvpHGKoAS_dcMN8LYpTSYeVFCraUnV.2Ag1Ki7m4znVO6"
|
||||||
APP_VERSION = "1.51.9"
|
APP_VERSION = "1.53.7"
|
||||||
OS_VERSION = 31
|
OS_VERSION = 31
|
||||||
OS = "android"
|
OS = "android"
|
||||||
DEVICE_MODEL = "exynos9820"
|
DEVICE_MODEL = "exynos9820"
|
||||||
|
|
|
@ -81,6 +81,20 @@ class HonDevice:
|
||||||
def appliance(self):
|
def appliance(self):
|
||||||
return self._appliance
|
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):
|
async def load_commands(self):
|
||||||
raw = await self._connector.load_commands(self)
|
raw = await self._connector.load_commands(self)
|
||||||
self._appliance_model = raw.pop("applianceModel")
|
self._appliance_model = raw.pop("applianceModel")
|
||||||
|
@ -98,6 +112,7 @@ class HonDevice:
|
||||||
multi[program] = cmd
|
multi[program] = cmd
|
||||||
commands[command] = cmd
|
commands[command] = cmd
|
||||||
self._commands = commands
|
self._commands = commands
|
||||||
|
await self._recover_last_command_states(commands)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def settings(self):
|
def settings(self):
|
||||||
|
|
Loading…
Reference in a new issue