Skip to content

Commit 4e89c86

Browse files
committed
Improve
1 parent 5983efb commit 4e89c86

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

plugwise/helper.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,19 +898,22 @@ def _rank_thermostat(
898898
"""
899899
appl_class = appliance_details["dev_class"]
900900
appl_d_loc = appliance_details["location"]
901+
thermo_loc = self._thermo_locs[loc_id]
901902
if loc_id == appl_d_loc and appl_class in thermo_matching:
903+
if thermo_matching[appl_class] == thermo_loc["primary_prio"]:
904+
thermo_loc["primary"].append(appliance_id)
902905
# Pre-elect new primary
903-
if thermo_matching[appl_class] > self._thermo_locs[loc_id]["primary_prio"]:
906+
elif (thermo_rank := thermo_matching[appl_class]) > thermo_loc["primary_prio"]:
907+
thermo_loc["primary_prio"] = thermo_rank
904908
# Demote former primary
905-
if (tl_primary := self._thermo_locs[loc_id]["primary"]):
906-
self._thermo_locs[loc_id]["secondary"] = tl_primary
907-
self._thermo_locs[loc_id]["primary"] = []
909+
if (tl_primary := thermo_loc["primary"]):
910+
thermo_loc["secondary"] += tl_primary
911+
thermo_loc["primary"] = []
908912

909913
# Crown primary
910-
self._thermo_locs[loc_id]["primary_prio"] = thermo_matching[appl_class]
911-
self._thermo_locs[loc_id]["primary"].append(appliance_id)
914+
thermo_loc["primary"].append(appliance_id)
912915
else:
913-
self._thermo_locs[loc_id]["secondary"].append(appliance_id)
916+
thermo_loc["secondary"].append(appliance_id)
914917

915918
def _control_state(self, loc_id: str) -> str | bool:
916919
"""Helper-function for _get_adam_data().

0 commit comments

Comments
 (0)