Skip to content

Commit 629f942

Browse files
committed
Move code into helper functions
1 parent 1792e4d commit 629f942

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

plugwise/smile.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ async def full_update_device(self):
215215
self._modules = await self.request(MODULES)
216216

217217
def update_device_state(self, data, dev_dict):
218-
"""Helper for update_helper."""
218+
"""Helper for device_state_updater()."""
219219
_cooling_state = False
220220
_dhw_state = False
221221
_heating_state = False
@@ -248,6 +248,14 @@ def update_device_state(self, data, dev_dict):
248248

249249
return [state, icon]
250250

251+
def device_state_updater(self, data, dev_id, dev_dict):
252+
""" Device State sensor update helper."""
253+
for idx, item in enumerate(dev_dict["sensors"]):
254+
if item[ATTR_ID] == "device_state":
255+
result = self.update_device_state(data, dev_dict)
256+
self.gw_devices[dev_id]["sensors"][idx][ATTR_STATE] = result[0]
257+
self.gw_devices[dev_id]["sensors"][idx][ATTR_ICON] = result[1]
258+
251259
def update_helper(self, data, dev_dict, dev_id, key, entity_type):
252260
"""Helper for update_gw_devices."""
253261
for tmp_dict in dev_dict[entity_type]:
@@ -257,6 +265,14 @@ def update_helper(self, data, dev_dict, dev_id, key, entity_type):
257265
if key == item[ATTR_ID]:
258266
gw_list[idx][ATTR_STATE] = data[key]
259267

268+
def update_pw_notification(self, dev_id, dev_dict):
269+
""" PW_Notification update helper."""
270+
for idx, item in enumerate(dev_dict["binary_sensors"]):
271+
if item[ATTR_ID] == "plugwise_notification":
272+
self.gw_devices[dev_id]["binary_sensors"][idx][ATTR_STATE] = (
273+
self.notifications != {}
274+
)
275+
260276
async def update_gw_devices(self):
261277
"""Update all XML data from device."""
262278
await self.update_domain_objects()
@@ -273,19 +289,11 @@ async def update_gw_devices(self):
273289
if "binary_sensors" in dev_dict:
274290
for key, value in list(data.items()):
275291
self.update_helper(data, dev_dict, dev_id, key, "binary_sensors")
276-
for idx, item in enumerate(dev_dict["binary_sensors"]):
277-
if item[ATTR_ID] == "plugwise_notification":
278-
self.gw_devices[dev_id]["binary_sensors"][idx][ATTR_STATE] = (
279-
self.notifications != {}
280-
)
292+
self.update_pw_notification(dev_id, dev_dict)
281293
if "sensors" in dev_dict:
282294
for key, value in list(data.items()):
283295
self.update_helper(data, dev_dict, dev_id, key, "sensors")
284-
for idx, item in enumerate(dev_dict["sensors"]):
285-
if item[ATTR_ID] == "device_state":
286-
result = self.update_device_state(data, dev_dict)
287-
self.gw_devices[dev_id]["sensors"][idx][ATTR_STATE] = result[0]
288-
self.gw_devices[dev_id]["sensors"][idx][ATTR_ICON] = result[1]
296+
self.device_state_updater(data, dev_id, dev_dict)
289297
if "switches" in dev_dict:
290298
for key, value in list(data.items()):
291299
self.update_helper(data, dev_dict, dev_id, key, "switches")

0 commit comments

Comments
 (0)