Skip to content

Commit 345535f

Browse files
committed
Revert all no_node_response_expected changes
1 parent 3e3a5ad commit 345535f

File tree

3 files changed

+22
-29
lines changed

3 files changed

+22
-29
lines changed

plugwise_usb/connection/queue.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ async def submit(self, request: PlugwiseRequest) -> PlugwiseResponse | None:
9494

9595
await self._add_request_to_queue(request)
9696
try:
97-
if not request.node_response_expected:
98-
return None
9997
response: PlugwiseResponse = await request.response_future()
10098
return response
10199
except (NodeTimeout, StickTimeout) as exc:

plugwise_usb/connection/sender.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ async def write_request_to_port(self, request: PlugwiseRequest) -> None:
8181
serialized_data = request.serialize()
8282
_LOGGER.debug("write_request_to_port | Write %s to port as %s", request, serialized_data)
8383
self._transport.write(serialized_data)
84-
if request.node_response_expected:
85-
request.start_response_timeout()
84+
request.start_response_timeout()
8685

8786
# Wait for USB stick to accept request
8887
try:

plugwise_usb/messages/requests.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
NodeFeaturesResponse,
3434
NodeImageValidationResponse,
3535
NodeInfoResponse,
36+
NodeJoinAckResponse,
3637
NodePingResponse,
3738
NodeRemoveResponse,
3839
NodeResponse,
@@ -68,7 +69,6 @@ def __init__(
6869
send_fn: Callable[[PlugwiseRequest, bool], Awaitable[PlugwiseResponse | None]]
6970
| None,
7071
mac: bytes | None,
71-
node_response=True,
7272
) -> None:
7373
"""Initialize request message."""
7474
super().__init__()
@@ -105,12 +105,9 @@ def __init__(
105105
self._unsubscribe_stick_response: Callable[[], None] | None = None
106106
self._unsubscribe_node_response: Callable[[], None] | None = None
107107
self._response_timeout: TimerHandle | None = None
108-
self._response_future: Future[PlugwiseResponse] | None = None
109-
if node_response:
110-
self._response_future = self._loop.create_future()
108+
self._response_future: Future[PlugwiseResponse] = self._loop.create_future()
111109
self._waiting_for_response = False
112110

113-
self.node_response_expected: bool = node_response
114111

115112
def __repr__(self) -> str:
116113
"""Convert request into writable str."""
@@ -176,13 +173,12 @@ async def subscribe_to_response(
176173
self._unsubscribe_stick_response = await stick_subscription_fn(
177174
self._process_stick_response, self._seq_id, None
178175
)
179-
if self.node_response_expected:
180-
self._unsubscribe_node_response = await node_subscription_fn(
181-
self.process_node_response,
182-
self._mac,
183-
(self._reply_identifier,),
184-
self._seq_id,
185-
)
176+
self._unsubscribe_node_response = await node_subscription_fn(
177+
self.process_node_response,
178+
self._mac,
179+
(self._reply_identifier,),
180+
self._seq_id,
181+
)
186182

187183
def _unsubscribe_from_stick(self) -> None:
188184
"""Unsubscribe from StickResponse messages."""
@@ -227,8 +223,7 @@ def _response_timeout_expired(self, stick_timeout: bool = False) -> None:
227223
)
228224
self._seq_id = None
229225
self._unsubscribe_from_stick()
230-
if self.node_response_expected:
231-
self._unsubscribe_from_node()
226+
self._unsubscribe_from_node()
232227
if stick_timeout:
233228
self._response_future.set_exception(
234229
StickTimeout(f"USB-stick responded with time out to {self}")
@@ -244,8 +239,7 @@ def assign_error(self, error: BaseException) -> None:
244239
"""Assign error for this request."""
245240
self.stop_response_timeout()
246241
self._unsubscribe_from_stick()
247-
if self.node_response_expected:
248-
self._unsubscribe_from_node()
242+
self._unsubscribe_from_node()
249243
if self._response_future.done():
250244
return
251245
self._waiting_for_response = False
@@ -274,8 +268,7 @@ async def process_node_response(self, response: PlugwiseResponse) -> bool:
274268
self._response = copy(response)
275269
self.stop_response_timeout()
276270
self._unsubscribe_from_stick()
277-
if self.node_response_expected:
278-
self._unsubscribe_from_node()
271+
self._unsubscribe_from_node()
279272
if self._send_counter > 1:
280273
_LOGGER.debug(
281274
"Received %s after %s retries as reply to %s",
@@ -416,7 +409,7 @@ class NodeAddRequest(PlugwiseRequest):
416409
"""Add node to the Plugwise Network and add it to memory of Circle+ node.
417410
418411
Supported protocols : 1.0, 2.0
419-
Response message : (@bouwew) no Response
412+
Response message : NodeJoinAckResponse, b"0061"
420413
"""
421414

422415
_identifier = b"0007"
@@ -432,13 +425,16 @@ def __init__(
432425
accept_value = 1 if accept else 0
433426
self._args.append(Int(accept_value, length=2))
434427

435-
async def send(self) -> None:
428+
async def send(self) -> NodeJoinAckResponse | None:
436429
"""Send request."""
437-
if (
438-
result := await self._send_request()
439-
) is not None:
440-
raise MessageError(
441-
f"Invalid response message. Received {result.__class__.__name__}, expected no Response"
430+
if (result := await self._send_request()) is None:
431+
return None
432+
433+
if isinstance(result, NodeJoinAckResponse):
434+
return result
435+
436+
raise MessageError(
437+
f"Invalid response message. Received {result.__class__.__name__}, expected NodeJoinAckResponse"
442438
)
443439

444440
# This message has an exceptional format (MAC at end of message)

0 commit comments

Comments
 (0)