Skip to content

Commit 29d0a16

Browse files
committed
Improve _get_appliances() logic
1 parent 468d451 commit 29d0a16

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

plugwise/common.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,10 @@ def _get_groups(self) -> None:
208208
if group_id is None:
209209
continue # pragma: no cover
210210

211-
self._new_groups.append(group_id)
212-
if (
213-
(members := self._collect_members(group))
214-
and group_id in self._existing_groups
215-
and self.gw_entities[group_id]["name"] == group_name
216-
):
211+
members = self._collect_members(group)
212+
if group_id not in self._existing_groups and members:
213+
self._new_groups.append(group_id)
214+
elif self.gw_entities[group_id]["name"] == group_name
217215
continue
218216

219217
group_type = group.find("type").text
@@ -226,9 +224,6 @@ def _get_groups(self) -> None:
226224
"vendor": "Plugwise",
227225
}
228226
self._count += 5
229-
elif group_id in self._existing_groups:
230-
# Group existed but now has no valid members -> remove
231-
self._new_groups.remove(group_id)
232227

233228
removed = list(set(self._existing_groups) - set(self._new_groups))
234229
if self._existing_groups and removed:

plugwise/helper.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,19 @@ def _get_appliances(self) -> bool:
157157

158158
extend_plug_device_class(appl, appliance)
159159

160-
self._new_appliances.append(appl.entity_id)
161-
if appl.entity_id in self._existing_appliances and (
160+
if appl.entity_id not in self._existing_appliances:
161+
self._new_appliances.append(appl.entity_id)
162+
elif (
162163
appl.pwclass in ("gateway", "heater_central")
163164
or self.gw_entities[appl.entity_id]["name"] == appl.name
164165
):
165166
continue
166167

167168
# Collect appliance info, skip orphaned/removed devices
168-
if not (appl := self._appliance_info_finder(appl, appliance)):
169+
if not (
170+
appl := self._appliance_info_finder(appl, appliance)
171+
and appl.entity_id in self._new_appliances
172+
):
169173
self._new_appliances.pop()
170174
continue
171175

0 commit comments

Comments
 (0)