Skip to content

Commit d81a67b

Browse files
committed
Add remove_empty_platform_dicts() function and implement
1 parent 06919ee commit d81a67b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

plugwise/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@
4747
from .helper import SmileComm, SmileHelper
4848

4949

50+
def remove_empty_platform_dicts(data: DeviceData) -> DeviceData:
51+
"""Helper-function for removing any empty platform dicts."""
52+
if not data["binary_sensors"]:
53+
data.pop("binary_sensors")
54+
if not data["sensors"]:
55+
data.pop("sensors")
56+
if not data["switches"]:
57+
data.pop("switches")
58+
59+
return data
60+
61+
5062
class SmileData(SmileHelper):
5163
"""The Plugwise Smile main class."""
5264

@@ -97,12 +109,7 @@ def _all_device_data(self) -> None:
97109
if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS:
98110
self.update_for_cooling(self.gw_devices[device_id])
99111

100-
if not self.gw_devices[device_id]["binary_sensors"]:
101-
self.gw_devices[device_id].pop("binary_sensors")
102-
if not self.gw_devices[device_id]["sensors"]:
103-
self.gw_devices[device_id].pop("sensors")
104-
if not self.gw_devices[device_id]["switches"]:
105-
self.gw_devices[device_id].pop("switches")
112+
remove_empty_platform_dicts(self.gw_devices[device_id])
106113

107114
self.gw_data.update(
108115
{"smile_name": self.smile_name, "gateway_id": self.gateway_id}
@@ -545,12 +552,7 @@ async def async_update(self) -> PlugwiseData:
545552
if device["dev_class"] in ZONE_THERMOSTATS:
546553
self.update_for_cooling(device)
547554

548-
if not device["binary_sensors"]:
549-
device.pop("binary_sensors")
550-
if not device["sensors"]:
551-
device.pop("sensors")
552-
if not device["switches"]:
553-
device.pop("switches")
555+
remove_empty_platform_dicts(device)
554556

555557
return PlugwiseData(self.gw_data, self.gw_devices)
556558

0 commit comments

Comments
 (0)