Skip to content

Commit 52df225

Browse files
committed
Adapt to several primary thermostats
1 parent a41bdb2 commit 52df225

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

plugwise/helper.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def _scan_thermostats(self) -> None:
801801
self._thermo_locs = self._match_locations()
802802

803803
thermo_matching: dict[str, int] = {
804-
"thermostat": 3,
804+
"thermostat": 2,
805805
"zone_thermometer": 2,
806806
"zone_thermostat": 2,
807807
"thermostatic_radiator_valve": 1,
@@ -828,7 +828,7 @@ def _match_locations(self) -> dict[str, ThermoLoc]:
828828
for appliance_details in self.gw_devices.values():
829829
if appliance_details["location"] == location_id:
830830
location_details.update(
831-
{"primary": None, "primary_prio": 0, "secondary": set()}
831+
{"primary": set(), "primary_prio": 0, "secondary": set()}
832832
)
833833
matched_locations[location_id] = location_details
834834

@@ -844,19 +844,21 @@ def _rank_thermostat(
844844
"""Helper-function for _scan_thermostats().
845845
846846
Rank the thermostat based on appliance_details: primary or secondary.
847+
Note: there can be several primary thermostats, then the lowest reported
848+
temperature of a location is used as the reported value.
847849
"""
848850
appl_class = appliance_details["dev_class"]
849851
appl_d_loc = appliance_details["location"]
850852
if loc_id == appl_d_loc and appl_class in thermo_matching:
851853
# Pre-elect new primary
852854
if thermo_matching[appl_class] > self._thermo_locs[loc_id]["primary_prio"]:
853855
# Demote former primary
854-
if (tl_primary:= self._thermo_locs[loc_id]["primary"]) is not None:
856+
if (tl_primary:= self._thermo_locs[loc_id]["primary"]):
855857
self._thermo_locs[loc_id]["secondary"].add(tl_primary)
856858

857859
# Crown primary
858860
self._thermo_locs[loc_id]["primary_prio"] = thermo_matching[appl_class]
859-
self._thermo_locs[loc_id]["primary"] = appliance_id
861+
self._thermo_locs[loc_id]["primary"].add(appliance_id)
860862

861863
else:
862864
self._thermo_locs[loc_id]["secondary"].add(appliance_id)

0 commit comments

Comments
 (0)