Skip to content

Commit 2bc1551

Browse files
committed
Detect smartmeter change
1 parent 0c0ecd7 commit 2bc1551

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
@@ -174,21 +174,19 @@ def _get_appliances(self) -> bool:
174174

175175
self._create_gw_entities(appl)
176176

177-
removed = list(set(self._existing_appliances) - set(self._new_appliances))
178-
if self._existing_appliances:
179-
for appliance in removed:
180-
self.gw_entities.pop(appliance)
181-
return False
182-
183177
# A smartmeter is not present as an appliance, add it specifically
184-
if not self._existing_appliances and (
185-
self.smile.type == "power" or self.smile.anna_p1
186-
):
178+
if self.smile.type == "power" or self.smile.anna_p1:
187179
self._add_p1_smartmeter_info()
188180

189181
# Sort the gw_entities
190182
self._reorder_devices()
191183

184+
removed = list(set(self._existing_appliances) - set(self._new_appliances))
185+
if self._existing_appliances:
186+
for appliance in removed:
187+
self.gw_entities.pop(appliance)
188+
return False
189+
192190
self._existing_appliances = self._new_appliances
193191
self._new_appliances = []
194192
return True
@@ -207,6 +205,13 @@ def _add_p1_smartmeter_info(self) -> None:
207205
if not module_data["contents"]: # pragma: no cover
208206
return
209207

208+
module_id = module_data["module_id"]
209+
if (
210+
self.gw_entities[self._home_loc_id]["module_id"] == module_id
211+
or self.gw_entities[self._gateway_id]["module_id"] == module_id
212+
):
213+
return
214+
210215
appl.available = None
211216
appl.entity_id = self._home_loc_id
212217
if not self.smile.anna_p1:
@@ -217,7 +222,7 @@ def _add_p1_smartmeter_info(self) -> None:
217222
appl.mac = None
218223
appl.model = module_data["vendor_model"]
219224
appl.model_id = None # don't use model_id for SmartMeter
220-
appl.module_id = module_data["module_id"]
225+
appl.module_id = module_id
221226
appl.name = "P1"
222227
appl.pwclass = "smartmeter"
223228
appl.vendor_name = module_data["vendor_name"]

0 commit comments

Comments
 (0)