From 91a96f82f24e35a8a92245d887ca97d1dcbacdd1 Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Tue, 7 Jan 2025 23:51:15 +0000 Subject: [PATCH 1/2] update catch for TRV --- pyhiveapi/apyhiveapi/helper/hive_helper.py | 18 +++++++++++------- pyhiveapi/apyhiveapi/session.py | 22 +++++++++++----------- setup.py | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pyhiveapi/apyhiveapi/helper/hive_helper.py b/pyhiveapi/apyhiveapi/helper/hive_helper.py index 2da30d0..9677088 100644 --- a/pyhiveapi/apyhiveapi/helper/hive_helper.py +++ b/pyhiveapi/apyhiveapi/helper/hive_helper.py @@ -81,7 +81,7 @@ def getDeviceData(self, product: dict): Returns: [type]: Device data. """ - device = product + device_id = product["id"] type = product["type"] if type in ("heating", "hotwater"): for aDevice in self.session.data.devices: @@ -91,19 +91,23 @@ def getDeviceData(self, product: dict): product["props"]["zone"] == self.session.data.devices[aDevice]["props"]["zone"] ): - device = self.session.data.devices[aDevice] + device_id = self.session.data.devices[aDevice]["id"] except KeyError: pass elif type == "trvcontrol": - device = self.session.data.devices[product["props"]["trvs"][0]] + trv_present = len(product["props"]["trvs"]) > 0 + if trv_present: + device_id = self.session.data.devices[product["props"]["trvs"][0]]["id"] + else: + raise KeyError elif type == "warmwhitelight" and product["props"]["model"] == "SIREN001": - device = self.session.data.devices[product["parent"]] + device_id = self.session.data.devices[product["parent"]] elif type == "sense": - device = self.session.data.devices[product["parent"]] + device_id = self.session.data.devices[product["parent"]] else: - device = self.session.data.devices[product["id"]] + device_id = self.session.data.devices[product["id"]] - return device + return device_id def convertMinutesToTime(self, minutes_to_convert: str): """Convert minutes string to datetime. diff --git a/pyhiveapi/apyhiveapi/session.py b/pyhiveapi/apyhiveapi/session.py index 25ac508..75e1256 100644 --- a/pyhiveapi/apyhiveapi/session.py +++ b/pyhiveapi/apyhiveapi/session.py @@ -128,15 +128,15 @@ def addList(self, entityType: str, data: dict, **kwargs: dict): Returns: dict: Entity. """ - device = self.helper.getDeviceData(data) - device_name = ( - device["state"]["name"] - if device["state"]["name"] != "Receiver" - else "Heating" - ) - formatted_data = {} - try: + device = self.helper.getDeviceData(data) + device_name = ( + device["state"]["name"] + if device["state"]["name"] != "Receiver" + else "Heating" + ) + formatted_data = {} + formatted_data = { "hiveID": data.get("id", ""), "hiveName": device_name, @@ -154,11 +154,11 @@ def addList(self, entityType: str, data: dict, **kwargs: dict): else: formatted_data["haName"] = device_name formatted_data.update(kwargs) + self.deviceList[entityType].append(formatted_data) + return formatted_data except KeyError as error: self.logger.error(error) - - self.deviceList[entityType].append(formatted_data) - return formatted_data + return None async def updateInterval(self, new_interval: timedelta): """Update the scan interval. diff --git a/setup.py b/setup.py index e3a4769..98df848 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def requirements_from_file(filename="requirements.txt"): setup( - version="0.5.16", + version="0.5.17", package_data={"data": ["*.json"]}, include_package_data=True, cmdclass={ From dd0c9546571a3ec0f06f83d6813dfb25e84e3e7c Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Wed, 8 Jan 2025 00:03:35 +0000 Subject: [PATCH 2/2] fix liniting issue with exception --- pyhiveapi/apyhiveapi/session.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyhiveapi/apyhiveapi/session.py b/pyhiveapi/apyhiveapi/session.py index f1ce3e3..d0dde40 100644 --- a/pyhiveapi/apyhiveapi/session.py +++ b/pyhiveapi/apyhiveapi/session.py @@ -535,10 +535,12 @@ async def createDevices(self): ): continue product_list = PRODUCTS.get(self.data.products[aProduct]["type"], []) + product_name = self.data.products[aProduct]["state"].get("name", "Unknown") for code in product_list: try: eval("self." + code) - except: + except (NameError, AttributeError) as e: + self.log.warning(f"Device {product_name} cannot be setup - {e}") pass if self.data.products[aProduct]["type"] in hive_type: