Skip to content
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: 6 additions & 12 deletions src/helper/hive_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,14 @@ def get_device_data(self, product: dict):
device = product
product_type = product["type"]
if product_type in ("heating", "hotwater"):
product_zone = product.get("props", {}).get("zone")
for a_device in self.session.data.devices:
if self.session.data.devices[a_device]["type"] in HIVE_TYPES["Thermo"]:
try:
if (
product["props"]["zone"]
== self.session.data.devices[a_device]["props"]["zone"]
):
device = self.session.data.devices[a_device]
except KeyError as e:
_LOGGER.warning(
"get_device_data - KeyError accessing zone data for device %s: %s",
a_device,
str(e),
)
device_zone = (
self.session.data.devices[a_device].get("props", {}).get("zone")
)
if product_zone and device_zone and product_zone == device_zone:
device = self.session.data.devices[a_device]
elif product_type == "trvcontrol":
trv_present = len(product["props"]["trvs"]) > 0
if trv_present:
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/test_remaining_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,42 @@ def test_zone_mismatch_keeps_product_as_device(self):
# The zone mismatch means device was never re-assigned; returns the product
assert result is product

def test_trv_without_zone_does_not_log_warning(self, caplog):
"""TRV devices that omit 'zone' from props are silently skipped (no warning)."""
import logging

helper = HiveHelper(session=MagicMock())
helper.session.data = Map(
{
"devices": {
"trv-1": {
"type": "trv",
"props": {
"online": True
}, # no 'zone' key — current API behaviour
}
},
"products": {},
"actions": {},
"user": {},
"minMax": {},
}
)

product = {
"type": "heating",
"id": "prod-1",
"props": {"zone": "zone-A"},
}

with caplog.at_level(logging.WARNING, logger="apyhiveapi.helper.hive_helper"):
result = helper.get_device_data(product)

assert result is product
assert not caplog.records, (
f"Unexpected warnings: {[r.getMessage() for r in caplog.records]}"
)

def test_zone_match_replaces_device_with_thermostat(self):
"""Matching zones cause device to be replaced with the thermostat entry."""
helper = HiveHelper(session=MagicMock())
Expand Down
Loading