Skip to content

Commit a344500

Browse files
committed
Move helper-functions into helper.py
1 parent 5bc381b commit a344500

File tree

2 files changed

+63
-62
lines changed

2 files changed

+63
-62
lines changed

plugwise/helper.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,3 +1014,63 @@ def get_lock_state(self, xml):
10141014
data["lock"] = format_measure(measure, None)
10151015

10161016
return data
1017+
1018+
def update_helper(self, data, d_dict, d_id, e_type, key):
1019+
"""Helper for update_gw_devices."""
1020+
for dummy in d_dict[e_type]:
1021+
if key != dummy[ATTR_ID]:
1022+
continue
1023+
for idx, item in enumerate(self.gw_devices[d_id][e_type]):
1024+
if key != item[ATTR_ID]:
1025+
continue
1026+
self.gw_devices[d_id][e_type][idx][ATTR_STATE] = data[key]
1027+
1028+
def update_device_state(self, data, d_dict):
1029+
"""Helper for device_state_updater()."""
1030+
_cooling_state = False
1031+
_dhw_state = False
1032+
_heating_state = False
1033+
state = "idle"
1034+
icon = IDLE_ICON
1035+
1036+
for idx, item in enumerate(d_dict["binary_sensors"]):
1037+
if item[ATTR_ID] == "dhw_state":
1038+
if item[ATTR_STATE]:
1039+
state = "dhw-heating"
1040+
icon = FLAME_ICON
1041+
_dhw_state = True
1042+
1043+
if "heating_state" in data:
1044+
if data["heating_state"]:
1045+
state = "heating"
1046+
icon = HEATING_ICON
1047+
_heating_state = True
1048+
if _heating_state and _dhw_state:
1049+
state = "dhw and heating"
1050+
icon = HEATING_ICON
1051+
if "cooling_state" in data:
1052+
if data["cooling_state"]:
1053+
state = "cooling"
1054+
icon = COOLING_ICON
1055+
_cooling_state = True
1056+
if _cooling_state and _dhw_state:
1057+
state = "dhw and cooling"
1058+
icon = COOLING_ICON
1059+
1060+
return [state, icon]
1061+
1062+
def device_state_updater(self, data, d_id, d_dict):
1063+
""" Device State sensor update helper."""
1064+
for idx, item in enumerate(d_dict["sensors"]):
1065+
if item[ATTR_ID] == "device_state":
1066+
result = self.update_device_state(data, d_dict)
1067+
self.gw_devices[d_id]["sensors"][idx][ATTR_STATE] = result[0]
1068+
self.gw_devices[d_id]["sensors"][idx][ATTR_ICON] = result[1]
1069+
1070+
def pw_notification_updater(self, d_id, d_dict):
1071+
""" PW_Notification update helper."""
1072+
for idx, item in enumerate(d_dict["binary_sensors"]):
1073+
if item[ATTR_ID] == "plugwise_notification":
1074+
self.gw_devices[d_id]["binary_sensors"][idx][ATTR_STATE] = (
1075+
self.notifications != {}
1076+
)

plugwise/smile.py

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -214,65 +214,6 @@ async def full_update_device(self):
214214
if self.smile_type != "power":
215215
self._modules = await self.request(MODULES)
216216

217-
def update_helper(self, data, dev_dict, dev_id, key, entity_type):
218-
"""Helper for update_gw_devices."""
219-
for tmp_dict in dev_dict[entity_type]:
220-
if key == tmp_dict[ATTR_ID]:
221-
gw_list = self.gw_devices[dev_id][entity_type]
222-
for idx, item in enumerate(gw_list):
223-
if key == item[ATTR_ID]:
224-
gw_list[idx][ATTR_STATE] = data[key]
225-
226-
def update_device_state(self, data, dev_dict):
227-
"""Helper for device_state_updater()."""
228-
_cooling_state = False
229-
_dhw_state = False
230-
_heating_state = False
231-
state = "idle"
232-
icon = IDLE_ICON
233-
234-
for idx, item in enumerate(dev_dict["binary_sensors"]):
235-
if item[ATTR_ID] == "dhw_state":
236-
if item[ATTR_STATE]:
237-
state = "dhw-heating"
238-
icon = FLAME_ICON
239-
_dhw_state = True
240-
241-
if "heating_state" in data:
242-
if data["heating_state"]:
243-
state = "heating"
244-
icon = HEATING_ICON
245-
_heating_state = True
246-
if _heating_state and _dhw_state:
247-
state = "dhw and heating"
248-
icon = HEATING_ICON
249-
if "cooling_state" in data:
250-
if data["cooling_state"]:
251-
state = "cooling"
252-
icon = COOLING_ICON
253-
_cooling_state = True
254-
if _cooling_state and _dhw_state:
255-
state = "dhw and cooling"
256-
icon = COOLING_ICON
257-
258-
return [state, icon]
259-
260-
def device_state_updater(self, data, dev_id, dev_dict):
261-
""" Device State sensor update helper."""
262-
for idx, item in enumerate(dev_dict["sensors"]):
263-
if item[ATTR_ID] == "device_state":
264-
result = self.update_device_state(data, dev_dict)
265-
self.gw_devices[dev_id]["sensors"][idx][ATTR_STATE] = result[0]
266-
self.gw_devices[dev_id]["sensors"][idx][ATTR_ICON] = result[1]
267-
268-
def pw_notification_updater(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-
276217
async def update_gw_devices(self):
277218
"""Update all XML data from device."""
278219
await self.update_domain_objects()
@@ -288,15 +229,15 @@ async def update_gw_devices(self):
288229
self.gw_devices[dev_id][key] = value
289230
if "binary_sensors" in dev_dict:
290231
for key, value in list(data.items()):
291-
self.update_helper(data, dev_dict, dev_id, key, "binary_sensors")
232+
self.update_helper(data, dev_dict, dev_id, "binary_sensors", key)
292233
self.pw_notification_updater(dev_id, dev_dict)
293234
if "sensors" in dev_dict:
294235
for key, value in list(data.items()):
295-
self.update_helper(data, dev_dict, dev_id, key, "sensors")
236+
self.update_helper(data, dev_dict, dev_id, "sensors", key)
296237
self.device_state_updater(data, dev_id, dev_dict)
297238
if "switches" in dev_dict:
298239
for key, value in list(data.items()):
299-
self.update_helper(data, dev_dict, dev_id, key, "switches")
240+
self.update_helper(data, dev_dict, dev_id, "switches", key)
300241

301242
def append_special(self, data, dev_id, bs_list, s_list):
302243
"""Helper for all_device_data()."""

0 commit comments

Comments
 (0)