Skip to content

Commit 5fa52c7

Browse files
committed
Change handling of 000A-responses
1 parent ea10484 commit 5fa52c7

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

plugwise_usb/connection/__init__.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ async def _handle_stick_event(self, event: StickEvent) -> None:
151151
elif event == StickEvent.DISCONNECTED and self._queue.is_running:
152152
await self._queue.stop()
153153

154+
async def _handle_stick_init_response(self, response: PlugwiseResponse) -> None:
155+
"""Handle the received Stick init response."""
156+
if not isinstance(response, StickInitResponse | StickInitShortResponse):
157+
raise MessageError(
158+
f"Invalid response message type ({response.__class__.__name__}) received, expected StickInitResponse, StickInitShortResponse"
159+
)
160+
self._mac_stick = response.mac_decoded
161+
self.stick_name = f"Stick {self._mac_stick[-5:]}"
162+
self._network_online = response.network_online
163+
if self._network_online:
164+
# Replace first 2 characters by 00 for mac of circle+ node
165+
self._mac_nc = response.mac_network_controller
166+
self._network_id = response.network_id
167+
168+
154169
async def initialize_stick(self, node_info=True) -> None:
155170
"""Initialize connection to the USB-stick."""
156171
if not self._manager.is_connected:
@@ -162,9 +177,7 @@ async def initialize_stick(self, node_info=True) -> None:
162177

163178
try:
164179
request = StickInitRequest(self.send)
165-
init_response: (
166-
StickInitResponse | StickInitShortResponse | None
167-
) = await request.send()
180+
init_response: (NodeSpecificResponse | None) = await request.send()
168181
except StickError as err:
169182
raise StickError(
170183
"No response from USB-Stick to initialization request."
@@ -177,13 +190,6 @@ async def initialize_stick(self, node_info=True) -> None:
177190
+ " Validate USB-stick is connected to port "
178191
+ f"' {self._manager.serial_path}'"
179192
)
180-
self._mac_stick = init_response.mac_decoded
181-
self.stick_name = f"Stick {self._mac_stick[-5:]}"
182-
self._network_online = init_response.network_online
183-
if self._network_online:
184-
# Replace first 2 characters by 00 for mac of circle+ node
185-
self._mac_nc = init_response.mac_network_controller
186-
self._network_id = init_response.network_id
187193

188194
self._is_initialized = True
189195

plugwise_usb/messages/requests.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ class StickInitRequest(PlugwiseRequest):
522522
"""
523523

524524
_identifier = b"000A"
525-
_reply_identifier = b"0011"
525+
_reply_identifier = b"0003"
526+
# The 0011-response is handled by a separate subscription
526527

527528
def __init__(
528529
self,
@@ -532,17 +533,17 @@ def __init__(
532533
super().__init__(send_fn, None)
533534
self._max_retries = 1
534535

535-
async def send(self) -> StickInitResponse | StickInitShortResponse | None:
536+
async def send(self) -> NodeSpecificResponse | None:
536537
"""Send request."""
537538
if self._send_fn is None:
538539
raise MessageError("Send function missing")
539540
result = await self._send_request()
540-
if isinstance(result, StickInitResponse | StickInitShortResponse):
541+
if isinstance(result, NodeSpecificResponse):
541542
return result
542543
if result is None:
543544
return None
544545
raise MessageError(
545-
f"Invalid response message. Received {result.__class__.__name__}, expected StickInitResponse/StickInitShortResponse"
546+
f"Invalid response message. Received {result.__class__.__name__}, expected NodeSpecificResponse"
546547
)
547548

548549

0 commit comments

Comments
 (0)