Skip to content

Commit 2f367c4

Browse files
committed
Entities.py: solve complexity
1 parent f0db2aa commit 2f367c4

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

plugwise/entities.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ def notification(self):
5656
"""Plugwise Notification message."""
5757
return self._notification
5858

59+
def icon_selector(arg, state):
60+
selector = {
61+
"dhw_state": FLOW_ON_ICON if state else FLOW_OFF_ICON,
62+
"flame_state": FLAME_ICON if state else IDLE_ICON,
63+
"slave_boiler_state": FLAME_ICON if state else IDLE_ICON,
64+
"plugwise_notification": NOTIFICATION_ICON if state else NO_NOTIFICATION_ICON,
65+
}
66+
return selector.get(arg)
67+
5968
def update_data(self):
6069
"""Handle update callbacks."""
6170
data = self._api.gw_devices[self._dev_id]
@@ -69,18 +78,11 @@ def update_data(self):
6978
continue
7079

7180
self._is_on = item[ATTR_STATE]
72-
if self._binary_sensor == "dhw_state":
73-
self._icon = FLOW_ON_ICON if self._is_on else FLOW_OFF_ICON
74-
if (
75-
self._binary_sensor == "flame_state"
76-
or self._binary_sensor == "slave_boiler_state"
77-
):
78-
self._icon = FLAME_ICON if self._is_on else IDLE_ICON
81+
self._icon = self.icon_selector(self._binary_sensor, self._is_on)
7982

8083
if self._binary_sensor != "plugwise_notification":
8184
continue
8285

83-
self._icon = NOTIFICATION_ICON if self._is_on else NO_NOTIFICATION_ICON
8486
notify = self._api.notifications
8587
self._notification = {}
8688
for severity in SEVERITIES:

0 commit comments

Comments
 (0)