|
17 | 17 | from homeassistant.helpers.entity_platform import AddEntitiesCallback |
18 | 18 |
|
19 | 19 | from . import PlugwiseConfigEntry |
20 | | -from .const import COOLING_ENA_SWITCH, DHW_CM_SWITCH, LOCK, MEMBERS, RELAY, SWITCHES |
| 20 | +from .const import ( |
| 21 | + COOLING_ENA_SWITCH, |
| 22 | + DHW_CM_SWITCH, |
| 23 | + LOCK, |
| 24 | + LOGGER, # pw-beta |
| 25 | + MEMBERS, |
| 26 | + RELAY, |
| 27 | + SWITCHES, |
| 28 | +) |
21 | 29 |
|
22 | 30 | # Upstream consts |
23 | 31 | from .coordinator import PlugwiseDataUpdateCoordinator |
@@ -76,13 +84,28 @@ def _add_entities() -> None: |
76 | 84 | if not coordinator.new_devices: |
77 | 85 | return |
78 | 86 |
|
79 | | - async_add_entities( |
80 | | - PlugwiseSwitchEntity(coordinator, device_id, description) |
81 | | - for device_id in coordinator.new_devices |
82 | | - if (switches := coordinator.data.devices[device_id].get(SWITCHES)) |
83 | | - for description in PLUGWISE_SWITCHES |
84 | | - if description.key in switches |
85 | | - ) |
| 87 | + # Upstream consts |
| 88 | + # async_add_entities( |
| 89 | + # PlugwiseSwitchEntity(coordinator, device_id, description) |
| 90 | + # for device_id in coordinator.new_devices |
| 91 | + # if (switches := coordinator.data.devices[device_id].get(SWITCHES)) |
| 92 | + # for description in PLUGWISE_SWITCHES |
| 93 | + # if description.key in switches |
| 94 | + # ) |
| 95 | + # pw-beta alternative for debugging |
| 96 | + entities: list[PlugwiseSwitchEntity] = [] |
| 97 | + for device_id in coordinator.new_devices: |
| 98 | + device = coordinator.data.devices[device_id] |
| 99 | + if not (switches := device.get(SWITCHES)): |
| 100 | + continue |
| 101 | + for description in PLUGWISE_SWITCHES: |
| 102 | + if description.key not in switches: |
| 103 | + continue |
| 104 | + entities.append(PlugwiseSwitchEntity(coordinator, device_id, description)) |
| 105 | + LOGGER.debug( |
| 106 | + "Add %s %s switch", device["name"], description.translation_key |
| 107 | + ) |
| 108 | + async_add_entities(entities) |
86 | 109 |
|
87 | 110 | _add_entities() |
88 | 111 | entry.async_on_unload(coordinator.async_add_listener(_add_entities)) |
|
0 commit comments