Skip to content

Commit 3f0489c

Browse files
committed
Improve/rework _get_groups()
1 parent 76983c4 commit 3f0489c

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

plugwise/common.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def __init__(self) -> None:
5454
self._cooling_present: bool
5555
self._count: int
5656
self._domain_objects: etree.Element
57+
self._existing_groups: list[str] = []
5758
self._heater_id: str = NONE
59+
self._new_groups: list[st] = []
5860
self._on_off_device: bool
5961
self.gw_entities: dict[str, GwEntityData] = {}
6062
self.smile: Munch
@@ -191,19 +193,22 @@ def _entity_switching_group(self, entity: GwEntityData, data: GwEntityData) -> N
191193
data["switches"]["relay"] = counter != 0
192194
self._count += 1
193195

194-
def _get_groups(self) -> dict[str, GwEntityData]:
196+
def _get_groups(self) -> None:
195197
"""Helper-function for smile.py: get_all_gateway_entities().
196198
197199
Collect switching-, pumping- or report-group info.
198200
"""
199-
groups: dict[str, GwEntityData] = {}
200201
# P1 and Anna don't have groups
201202
if self.smile.type == "power" or self.check_name(ANNA):
202-
return groups
203+
return
203204

204205
for group in self._domain_objects.findall("./group"):
205206
members: list[str] = []
206207
group_id = group.attrib["id"]
208+
self._new_groups.append(group_id)
209+
if group_id in self._existing_appliances:
210+
continue
211+
207212
group_name = group.find("name").text
208213
group_type = group.find("type").text
209214
group_appliances = group.findall("appliances/appliance")
@@ -213,7 +218,7 @@ def _get_groups(self) -> dict[str, GwEntityData]:
213218
members.append(item.attrib["id"])
214219

215220
if group_type in GROUP_TYPES and members:
216-
groups[group_id] = {
221+
self.gw_entities[group_id] = {
217222
"dev_class": group_type,
218223
"model": "Group",
219224
"name": group_name,
@@ -222,7 +227,13 @@ def _get_groups(self) -> dict[str, GwEntityData]:
222227
}
223228
self._count += 5
224229

225-
return groups
230+
removed = list(set(self._existing_groups) - set(self._new_groups))
231+
if self._existing_groups and removed:
232+
for group in removed:
233+
self.gw_entities.pop(group)
234+
235+
self._existing_groups = self._new_groups
236+
self._new_groups = []
226237

227238
def _get_lock_state(
228239
self, xml: etree.Element, data: GwEntityData, stretch_v2: bool = False

plugwise/smile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def get_all_gateway_entities(self) -> None:
119119
if self.check_name(ADAM):
120120
self._scan_thermostats()
121121

122-
if group_data := self._get_groups():
123-
self.gw_entities.update(group_data)
122+
self._get_groups()
124123

125124
self._all_entity_data()
126125

0 commit comments

Comments
 (0)