Skip to content

Commit 1f466d1

Browse files
committed
Improve
1 parent 373c9ce commit 1f466d1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

plugwise/helper.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,19 +898,20 @@ 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:
902903
# Pre-elect new primary
903-
if thermo_matching[appl_class] > self._thermo_locs[loc_id]["primary_prio"]:
904+
if (thermo_rank := thermo_matching[appl_class]) > thermo_loc["primary_prio"]:
905+
thermo_loc["primary_prio"] = thermo_rank
904906
# 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"] = []
907+
if (tl_primary := thermo_loc["primary"]):
908+
thermo_loc["secondary"].append(tl_primary)
909+
thermo_loc["primary"].remove(tl_primary)
908910

909911
# Crown primary
910-
self._thermo_locs[loc_id]["primary_prio"] = thermo_matching[appl_class]
911-
self._thermo_locs[loc_id]["primary"].append(appliance_id)
912+
thermo_loc["primary"].append(appliance_id)
912913
else:
913-
self._thermo_locs[loc_id]["secondary"].append(appliance_id)
914+
thermo_loc["secondary"].append(appliance_id)
914915

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

0 commit comments

Comments
 (0)