Skip to content

Commit 6a41486

Browse files
committed
Improve _match_and_rank_thermostats() as suggested
1 parent 33e1e4d commit 6a41486

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

plugwise/helper.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
def extend_plug_device_class(appl: Munch, appliance: etree.Element) -> None:
6161
"""Extend device_class name of Plugs (Plugwise and Aqara) - Pw-Beta Issue #739."""
62-
62+
6363
if (
6464
(search := appliance.find("description")) is not None
6565
and (description := search.text) is not None
@@ -774,8 +774,16 @@ def _match_and_rank_thermostats(self) -> None:
774774
775775
Match thermostat-appliances with locations, rank them for locations with multiple thermostats.
776776
"""
777+
# Build location index
778+
entities_by_location: dict[str, list[tuple[str, GwEntityData]]] = {}
779+
for entity_id, entity in self.gw_entities.items():
780+
if "location" in entity:
781+
loc = entity["location"]
782+
entities_by_location.setdefault(loc, []).append((entity_id, entity))
783+
784+
# Rank thermostats per location
777785
for location_id, location in self._loc_data.items():
778-
for entity_id, entity in self.gw_entities.items():
786+
for entity_id, entity in entities_by_location.get(location_id, []):
779787
self._rank_thermostat(
780788
entity_id, entity, location_id, location, THERMO_MATCHING
781789
)

0 commit comments

Comments
 (0)