Skip to content

Commit 08804a1

Browse files
authored
Merge pull request #416 from plugwise/relay_config
Relay config
2 parents 9e81349 + 76dcc5e commit 08804a1

10 files changed

Lines changed: 80 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.59.2
4+
5+
- Fix set_relay_init() function, improve _handle_coordinator_update() error-handling in all platform files
6+
- Link to plugwise_usb [v0.47.6](https://github.com/plugwise/python-plugwise-usb/releases/tag/v0.47.6)
7+
- Link to plugwise_usb v0.47.5 (not released)
8+
- Link to plugwise_usb [v0.47.4](https://github.com/plugwise/python-plugwise-usb/releases/tag/v0.47.4)
9+
310
## v0.59.1
411

512
- Remove device serial_number, ZigBee MAC addresses are now shown in HA, via PR [400](https://github.com/plugwise/plugwise_usb-beta/pull/400)

custom_components/plugwise_usb/binary_sensor.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from homeassistant.const import EntityCategory, Platform
1717
from homeassistant.core import HomeAssistant, callback
1818
from homeassistant.helpers.entity_platform import AddEntitiesCallback
19+
from homeassistant.helpers.update_coordinator import UpdateFailed
1920

2021
from .const import NODES, STICK, UNSUB_NODE_LOADED
2122
from .coordinator import PlugwiseUSBConfigEntry
@@ -143,20 +144,21 @@ class PlugwiseUSBBinarySensor(PlugwiseUSBEntity, BinarySensorEntity):
143144
@callback
144145
def _handle_coordinator_update(self) -> None:
145146
"""Handle updated data from the coordinator."""
146-
data = self.coordinator.data.get(self.entity_description.node_feature, None)
147-
if data is None:
147+
148+
if self.coordinator.data is None:
148149
_LOGGER.debug(
149-
"No %s binary sensor data for %s",
150-
self.entity_description.node_feature,
150+
"No coordinator data available for %s",
151151
self._node_info.mac,
152152
)
153153
return
154-
if self.coordinator.data[self.entity_description.node_feature] is None:
155-
_LOGGER.info(
156-
"No binary sensor data for %s",
157-
str(self.entity_description.node_feature),
158-
)
154+
155+
feature = self.entity_description.node_feature
156+
data = self.coordinator.data.get(feature, None)
157+
if data is None or self.coordinator.data.get(feature) is None:
158+
_LOGGER.debug(
159+
"No %s binary sensor data for %s", feature, self._node_info.mac)
159160
return
161+
160162
self._attr_is_on = getattr(
161163
self.coordinator.data[self.entity_description.node_feature],
162164
self.entity_description.api_attribute,

custom_components/plugwise_usb/coordinator.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ async def async_node_update(self) -> dict[NodeFeature, Any]:
7575
features = tuple(freq_features.keys())
7676
try:
7777
states = await self.node.get_state(features)
78-
except StickError as err:
79-
raise ConfigEntryError from err
80-
except (StickTimeout, NodeTimeout) as err:
81-
raise TimeoutError from err
82-
except NodeError as err:
83-
raise UpdateFailed from err
78+
except (NodeError, NodeTimeout, StickError, StickTimeout) as err:
79+
raise UpdateFailed(
80+
f"Failed to refresh node {self.node.node_info.mac}: {err}"
81+
) from err
8482

8583
if (
8684
not self.node.node_info.is_battery_powered

custom_components/plugwise_usb/event.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from homeassistant.const import Platform
1717
from homeassistant.core import HomeAssistant, callback
1818
from homeassistant.helpers.entity_platform import AddEntitiesCallback
19+
from homeassistant.helpers.update_coordinator import UpdateFailed
1920

2021
from .const import NODES, STICK, UNSUB_NODE_LOADED
2122
from .coordinator import PlugwiseUSBConfigEntry, PlugwiseUSBDataUpdateCoordinator
@@ -135,14 +136,21 @@ def __init__(
135136
@callback
136137
def _handle_coordinator_update(self) -> None:
137138
"""Handle updated data from the coordinator."""
138-
data = self.coordinator.data.get(self.entity_description.node_feature, None)
139-
if data is None:
139+
if self.coordinator.data is None:
140140
_LOGGER.debug(
141-
"No %s event data for %s",
142-
self.entity_description.node_feature,
141+
"No coordinator data available for %s",
143142
self._node_info.mac,
144143
)
145144
return
145+
146+
feature = self.entity_description.node_feature
147+
data = self.coordinator.data.get(feature, None)
148+
149+
if data is None or self.coordinator.data.get(feature) is None:
150+
_LOGGER.debug(
151+
"No %s event data for %s", feature, self._node_info.mac)
152+
return
153+
146154
# SWITCH logic
147155
state_value = data.state
148156
group_value = data.group

custom_components/plugwise_usb/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"iot_class": "local_polling",
1010
"issue_tracker": "https://github.com/plugwise/python-plugwise-usb/issues",
1111
"loggers": ["plugwise_usb"],
12-
"requirements": ["plugwise-usb==0.47.2"],
13-
"version": "0.59.1"
12+
"requirements": ["plugwise-usb==0.47.6"],
13+
"version": "0.59.2"
1414
}

custom_components/plugwise_usb/number.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from homeassistant.core import HomeAssistant, callback
2424
from homeassistant.helpers.entity_platform import AddEntitiesCallback
25+
from homeassistant.helpers.update_coordinator import UpdateFailed
2526

2627
from .const import NODES, STICK, UNSUB_NODE_LOADED
2728
from .coordinator import PlugwiseUSBConfigEntry, PlugwiseUSBDataUpdateCoordinator
@@ -240,14 +241,20 @@ def __init__(
240241
@callback
241242
def _handle_coordinator_update(self) -> None:
242243
"""Handle updated data from the coordinator."""
243-
data = self.coordinator.data.get(self.entity_description.node_feature, None)
244-
if data is None:
244+
if self.coordinator.data is None:
245245
_LOGGER.debug(
246-
"No %s number data for %s",
247-
self.entity_description.node_feature,
246+
"No coordinator data available for %s",
248247
self._node_info.mac,
249248
)
250249
return
250+
251+
feature = self.entity_description.node_feature
252+
data = self.coordinator.data.get(feature, None)
253+
if data is None or self.coordinator.data.get(feature) is None:
254+
_LOGGER.debug(
255+
"No %s numbeer data for %s", feature, self._node_info.mac)
256+
return
257+
251258
self._attr_native_value = getattr(
252259
self.coordinator.data[self.entity_description.node_feature],
253260
self.entity_description.key,

custom_components/plugwise_usb/select.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from homeassistant.const import EntityCategory, Platform
1414
from homeassistant.core import HomeAssistant, callback
1515
from homeassistant.helpers.entity_platform import AddEntitiesCallback
16+
from homeassistant.helpers.update_coordinator import UpdateFailed
1617

1718
from .const import NODES, STICK, UNSUB_NODE_LOADED
1819
from .coordinator import PlugwiseUSBConfigEntry, PlugwiseUSBDataUpdateCoordinator
@@ -113,15 +114,20 @@ def __init__(
113114
@callback
114115
def _handle_coordinator_update(self) -> None:
115116
"""Handle updated data from the coordinator."""
116-
data = self.coordinator.data.get(self.entity_description.node_feature, None)
117-
if data is None:
117+
if self.coordinator.data is None:
118118
_LOGGER.debug(
119-
"No %s select data for %s",
120-
str(self.entity_description.node_feature),
119+
"No coordinator data available for %s",
121120
self._node_info.mac,
122121
)
123122
return
124123

124+
feature = self.entity_description.node_feature
125+
data = self.coordinator.data.get(feature, None)
126+
if data is None or self.coordinator.data.get(feature) is None:
127+
_LOGGER.debug(
128+
"No %s select data for %s", feature, self._node_info.mac)
129+
return
130+
125131
current_option = getattr(
126132
data,
127133
self.entity_description.key,

custom_components/plugwise_usb/sensor.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727
from homeassistant.core import HomeAssistant, callback
2828
from homeassistant.helpers.entity_platform import AddEntitiesCallback
29+
from homeassistant.helpers.update_coordinator import UpdateFailed
2930

3031
from .const import NODES, STICK, UNSUB_NODE_LOADED
3132
from .coordinator import PlugwiseUSBConfigEntry
@@ -220,14 +221,20 @@ class PlugwiseUSBSensorEntity(PlugwiseUSBEntity, SensorEntity):
220221
@callback
221222
def _handle_coordinator_update(self) -> None:
222223
"""Handle updated data from the coordinator."""
223-
data = self.coordinator.data.get(self.entity_description.node_feature, None)
224-
if data is None:
224+
if self.coordinator.data is None:
225225
_LOGGER.debug(
226-
"No %s sensor data for %s",
227-
self.entity_description.node_feature,
226+
"No coordinator data available for %s",
228227
self._node_info.mac,
229228
)
230229
return
230+
231+
feature = self.entity_description.node_feature
232+
data = self.coordinator.data.get(feature, None)
233+
if data is None or self.coordinator.data.get(feature) is None:
234+
_LOGGER.debug(
235+
"No %s sensor data for %s", feature, self._node_info.mac)
236+
return
237+
231238
self._attr_native_value = getattr(
232239
self.coordinator.data[self.entity_description.node_feature],
233240
self.entity_description.key,

custom_components/plugwise_usb/switch.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from homeassistant.const import EntityCategory, Platform
1717
from homeassistant.core import HomeAssistant, callback
1818
from homeassistant.helpers.entity_platform import AddEntitiesCallback
19+
from homeassistant.helpers.update_coordinator import UpdateFailed
1920

2021
from .const import NODES, STICK, UNSUB_NODE_LOADED
2122
from .coordinator import PlugwiseUSBConfigEntry, PlugwiseUSBDataUpdateCoordinator
@@ -60,7 +61,7 @@ class PlugwiseSwitchEntityDescription(
6061
async_switch_fn="set_relay_init",
6162
entity_category=EntityCategory.CONFIG,
6263
node_feature=NodeFeature.RELAY_INIT,
63-
api_attribute="state",
64+
api_attribute="init_state",
6465
),
6566
PlugwiseSwitchEntityDescription(
6667
key="daylight_mode",
@@ -174,15 +175,20 @@ def __init__(
174175
@callback
175176
def _handle_coordinator_update(self) -> None:
176177
"""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:
179179
_LOGGER.debug(
180-
"No %s switch data for %s",
181-
str(self.entity_description.node_feature),
180+
"No coordinator data available for %s",
182181
self._node_info.mac,
183182
)
184183
return
185184

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+
186192
self._attr_is_on = getattr(
187193
data,
188194
self.entity_description.api_attribute,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "plugwise_usb-beta"
3-
version = "0.59.1"
3+
version = "0.59.2"
44
description = "Plugwise USB custom_component (BETA)"
55
readme = "README.md"
66
requires-python = ">=3.13"

0 commit comments

Comments
 (0)