From 9971fe95e2bb6599dd72d8060ce44c7aa19db25a Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sat, 20 May 2023 13:24:24 +0200 Subject: [PATCH] Get appliance code from serial number --- pyhon/appliance.py | 7 +++++++ pyhon/connection/api.py | 7 ++++--- setup.py | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pyhon/appliance.py b/pyhon/appliance.py index a518076..cc64d72 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -98,6 +98,13 @@ class HonAppliance: def nick_name(self) -> str: return self._check_name_zone("nickName") + @property + def code(self) -> str: + if code := self.info.get("code"): + return code + serial_number = self.info.get("serialNumber", "") + return serial_number[:8] if len(serial_number) < 18 else serial_number[:11] + @property def commands_options(self): return self._appliance_model.get("options") diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py index aace11a..6583bbf 100644 --- a/pyhon/connection/api.py +++ b/pyhon/connection/api.py @@ -76,18 +76,19 @@ class HonAPI: "macAddress": appliance.mac_address, "os": const.OS, "appVersion": const.APP_VERSION, - "series": appliance.info["series"], + "code": appliance.code, } if firmware_id := appliance.info.get("eepromId"): params["firmwareId"] = firmware_id if firmware_version := appliance.info.get("fwVersion"): params["fwVersion"] = firmware_version - if code := appliance.info.get("code"): - params["code"] = code + if series := appliance.info.get("series"): + params["series"] = series url: str = f"{const.API_URL}/commands/v1/retrieve" async with self._hon.get(url, params=params) as response: result: Dict = (await response.json()).get("payload", {}) if not result or result.pop("resultCode") != "0": + _LOGGER.error(await response.json()) return {} return result diff --git a/setup.py b/setup.py index 1f85329..bff241d 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.10.9", + version="0.10.10", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,