Skip to content

Commit

Permalink
Merge pull request #82 from Pyhass/fix-trv-handling
Browse files Browse the repository at this point in the history
Create and catch Key error for TRV matching
  • Loading branch information
KJonline authored Jan 8, 2025
2 parents ed1cc95 + dd0c954 commit b039a9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
18 changes: 11 additions & 7 deletions pyhiveapi/apyhiveapi/helper/hive_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
26 changes: 14 additions & 12 deletions pyhiveapi/apyhiveapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand Down

0 comments on commit b039a9d

Please sign in to comment.