@@ -68,6 +68,7 @@ def __init__(
6868 send_fn : Callable [[PlugwiseRequest , bool ], Awaitable [PlugwiseResponse | None ]]
6969 | None ,
7070 mac : bytes | None ,
71+ node_response = True ,
7172 ) -> None :
7273 """Initialize request message."""
7374 super ().__init__ ()
@@ -104,9 +105,13 @@ def __init__(
104105 self ._unsubscribe_stick_response : Callable [[], None ] | None = None
105106 self ._unsubscribe_node_response : Callable [[], None ] | None = None
106107 self ._response_timeout : TimerHandle | None = None
107- self ._response_future : Future [PlugwiseResponse ] = self ._loop .create_future ()
108+ self ._response_future : Future [PlugwiseResponse ] | None = None
109+ if node_response :
110+ self ._response_future = self ._loop .create_future ()
108111 self ._waiting_for_response = False
109112
113+ self .node_response_expected : bool = node_response
114+
110115 def __repr__ (self ) -> str :
111116 """Convert request into writable str."""
112117 if self ._seq_id is None :
@@ -171,12 +176,13 @@ async def subscribe_to_response(
171176 self ._unsubscribe_stick_response = await stick_subscription_fn (
172177 self ._process_stick_response , self ._seq_id , None
173178 )
174- self ._unsubscribe_node_response = await node_subscription_fn (
175- self .process_node_response ,
176- self ._mac ,
177- (self ._reply_identifier ,),
178- self ._seq_id ,
179- )
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+ )
180186
181187 def _unsubscribe_from_stick (self ) -> None :
182188 """Unsubscribe from StickResponse messages."""
@@ -221,7 +227,8 @@ def _response_timeout_expired(self, stick_timeout: bool = False) -> None:
221227 )
222228 self ._seq_id = None
223229 self ._unsubscribe_from_stick ()
224- self ._unsubscribe_from_node ()
230+ if self .node_response_expected :
231+ self ._unsubscribe_from_node ()
225232 if stick_timeout :
226233 self ._response_future .set_exception (
227234 StickTimeout (f"USB-stick responded with time out to { self } " )
@@ -237,7 +244,8 @@ def assign_error(self, error: BaseException) -> None:
237244 """Assign error for this request."""
238245 self .stop_response_timeout ()
239246 self ._unsubscribe_from_stick ()
240- self ._unsubscribe_from_node ()
247+ if self .node_response_expected :
248+ self ._unsubscribe_from_node ()
241249 if self ._response_future .done ():
242250 return
243251 self ._waiting_for_response = False
@@ -266,7 +274,8 @@ async def process_node_response(self, response: PlugwiseResponse) -> bool:
266274 self ._response = copy (response )
267275 self .stop_response_timeout ()
268276 self ._unsubscribe_from_stick ()
269- self ._unsubscribe_from_node ()
277+ if self .node_response_expected :
278+ self ._unsubscribe_from_node ()
270279 if self ._send_counter > 1 :
271280 _LOGGER .debug (
272281 "Received %s after %s retries as reply to %s" ,
@@ -303,15 +312,11 @@ async def _process_stick_response(self, stick_response: StickResponse) -> None:
303312 self ,
304313 )
305314
306- async def _send_request (
307- self , suppress_node_errors = False , no_response_expected = False
308- ) -> PlugwiseResponse | None :
315+ async def _send_request (self , suppress_node_errors = False ) -> PlugwiseResponse | None :
309316 """Send request."""
310317 if self ._send_fn is None :
311318 return None
312- return await self ._send_fn (
313- self , suppress_node_errors , no_response_expected
314- )
319+ return await self ._send_fn (self , suppress_node_errors )
315320
316321 @property
317322 def max_retries (self ) -> int :
@@ -423,14 +428,14 @@ def __init__(
423428 accept : bool ,
424429 ) -> None :
425430 """Initialize NodeAddRequest message object."""
426- super ().__init__ (send_fn , mac )
431+ super ().__init__ (send_fn , mac , node_response = False )
427432 accept_value = 1 if accept else 0
428433 self ._args .append (Int (accept_value , length = 2 ))
429434
430435 async def send (self ) -> None :
431436 """Send request."""
432437 if (
433- result := await self ._send_request (no_response_expected = True )
438+ result := await self ._send_request ()
434439 ) is not None :
435440 raise MessageError (
436441 f"Invalid response message. Received { result .__class__ .__name__ } , expected no Response"
0 commit comments