Skip to content

Commit 6bb2c00

Browse files
committed
Add existing/new detection for zones
1 parent 3998bd0 commit 6bb2c00

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
@@ -792,9 +794,14 @@ def _scan_thermostats(self) -> None:
792794
the result to update the device_class of secondary thermostats.
793795
"""
794796
self._match_and_rank_thermostats()
795-
for location_id in self._new_locations:
796-
location = self._loc_data[location_id]
797+
# for location_id in self._new_locations:
798+
# location = self._loc_data[location_id]
799+
for location_id, location in self._loc_data.items():
797800
if location["primary_prio"] != 0:
801+
self._new_zones.append(location_id)
802+
if location_id in self._existing_zones:
803+
continue
804+
798805
self._zones[location_id] = {
799806
"dev_class": "climate",
800807
"model": "ThermoZone",
@@ -807,6 +814,14 @@ def _scan_thermostats(self) -> None:
807814
}
808815
self._count += 5
809816

817+
removed = list(set(self._existing_zones) - set(self._new_zones))
818+
if self._existing_zones and removed:
819+
for location_id in removed:
820+
self._zones.pop(location_id)
821+
822+
self._existing_zones = self._new_zones
823+
self._new_zones = []
824+
810825
def _match_and_rank_thermostats(self) -> dict[str, ThermoLoc]:
811826
"""Helper-function for _scan_thermostats().
812827
@@ -818,8 +833,9 @@ def _match_and_rank_thermostats(self) -> dict[str, ThermoLoc]:
818833
"zone_thermostat": 2,
819834
"thermostatic_radiator_valve": 1,
820835
}
821-
for location_id in self._new_locations:
822-
location = self._loc_data[location_id]
836+
# for location_id in self._new_locations:
837+
# location = self._loc_data[location_id]
838+
for location_id, location in self._loc_data.items():
823839
location.update({"primary": [], "primary_prio": 0, "secondary": []})
824840
for entity_id, entity in self.gw_entities.items():
825841
self._rank_thermostat(

0 commit comments

Comments
 (0)