Skip to content

Commit 81db388

Browse files
committed
Add existing/new detection in _get_locations() and related
1 parent 8c77aa0 commit 81db388

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

plugwise/helper.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def __init__(self) -> None:
7474
"""Set the constructor for this class."""
7575
super().__init__()
7676
self._existing_appliances: list[str] = []
77+
self._existing_locations: list[str] = []
7778
self._new_appliances: list[str] = []
79+
self._new_locations: list[str] = []
7880
self._endpoint: str
7981
self._elga: bool
8082
self._is_thermostat: bool
@@ -222,8 +224,12 @@ def _get_locations(self) -> None:
222224
loc = Munch()
223225
locations = self._domain_objects.findall("./location")
224226
for location in locations:
225-
loc.name = location.find("name").text
226227
loc.loc_id = location.attrib["id"]
228+
self._new_locations.append(loc.loc_id)
229+
if loc.loc_id in self._existing_locations:
230+
continue
231+
232+
loc.name = location.find("name").text
227233
self._loc_data[loc.loc_id] = {"name": loc.name}
228234
if loc.name != "Home":
229235
continue
@@ -233,6 +239,15 @@ def _get_locations(self) -> None:
233239
f"./location[@id='{loc.loc_id}']"
234240
)
235241

242+
removed = list(set(self._existing_locations) - set(self._new_locations))
243+
if self._existing_locations and removed:
244+
for location_id in removed:
245+
self._loc_data.pop(location_id)
246+
self._zones.pop(location_id)
247+
248+
self._existing_locations = self._new_locations
249+
self._new_locations = []
250+
236251
def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch:
237252
"""Collect info for all appliances found."""
238253
match appl.pwclass:
@@ -779,7 +794,8 @@ def _scan_thermostats(self) -> None:
779794
the result to update the device_class of secondary thermostats.
780795
"""
781796
self._match_and_rank_thermostats()
782-
for location_id, location in self._loc_data.items():
797+
for location_id in self._new_locations:
798+
location = self._loc_data[location_id]
783799
if location["primary_prio"] != 0:
784800
self._zones[location_id] = {
785801
"dev_class": "climate",
@@ -804,7 +820,8 @@ def _match_and_rank_thermostats(self) -> dict[str, ThermoLoc]:
804820
"zone_thermostat": 2,
805821
"thermostatic_radiator_valve": 1,
806822
}
807-
for location_id, location in self._loc_data.items():
823+
for location_id in self._new_locations:
824+
location = self._loc_data[location_id]
808825
location.update({"primary": [], "primary_prio": 0, "secondary": []})
809826
for entity_id, entity in self.gw_entities.items():
810827
self._rank_thermostat(

0 commit comments

Comments
 (0)