From a081ef1f97408579ad1f2128fe7b06f5a1048349 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 28 May 2023 19:24:02 +0200 Subject: [PATCH] Add favourites to progams hon#47 --- pyhon/appliance.py | 20 ++++++++++++++++++++ pyhon/const.py | 2 +- pyhon/parameter/program.py | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pyhon/appliance.py b/pyhon/appliance.py index 343f2cb..0efd603 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -2,6 +2,7 @@ import importlib 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 @@ -214,8 +215,27 @@ class HonAppliance: 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(): diff --git a/pyhon/const.py b/pyhon/const.py index 37e8601..c7e2c81 100644 --- a/pyhon/const.py +++ b/pyhon/const.py @@ -4,7 +4,7 @@ API_KEY = "GRCqFhC6Gk@ikWXm1RmnSmX1cm,MxY-configuration" 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" diff --git a/pyhon/parameter/program.py b/pyhon/parameter/program.py index bbe2b11..46e7d36 100644 --- a/pyhon/parameter/program.py +++ b/pyhon/parameter/program.py @@ -47,3 +47,6 @@ class HonParameterProgram(HonParameterEnum): if "iot_" not in n and p.parameters.get("prCode") } return dict(sorted(values.items())) + + def set_value(self, value: str): + self._value = value