Skip to content

Commit 939a388

Browse files
committed
Adapt to several primary thermostats
1 parent 3e58098 commit 939a388

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
@@ -826,7 +826,7 @@ def _scan_thermostats(self) -> None:
826826
self._thermo_locs = self._match_locations()
827827

828828
thermo_matching: dict[str, int] = {
829-
"thermostat": 3,
829+
"thermostat": 2,
830830
"zone_thermometer": 2,
831831
"zone_thermostat": 2,
832832
"thermostatic_radiator_valve": 1,
@@ -853,7 +853,7 @@ def _match_locations(self) -> dict[str, ThermoLoc]:
853853
for appliance_details in self.gw_devices.values():
854854
if appliance_details["location"] == location_id:
855855
location_details.update(
856-
{"primary": None, "primary_prio": 0, "secondary": set()}
856+
{"primary": set(), "primary_prio": 0, "secondary": set()}
857857
)
858858
matched_locations[location_id] = location_details
859859

@@ -869,19 +869,21 @@ def _rank_thermostat(
869869
"""Helper-function for _scan_thermostats().
870870
871871
Rank the thermostat based on appliance_details: primary or secondary.
872+
Note: there can be several primary thermostats, then the lowest reported
873+
temperature of a location is used as the reported value.
872874
"""
873875
appl_class = appliance_details["dev_class"]
874876
appl_d_loc = appliance_details["location"]
875877
if loc_id == appl_d_loc and appl_class in thermo_matching:
876878
# Pre-elect new primary
877879
if thermo_matching[appl_class] > self._thermo_locs[loc_id]["primary_prio"]:
878880
# Demote former primary
879-
if (tl_primary:= self._thermo_locs[loc_id]["primary"]) is not None:
881+
if (tl_primary:= self._thermo_locs[loc_id]["primary"]):
880882
self._thermo_locs[loc_id]["secondary"].add(tl_primary)
881883

882884
# Crown primary
883885
self._thermo_locs[loc_id]["primary_prio"] = thermo_matching[appl_class]
884-
self._thermo_locs[loc_id]["primary"] = appliance_id
886+
self._thermo_locs[loc_id]["primary"].add(appliance_id)
885887

886888
else:
887889
self._thermo_locs[loc_id]["secondary"].add(appliance_id)

0 commit comments

Comments
 (0)