Skip to content

Commit

Permalink
Get appliance code from serial number
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed May 20, 2023
1 parent 9f130e2 commit 9971fe9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pyhon/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ def model_name(self) -> str:
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")
Expand Down
7 changes: 4 additions & 3 deletions pyhon/connection/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ async def load_commands(self, appliance: HonAppliance) -> Dict:
"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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="pyhOn",
version="0.10.9",
version="0.10.10",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,
Expand Down

0 comments on commit 9971fe9

Please sign in to comment.