From 10c8d961c4a2fd4722a10f3bb722791f839a4e0a Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 2 Oct 2023 01:38:40 +0200 Subject: [PATCH 1/4] Support new style rules hon#112 --- .github/workflows/python-check.yml | 2 +- pyhon/commands.py | 8 +++++--- pyhon/parameter/base.py | 5 +++-- pyhon/rules.py | 9 +++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python-check.yml b/.github/workflows/python-check.yml index 3d6f17c..00027a2 100644 --- a/.github/workflows/python-check.yml +++ b/.github/workflows/python-check.yml @@ -34,7 +34,7 @@ jobs: mypy pyhon/ - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') + pylint $(git ls-files '*.py') - name: Check black style run: | black . --check diff --git a/pyhon/commands.py b/pyhon/commands.py index b671e55..a305d78 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -102,10 +102,12 @@ class HonCommand: if name == "zoneMap" and self._appliance.zone: data["default"] = self._appliance.zone if data.get("category") == "rule": - if "fixedValue" not in data: - _LOGGER.error("Rule not supported: %s", data) - else: + if "fixedValue" in data: self._rules.append(HonRuleSet(self, data["fixedValue"])) + elif "enumValues" in data: + self._rules.append(HonRuleSet(self, data["enumValues"])) + else: + _LOGGER.warning("Rule not supported: %s", data) match data.get("typology"): case "range": self._parameters[name] = HonParameterRange(name, data, parameter) diff --git a/pyhon/parameter/base.py b/pyhon/parameter/base.py index 4d70051..5d93b29 100644 --- a/pyhon/parameter/base.py +++ b/pyhon/parameter/base.py @@ -68,8 +68,9 @@ class HonParameter: self._triggers.setdefault(value, []).append((func, data)) def check_trigger(self, value: str | float) -> None: - if str(value) in self._triggers: - for trigger in self._triggers[str(value)]: + triggers = {str(k).lower(): v for k, v in self._triggers.items()} + if str(value).lower() in triggers: + for trigger in triggers[str(value)]: func, args = trigger func(args) diff --git a/pyhon/rules.py b/pyhon/rules.py index 57d6de5..4a1a314 100644 --- a/pyhon/rules.py +++ b/pyhon/rules.py @@ -56,6 +56,11 @@ class HonRuleSet: extra[trigger_key] = trigger_value for extra_key, extra_data in param_data.items(): self._parse_conditions(param_key, extra_key, extra_data, extra) + else: + param_data = {"typology": "fixed", "fixedValue": param_data} + self._create_rule( + param_key, trigger_key, trigger_value, param_data, extra + ) def _create_rule( self, @@ -102,6 +107,10 @@ class HonRuleSet: param.values = [str(value)] param.value = str(value) elif isinstance(param, HonParameterRange): + if float(value) < param.min: + param.min = float(value) + elif float(value) > param.max: + param.max = float(value) param.value = float(value) return param.value = str(value) From ffba85bf0dcd9c4ad5caab2f6d9832ed7a51b949 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 2 Oct 2023 01:37:28 +0200 Subject: [PATCH 2/4] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e6a9cf6..19f02b0 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as f: setup( name="pyhOn", - version="0.15.6", + version="0.15.7", author="Andre Basche", description="Control hOn devices with python", long_description=long_description, From 658e80a8f4eb8b240ff581013335619e387d1769 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 2 Oct 2023 03:21:51 +0200 Subject: [PATCH 3/4] Change dependencies to variable major version --- requirements.txt | 6 +++--- setup.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2e9957d..ca541a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -aiohttp~=3.8.5 -yarl~=1.9.2 -typing-extensions~=4.7.1 +aiohttp~=3.8 +yarl~=1.9 +typing-extensions~=4.7 diff --git a/setup.py b/setup.py index 19f02b0..1d057f1 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as f: setup( name="pyhOn", - version="0.15.7", + version="0.15.8", author="Andre Basche", description="Control hOn devices with python", long_description=long_description, @@ -21,7 +21,7 @@ setup( packages=find_packages(), include_package_data=True, python_requires=">=3.10", - install_requires=["aiohttp~=3.8.5", "typing-extensions~=4.7.1", "yarl~=1.9.2"], + install_requires=["aiohttp~=3.8", "typing-extensions~=4.7", "yarl~=1.9"], classifiers=[ "Development Status :: 4 - Beta", "Environment :: Console", From ff8ae160bba9108b9b0774c036bcc7a1a0ccc046 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Fri, 6 Oct 2023 01:28:47 +0200 Subject: [PATCH 4/4] Fix empty prStr --- pyhon/commands.py | 2 ++ pyhon/const.py | 2 +- pyhon/parameter/fixed.py | 2 +- setup.py | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyhon/commands.py b/pyhon/commands.py index a305d78..68df63a 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -139,6 +139,8 @@ class HonCommand: async def send_parameters(self, params: Dict[str, str | float]) -> bool: ancillary_params = self.parameter_groups.get("ancillaryParameters", {}) ancillary_params.pop("programRules", None) + if "prStr" in params: + params["prStr"] = self._category_name.upper() self.appliance.sync_command_to_params(self.name) try: result = await self.api.send_command( diff --git a/pyhon/const.py b/pyhon/const.py index 4f97435..8d1fd26 100644 --- a/pyhon/const.py +++ b/pyhon/const.py @@ -6,7 +6,7 @@ CLIENT_ID = ( "3MVG9QDx8IX8nP5T2Ha8ofvlmjLZl5L_gvfbT9." "HJvpHGKoAS_dcMN8LYpTSYeVFCraUnV.2Ag1Ki7m4znVO6" ) -APP_VERSION = "2.1.2" +APP_VERSION = "2.3.5" OS_VERSION = 31 OS = "android" DEVICE_MODEL = "exynos9820" diff --git a/pyhon/parameter/fixed.py b/pyhon/parameter/fixed.py index 125ecd2..67a3056 100644 --- a/pyhon/parameter/fixed.py +++ b/pyhon/parameter/fixed.py @@ -18,7 +18,7 @@ class HonParameterFixed(HonParameter): @property def value(self) -> str | float: - return self._value if self._value is not None else "0" + return self._value if self._value != "" else "0" @value.setter def value(self, value: str | float) -> None: diff --git a/setup.py b/setup.py index 1d057f1..e12972d 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as f: setup( name="pyhOn", - version="0.15.8", + version="0.15.9", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,