From 0553e6c17dff015a40a9c50ead86f674651dc4c7 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sat, 1 Jul 2023 14:31:37 +0200 Subject: [PATCH] Improvements --- pyhon/__main__.py | 2 +- pyhon/appliance.py | 6 +++--- pyhon/const.py | 2 +- pyhon/diagnose.py | 11 +++++------ pyhon/parameter/enum.py | 2 +- pyhon/parameter/program.py | 2 +- pyhon/parameter/range.py | 4 +++- pyhon/printer.py | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pyhon/__main__.py b/pyhon/__main__.py index 45b028f..ea529c0 100755 --- a/pyhon/__main__.py +++ b/pyhon/__main__.py @@ -99,7 +99,7 @@ async def main() -> None: print(printer.key_print(data)) print( printer.pretty_print( - printer.create_command(device.commands, concat=True) + printer.create_commands(device.commands, concat=True) ) ) else: diff --git a/pyhon/appliance.py b/pyhon/appliance.py index 114a72d..30c460a 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -106,7 +106,7 @@ class HonAppliance: @property def nick_name(self) -> str: result = self._check_name_zone("nickName") - if not result or re.findall("^[xX\s]+$", result): + if not result or re.findall("^[xX1\\s]+$", result): return self.model_name return result @@ -238,12 +238,12 @@ class HonAppliance: if not (command := self.commands.get(command_name)): return for key, value in self.attributes.get("parameters", {}).items(): - if isinstance(value, str) and (new := command.parameters.get(key)): + if new := command.parameters.get(key): self.attributes["parameters"][key].update( str(new.intern_value), shield=True ) - def sync_command(self, main: str, target: Optional[List[str]] = None) -> None: + def sync_command(self, main: str, target: Optional[List[str] | str] = None) -> None: base: Optional[HonCommand] = self.commands.get(main) if not base: return diff --git a/pyhon/const.py b/pyhon/const.py index 73332df..49af0bf 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.10" +APP_VERSION = "2.1.2" OS_VERSION = 31 OS = "android" DEVICE_MODEL = "exynos9820" diff --git a/pyhon/diagnose.py b/pyhon/diagnose.py index 6dd63b2..02ea296 100644 --- a/pyhon/diagnose.py +++ b/pyhon/diagnose.py @@ -89,12 +89,11 @@ def yaml_export(appliance: "HonAppliance", anonymous: bool = False) -> str: if anonymous: for sensible in ["serialNumber", "coords"]: data.get("appliance", {}).pop(sensible, None) - data = { - "data": data, - "commands": printer.create_command(appliance.commands), - "rules": printer.create_rules(appliance.commands), - } - result = printer.pretty_print(data) + result = printer.pretty_print({"data": data}) + if commands := printer.create_commands(appliance.commands): + result += printer.pretty_print({"commands": commands}) + if rules := printer.create_rules(appliance.commands): + result += printer.pretty_print({"rules": rules}) if anonymous: result = anonymize_data(result) return result diff --git a/pyhon/parameter/enum.py b/pyhon/parameter/enum.py index c6b1dd0..9bc4698 100644 --- a/pyhon/parameter/enum.py +++ b/pyhon/parameter/enum.py @@ -41,4 +41,4 @@ class HonParameterEnum(HonParameter): self._value = value self.check_trigger(value) else: - raise ValueError(f"Allowed values {self._values}") + raise ValueError(f"Allowed values: {self._values} But was: {value}") diff --git a/pyhon/parameter/program.py b/pyhon/parameter/program.py index 841a633..2925bd2 100644 --- a/pyhon/parameter/program.py +++ b/pyhon/parameter/program.py @@ -28,7 +28,7 @@ class HonParameterProgram(HonParameterEnum): if value in self.values: self._command.category = value else: - raise ValueError(f"Allowed values {self.values}") + raise ValueError(f"Allowed values: {self.values} But was: {value}") @property def values(self) -> List[str]: diff --git a/pyhon/parameter/range.py b/pyhon/parameter/range.py index 5928369..e4077d7 100644 --- a/pyhon/parameter/range.py +++ b/pyhon/parameter/range.py @@ -53,7 +53,9 @@ class HonParameterRange(HonParameter): self._value = value self.check_trigger(value) else: - raise ValueError(f"Allowed: min {self.min} max {self.max} step {self.step}") + raise ValueError( + f"Allowed: min {self.min} max {self.max} step {self.step} But was: {value}" + ) @property def values(self) -> List[str]: diff --git a/pyhon/printer.py b/pyhon/printer.py index ca7190e..395c531 100644 --- a/pyhon/printer.py +++ b/pyhon/printer.py @@ -59,7 +59,7 @@ def pretty_print( return result -def create_command( +def create_commands( commands: Dict[str, "HonCommand"], concat: bool = False ) -> Dict[str, Any]: result: Dict[str, Any] = {}