|
47 | 47 | from .helper import SmileComm, SmileHelper |
48 | 48 |
|
49 | 49 |
|
| 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 | + |
50 | 62 | class SmileData(SmileHelper): |
51 | 63 | """The Plugwise Smile main class.""" |
52 | 64 |
|
@@ -97,12 +109,7 @@ def _all_device_data(self) -> None: |
97 | 109 | if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS: |
98 | 110 | self.update_for_cooling(self.gw_devices[device_id]) |
99 | 111 |
|
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]) |
106 | 113 |
|
107 | 114 | self.gw_data.update( |
108 | 115 | {"smile_name": self.smile_name, "gateway_id": self.gateway_id} |
@@ -545,12 +552,7 @@ async def async_update(self) -> PlugwiseData: |
545 | 552 | if device["dev_class"] in ZONE_THERMOSTATS: |
546 | 553 | self.update_for_cooling(device) |
547 | 554 |
|
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) |
554 | 556 |
|
555 | 557 | return PlugwiseData(self.gw_data, self.gw_devices) |
556 | 558 |
|
|
0 commit comments