Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and catch Key error for TRV matching #82

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading