From 7c6ac159016525ec769986078752fdb0cc09850d Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 28 May 2023 06:17:43 +0200 Subject: [PATCH] Add and improve fridge --- pyhon/appliance.py | 9 +++++++++ pyhon/appliances/ref.py | 28 ++++++++++++++++++++++++++++ pyhon/commands.py | 2 +- pyhon/const.py | 2 +- pyhon/parameter/base.py | 5 +++++ pyhon/parameter/range.py | 4 ++-- setup.py | 2 +- 7 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 pyhon/appliances/ref.py diff --git a/pyhon/appliance.py b/pyhon/appliance.py index 6c32347..1464780 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -295,6 +295,15 @@ class HonAppliance: ) return result.replace(self.mac_address, "xx-xx-xx-xx-xx-xx") + def sync_command(self, main, target=None) -> None: + base: HonCommand = self.commands.get(main) + for command, data in self.commands.items(): + if command == main or target and command not in target: + continue + for name, parameter in data.parameters.items(): + if base_value := base.parameters.get(name): + parameter.value = base_value.value + class HonApplianceTest(HonAppliance): def __init__(self, name): diff --git a/pyhon/appliances/ref.py b/pyhon/appliances/ref.py new file mode 100644 index 0000000..bbdd797 --- /dev/null +++ b/pyhon/appliances/ref.py @@ -0,0 +1,28 @@ +from pyhon.parameter.fixed import HonParameterFixed + + +class Appliance: + def __init__(self, appliance): + self.parent = appliance + + def data(self, data): + if data["attributes"]["parameters"]["holidayMode"] == "1": + data["modeZ1"] = "holiday" + elif data["attributes"]["parameters"]["intelligenceMode"] == "1": + data["modeZ1"] = "auto_set" + elif data["attributes"]["parameters"]["quickModeZ1"] == "1": + data["modeZ1"] = "super_cool" + else: + data["modeZ1"] = "no_mode" + + if data["attributes"]["parameters"]["quickModeZ2"] == "1": + data["modeZ2"] = "super_freeze" + elif data["attributes"]["parameters"]["intelligenceMode"] == "1": + data["modeZ2"] = "auto_set" + else: + data["modeZ2"] = "no_mode" + + return data + + def settings(self, settings): + return settings diff --git a/pyhon/commands.py b/pyhon/commands.py index 82a7c6d..ed13a29 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -48,7 +48,7 @@ class HonCommand: @property def api(self) -> "HonAPI": if self._api is None: - raise exceptions.NoAuthenticationException + raise exceptions.NoAuthenticationException("Missing hOn login") return self._api @property diff --git a/pyhon/const.py b/pyhon/const.py index 86749d8..37e8601 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 = "1.53.7" +APP_VERSION = "2.0.9" OS_VERSION = 31 OS = "android" DEVICE_MODEL = "exynos9820" diff --git a/pyhon/parameter/base.py b/pyhon/parameter/base.py index f7b8086..1ef4ee8 100644 --- a/pyhon/parameter/base.py +++ b/pyhon/parameter/base.py @@ -22,6 +22,11 @@ class HonParameter: def value(self) -> str | float: return self._value if self._value is not None else "0" + @value.setter + def value(self, value: str | float) -> None: + self._value = value + self.check_trigger(value) + @property def intern_value(self) -> str | float: return str(self._value) if self._value is not None else "" diff --git a/pyhon/parameter/range.py b/pyhon/parameter/range.py index ec1e376..8f35e97 100644 --- a/pyhon/parameter/range.py +++ b/pyhon/parameter/range.py @@ -37,11 +37,11 @@ class HonParameterRange(HonParameter): return self._step @property - def value(self) -> float: + def value(self) -> str | float: return self._value if self._value is not None else self._min @value.setter - def value(self, value: float) -> None: + def value(self, value: str | float) -> None: value = str_to_float(value) if self._min <= value <= self._max and not (value - self._min) % self._step: self._value = value diff --git a/setup.py b/setup.py index 2bea08b..d2419bd 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.11.1", + version="0.11.2", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,