Skip to content

Commit 83d7903

Browse files
committed
Detect removed appliances and pop them
1 parent bd65022 commit 83d7903

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

plugwise/helper.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,23 @@ def _all_appliances(self) -> bool:
153153
if appl.entity_id in self._existing_appliances:
154154
self._new_appliances.append((appl.entity_id))
155155
continue
156-
else:
156+
else: # add nnew appliance
157157
self._new_appliances.append(appl.entity_id)
158158

159159
self._create_gw_entities(appl)
160160

161161
LOGGER.debug("HOI existing: %s", self._existing_appliances)
162162
LOGGER.debug("HOI new: %s", self._new_appliances)
163-
is_subset = set(self._new_appliances) <= set(self._existing_appliances)
164-
LOGGER.debug("HOI is_subset: %s", is_subset)
165-
if self._existing_appliances and is_subset:
166-
LOGGER.debug("HOI no unknown appliance(s) found.")
167-
return False
163+
removed = list(set(self._existing_appliances) - set(self._new_appliances))
164+
if self._existing_appliances:
165+
if not removed:
166+
LOGGER.debug("HOI no removed appliance(s).")
167+
return False
168+
else:
169+
LOGGER.debug("HOI removed appliance(s): %s", removed)
170+
for appliance in removed:
171+
self.gw_entities.pop(appliance)
172+
return False
168173

169174
# A smartmeter is not present as an appliance, add it specifically
170175
if self.smile.type == "power" or self.smile.anna_p1:

0 commit comments

Comments
 (0)