Skip to content

Commit eee7bad

Browse files
committed
Detect smartmeter change
1 parent abf6cec commit eee7bad

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

plugwise/helper.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,19 @@ def _get_appliances(self) -> bool:
161161

162162
self._create_gw_entities(appl)
163163

164-
removed = list(set(self._existing_appliances) - set(self._new_appliances))
165-
if self._existing_appliances:
166-
for appliance in removed:
167-
self.gw_entities.pop(appliance)
168-
return False
169-
170164
# A smartmeter is not present as an appliance, add it specifically
171-
if not self._existing_appliances and (
172-
self.smile.type == "power" or self.smile.anna_p1
173-
):
165+
if self.smile.type == "power" or self.smile.anna_p1:
174166
self._add_p1_smartmeter_info()
175167

176168
# Sort the gw_entities
177169
self._reorder_devices()
178170

171+
removed = list(set(self._existing_appliances) - set(self._new_appliances))
172+
if self._existing_appliances:
173+
for appliance in removed:
174+
self.gw_entities.pop(appliance)
175+
return False
176+
179177
self._existing_appliances = self._new_appliances
180178
self._new_appliances = []
181179
return True
@@ -194,6 +192,13 @@ def _add_p1_smartmeter_info(self) -> None:
194192
if not module_data["contents"]: # pragma: no cover
195193
return
196194

195+
module_id = module_data["module_id"]
196+
if (
197+
self.gw_entities[self._home_loc_id]["module_id"] == module_id
198+
or self.gw_entities[self._gateway_id]["module_id"] == module_id
199+
):
200+
return
201+
197202
appl.available = None
198203
appl.entity_id = self._home_loc_id
199204
if not self.smile.anna_p1:
@@ -204,7 +209,7 @@ def _add_p1_smartmeter_info(self) -> None:
204209
appl.mac = None
205210
appl.model = module_data["vendor_model"]
206211
appl.model_id = None # don't use model_id for SmartMeter
207-
appl.module_id = module_data["module_id"]
212+
appl.module_id = module_id
208213
appl.name = "P1"
209214
appl.pwclass = "smartmeter"
210215
appl.vendor_name = module_data["vendor_name"]

0 commit comments

Comments
 (0)