Skip to content

Commit dd0a653

Browse files
committed
Add NodeReJoin feature
1 parent 5a76872 commit dd0a653

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

plugwise_usb/messages/responses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
NODE_JOIN_ID: Final = b"0006"
2727
NODE_AWAKE_RESPONSE_ID: Final = b"004F"
28+
NODE_REJOIN_ID: Final = b"0061"
2829
NODE_SWITCH_GROUP_ID: Final = b"0056"
2930
SENSE_REPORT_ID: Final = b"0105"
3031

@@ -896,7 +897,7 @@ class NodeRejoinResponse(PlugwiseResponse):
896897

897898
def __init__(self) -> None:
898899
"""Initialize NodeRejoinResponse message object."""
899-
super().__init__(b"0061")
900+
super().__init__(NODE_REJOIN_ID)
900901

901902

902903
class NodeAckResponse(PlugwiseResponse):

plugwise_usb/network/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
from ..messages.responses import (
2424
NODE_AWAKE_RESPONSE_ID,
2525
NODE_JOIN_ID,
26+
NODE_REJOIN_ID,
2627
NodeAwakeResponse,
2728
NodeInfoResponse,
2829
NodeJoinAvailableResponse,
2930
NodePingResponse,
31+
NodeRejoinResponse,
3032
NodeResponseType,
3133
PlugwiseResponse,
3234
)
@@ -74,6 +76,7 @@ def __init__(
7476
self._unsubscribe_stick_event: Callable[[], None] | None = None
7577
self._unsubscribe_node_awake: Callable[[], None] | None = None
7678
self._unsubscribe_node_join: Callable[[], None] | None = None
79+
self._unsubscribe_node_rejoin: Callable[[], None] | None = None
7780

7881
# region - Properties
7982

@@ -244,6 +247,31 @@ async def node_join_available_message(self, response: PlugwiseResponse) -> bool:
244247
await self._notify_node_event_subscribers(NodeEvent.JOIN, mac)
245248
return True
246249

250+
async def node_rejoin_message(self, response: PlugwiseResponse) -> bool:
251+
"""Handle NodeRejoinResponse messages."""
252+
if not isinstance(response, NodeRejoinResponse):
253+
raise MessageError(
254+
f"Invalid response message type ({response.__class__.__name__}) received, expected NodeRejoinResponse"
255+
)
256+
mac = response.mac_decoded
257+
address = self._register.network_address(mac)
258+
if (address := self._register.network_address(mac)) is not None:
259+
if self._nodes.get(mac) is None:
260+
if self._discover_sed_tasks.get(mac) is None:
261+
self._discover_sed_tasks[mac] = create_task(
262+
self._discover_battery_powered_node(address, mac)
263+
)
264+
elif self._discover_sed_tasks[mac].done():
265+
self._discover_sed_tasks[mac] = create_task(
266+
self._discover_battery_powered_node(address, mac)
267+
)
268+
else:
269+
_LOGGER.debug("duplicate awake discovery for %s", mac)
270+
return True
271+
else:
272+
raise NodeError("Unknown network address for node {mac}")
273+
return True
274+
247275
def _unsubscribe_to_protocol_events(self) -> None:
248276
"""Unsubscribe to events from protocol."""
249277
if self._unsubscribe_node_awake is not None:
@@ -478,6 +506,7 @@ async def start(self) -> None:
478506
self._register.full_scan_finished(self._discover_registered_nodes)
479507
await self._register.start()
480508
self._subscribe_to_protocol_events()
509+
await self._subscribe_to_node_events()
481510
self._is_running = True
482511

483512
async def discover_nodes(self, load: bool = True) -> bool:

0 commit comments

Comments
 (0)