Skip to content

Commit 0334544

Browse files
committed
Split off _add_or_update_notifications() function
1 parent 47cd1b2 commit 0334544

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

plugwise/__init__.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,36 @@ def remove_empty_platform_dicts(data: DeviceData) -> None:
6565
class SmileData(SmileHelper):
6666
"""The Plugwise Smile main class."""
6767

68-
def update_for_cooling(self, device: DeviceData) -> None:
68+
def _update_gw_devices(self) -> None:
69+
"""Helper-function for _all_device_data() and async_update().
70+
71+
Collect data for each device and add to self.gw_devices.
72+
"""
73+
for device_id, device in self.gw_devices.items():
74+
data = self._get_device_data(device_id)
75+
self._add_or_update_notifications(data, device_id, device)
76+
device.update(data)
77+
self._update_for_cooling(device)
78+
remove_empty_platform_dicts(device)
79+
80+
def _add_or_update_notifications(
81+
self, data: DeviceData, device_id: str, device: DeviceData
82+
) -> None:
83+
"""Helper-function adding or updating the Plugwise notifications."""
84+
if (
85+
device_id == self.gateway_id
86+
and (
87+
self._is_thermostat
88+
or (self.smile_type == "power" and not self._smile_legacy)
89+
)
90+
) or (
91+
"binary_sensors" in device
92+
and "plugwise_notification" in device["binary_sensors"]
93+
):
94+
data["binary_sensors"]["plugwise_notification"] = bool(self._notifications)
95+
self._count += 1
96+
97+
def _update_for_cooling(self, device: DeviceData) -> None:
6998
"""Helper-function for adding/updating various cooling-related values."""
7099
# For heating + cooling, replace setpoint with setpoint_high/_low
71100
if (
@@ -93,32 +122,6 @@ def update_for_cooling(self, device: DeviceData) -> None:
93122
sensors["setpoint_high"] = temp_dict["setpoint_high"]
94123
self._count += 2
95124

96-
def _update_gw_devices(self) -> None:
97-
"""Helper-function for _all_device_data() and async_update().
98-
99-
Collect data for each device and add to self.gw_devices.
100-
"""
101-
for device_id, device in self.gw_devices.items():
102-
data = self._get_device_data(device_id)
103-
if (
104-
device_id == self.gateway_id
105-
and (
106-
self._is_thermostat
107-
or (self.smile_type == "power" and not self._smile_legacy)
108-
)
109-
) or (
110-
"binary_sensors" in device
111-
and "plugwise_notification" in device["binary_sensors"]
112-
):
113-
data["binary_sensors"]["plugwise_notification"] = bool(
114-
self._notifications
115-
)
116-
self._count += 1
117-
118-
device.update(data)
119-
self.update_for_cooling(device)
120-
remove_empty_platform_dicts(device)
121-
122125
def _all_device_data(self) -> None:
123126
"""Helper-function for get_all_devices().
124127

0 commit comments

Comments
 (0)