Skip to content

Commit 60366cd

Browse files
committed
Add existing/new detection for zones
1 parent 81db388 commit 60366cd

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

plugwise/helper.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def __init__(self) -> None:
7575
super().__init__()
7676
self._existing_appliances: list[str] = []
7777
self._existing_locations: list[str] = []
78+
self._existing_zones: list[str] = []
7879
self._new_appliances: list[str] = []
7980
self._new_locations: list[str] = []
81+
self._new_zones: list[str] = []
8082
self._endpoint: str
8183
self._elga: bool
8284
self._is_thermostat: bool
@@ -794,9 +796,14 @@ def _scan_thermostats(self) -> None:
794796
the result to update the device_class of secondary thermostats.
795797
"""
796798
self._match_and_rank_thermostats()
797-
for location_id in self._new_locations:
798-
location = self._loc_data[location_id]
799+
# for location_id in self._new_locations:
800+
# location = self._loc_data[location_id]
801+
for location_id, location in self._loc_data.items():
799802
if location["primary_prio"] != 0:
803+
self._new_zones.append(location_id)
804+
if location_id in self._existing_zones:
805+
continue
806+
800807
self._zones[location_id] = {
801808
"dev_class": "climate",
802809
"model": "ThermoZone",
@@ -809,6 +816,14 @@ def _scan_thermostats(self) -> None:
809816
}
810817
self._count += 5
811818

819+
removed = list(set(self._existing_zones) - set(self._new_zones))
820+
if self._existing_zones and removed:
821+
for location_id in removed:
822+
self._zones.pop(location_id)
823+
824+
self._existing_zones = self._new_zones
825+
self._new_zones = []
826+
812827
def _match_and_rank_thermostats(self) -> dict[str, ThermoLoc]:
813828
"""Helper-function for _scan_thermostats().
814829
@@ -820,8 +835,9 @@ def _match_and_rank_thermostats(self) -> dict[str, ThermoLoc]:
820835
"zone_thermostat": 2,
821836
"thermostatic_radiator_valve": 1,
822837
}
823-
for location_id in self._new_locations:
824-
location = self._loc_data[location_id]
838+
# for location_id in self._new_locations:
839+
# location = self._loc_data[location_id]
840+
for location_id, location in self._loc_data.items():
825841
location.update({"primary": [], "primary_prio": 0, "secondary": []})
826842
for entity_id, entity in self.gw_entities.items():
827843
self._rank_thermostat(

0 commit comments

Comments
 (0)