Skip to content

Commit ba0e307

Browse files
committed
Add existing/new detection for zones
1 parent 4d61588 commit ba0e307

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

plugwise/helper.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ def __init__(self) -> None:
8787
super().__init__()
8888
self._existing_appliances: list[str] = []
8989
self._existing_locations: list[str] = []
90+
self._existing_zones: list[str] = []
9091
self._new_appliances: list[str] = []
9192
self._new_locations: list[str] = []
93+
self._new_zones: list[str] = []
9294
self._endpoint: str
9395
self._elga: bool
9496
self._is_thermostat: bool
@@ -821,9 +823,14 @@ def _scan_thermostats(self) -> None:
821823
return
822824

823825
self._match_and_rank_thermostats()
824-
for location_id in self._new_locations:
825-
location = self._loc_data[location_id]
826+
# for location_id in self._new_locations:
827+
# location = self._loc_data[location_id]
828+
for location_id, location in self._loc_data.items():
826829
if location["primary_prio"] != 0:
830+
self._new_zones.append(location_id)
831+
if location_id in self._existing_zones:
832+
continue
833+
827834
self._zones[location_id] = {
828835
"dev_class": "climate",
829836
"model": "ThermoZone",
@@ -836,7 +843,15 @@ def _scan_thermostats(self) -> None:
836843
}
837844
self._count += 5
838845

839-
def _match_and_rank_thermostats(self) -> None:
846+
removed = list(set(self._existing_zones) - set(self._new_zones))
847+
if self._existing_zones and removed:
848+
for location_id in removed:
849+
self._zones.pop(location_id)
850+
851+
self._existing_zones = self._new_zones
852+
self._new_zones = []
853+
854+
def _match_and_rank_thermostats(self) -> dict[str, ThermoLoc]:
840855
"""Helper-function for _scan_thermostats().
841856
842857
Match thermostat-appliances with locations, rank them for locations with multiple thermostats.

0 commit comments

Comments
 (0)