Skip to content

Commit 3998bd0

Browse files
committed
Add existing/new detection in _get_locations() and related
1 parent 8f73d46 commit 3998bd0

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:
@@ -777,7 +792,8 @@ def _scan_thermostats(self) -> None:
777792
the result to update the device_class of secondary thermostats.
778793
"""
779794
self._match_and_rank_thermostats()
780-
for location_id, location in self._loc_data.items():
795+
for location_id in self._new_locations:
796+
location = self._loc_data[location_id]
781797
if location["primary_prio"] != 0:
782798
self._zones[location_id] = {
783799
"dev_class": "climate",
@@ -802,7 +818,8 @@ def _match_and_rank_thermostats(self) -> dict[str, ThermoLoc]:
802818
"zone_thermostat": 2,
803819
"thermostatic_radiator_valve": 1,
804820
}
805-
for location_id, location in self._loc_data.items():
821+
for location_id in self._new_locations:
822+
location = self._loc_data[location_id]
806823
location.update({"primary": [], "primary_prio": 0, "secondary": []})
807824
for entity_id, entity in self.gw_entities.items():
808825
self._rank_thermostat(

0 commit comments

Comments
 (0)