From af4fbdd8cdcc41c55799bcc941cb5ec00ec8b55c Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Tue, 16 May 2023 20:44:48 +0200 Subject: [PATCH] Make 'code' attribute optional, fix hon#51 --- pyhon/connection/api.py | 2 ++ pyhon/hon.py | 21 ++++++++++++++------- setup.py | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pyhon/connection/api.py b/pyhon/connection/api.py index 26038ca..4e5fc6d 100644 --- a/pyhon/connection/api.py +++ b/pyhon/connection/api.py @@ -83,6 +83,8 @@ class HonAPI: params["firmwareId"] = firmware_id if firmware_version := appliance.info.get("fwVersion"): params["fwVersion"] = firmware_version + if code := appliance.info.get("code"): + params["code"] = code 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", {}) diff --git a/pyhon/hon.py b/pyhon/hon.py index e7b5e9b..31fa275 100644 --- a/pyhon/hon.py +++ b/pyhon/hon.py @@ -1,4 +1,5 @@ import asyncio +import logging from types import TracebackType from typing import List, Optional, Dict, Any, Type @@ -8,6 +9,8 @@ from typing_extensions import Self from pyhon import HonAPI, exceptions from pyhon.appliance import HonAppliance +_LOGGER = logging.getLogger(__name__) + class Hon: def __init__( @@ -70,13 +73,17 @@ class Hon: appliance = HonAppliance(self._api, appliance_data, zone=zone) if appliance.mac_address == "": return - await asyncio.gather( - *[ - appliance.load_attributes(), - appliance.load_commands(), - appliance.load_statistics(), - ] - ) + try: + await asyncio.gather( + *[ + appliance.load_attributes(), + appliance.load_commands(), + appliance.load_statistics(), + ] + ) + except (KeyError, ValueError, IndexError) as error: + _LOGGER.exception(error) + _LOGGER.error(f"Device data - %s", appliance_data) self._appliances.append(appliance) async def setup(self) -> None: diff --git a/setup.py b/setup.py index f02e547..ce11516 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.10.6", + version="0.10.7", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,