|
16 | 16 | from homeassistant.const import EntityCategory, Platform |
17 | 17 | from homeassistant.core import HomeAssistant, callback |
18 | 18 | from homeassistant.helpers.entity_platform import AddEntitiesCallback |
| 19 | +from homeassistant.helpers.update_coordinator import UpdateFailed |
19 | 20 |
|
20 | 21 | from .const import NODES, STICK, UNSUB_NODE_LOADED |
21 | 22 | from .coordinator import PlugwiseUSBConfigEntry, PlugwiseUSBDataUpdateCoordinator |
@@ -60,7 +61,7 @@ class PlugwiseSwitchEntityDescription( |
60 | 61 | async_switch_fn="set_relay_init", |
61 | 62 | entity_category=EntityCategory.CONFIG, |
62 | 63 | node_feature=NodeFeature.RELAY_INIT, |
63 | | - api_attribute="state", |
| 64 | + api_attribute="init_state", |
64 | 65 | ), |
65 | 66 | PlugwiseSwitchEntityDescription( |
66 | 67 | key="daylight_mode", |
@@ -174,15 +175,20 @@ def __init__( |
174 | 175 | @callback |
175 | 176 | def _handle_coordinator_update(self) -> None: |
176 | 177 | """Handle updated data from the coordinator.""" |
177 | | - data = self.coordinator.data.get(self.entity_description.node_feature, None) |
178 | | - if data is None: |
| 178 | + if self.coordinator.data is None: |
179 | 179 | _LOGGER.debug( |
180 | | - "No %s switch data for %s", |
181 | | - str(self.entity_description.node_feature), |
| 180 | + "No coordinator data available for %s", |
182 | 181 | self._node_info.mac, |
183 | 182 | ) |
184 | 183 | return |
185 | 184 |
|
| 185 | + feature = self.entity_description.node_feature |
| 186 | + data = self.coordinator.data.get(feature, None) |
| 187 | + if data is None or self.coordinator.data.get(feature) is None: |
| 188 | + _LOGGER.debug( |
| 189 | + "No %s switch data for %s", feature, self._node_info.mac) |
| 190 | + return |
| 191 | + |
186 | 192 | self._attr_is_on = getattr( |
187 | 193 | data, |
188 | 194 | self.entity_description.api_attribute, |
|
0 commit comments