Skip to content

Commit

Permalink
Add favourites to progams hon#47
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed May 28, 2023
1 parent 4888f2b commit a081ef1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions pyhon/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
from contextlib import suppress
from copy import copy
from datetime import datetime, timedelta
from pathlib import Path
from typing import Optional, Dict, Any
Expand Down Expand Up @@ -214,8 +215,27 @@ async def load_commands(self):
self._appliance_model = raw.pop("applianceModel")
raw.pop("dictionaryId", None)
self._commands = self._get_commands(raw)
await self._add_favourites()
await self._recover_last_command_states()

async def _add_favourites(self):
favourites = await self._api.command_favourites(self)
for favourite in favourites:
name = favourite.get("favouriteName")
command = favourite.get("command")
command_name = command.get("commandName")
program_name = command.get("programName", "").split(".")[-1].lower()
base = copy(self._commands[command_name].categories[program_name])
for param, data in command.items():
if isinstance(data, str):
continue
for key, value in data.items():
if parameter := base.parameters.get(key):
with suppress(ValueError):
parameter.value = value
base.parameters["program"].set_value(name)
self._commands[command_name].categories[name] = base

async def load_attributes(self):
self._attributes = await self.api.load_attributes(self)
for name, values in self._attributes.pop("shadow").get("parameters").items():
Expand Down
2 changes: 1 addition & 1 deletion pyhon/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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 = "2.0.9"
APP_VERSION = "2.0.10"
OS_VERSION = 31
OS = "android"
DEVICE_MODEL = "exynos9820"
Expand Down
3 changes: 3 additions & 0 deletions pyhon/parameter/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ def ids(self) -> Dict[int, str]:
if "iot_" not in n and p.parameters.get("prCode")
}
return dict(sorted(values.items()))

def set_value(self, value: str):
self._value = value

0 comments on commit a081ef1

Please sign in to comment.