@@ -49,8 +49,13 @@ async def start(self) -> None:
4949 # Other stick responses are not related to this request.
5050 self ._unsubscribe_stick_response = (
5151 await self ._receiver .subscribe_to_stick_responses (
52- self ._process_stick_response , None , (StickResponseType .ACCEPT ,)
53- # self._process_stick_response, None, (StickResponseType.ACCEPT, StickResponseType.FAILED)
52+ self ._process_stick_response ,
53+ None ,
54+ (
55+ StickResponseType .ACCEPT ,
56+ StickResponseType .TIMEOUT ,
57+ StickResponseType .FAILED ,
58+ ),
5459 )
5560 )
5661
@@ -68,7 +73,7 @@ async def write_request_to_port(self, request: PlugwiseRequest) -> None:
6873
6974 # Write message to serial port buffer
7075 serialized_data = request .serialize ()
71- _LOGGER .debug ("Write %s to port as %s" , request , serialized_data )
76+ _LOGGER .debug ("write_request_to_port | Write %s to port as %s" , request , serialized_data )
7277 self ._transport .write (serialized_data )
7378 request .start_response_timeout ()
7479
@@ -93,15 +98,21 @@ async def write_request_to_port(self, request: PlugwiseRequest) -> None:
9398 _LOGGER .warning ("Exception for %s: %s" , request , exc )
9499 request .assign_error (exc )
95100 else :
96- _LOGGER .debug (
97- "USB-Stick replied with %s to request %s" , response , request
98- )
101+ _LOGGER .debug ("write_request_to_port | USB-Stick replied with %s to request %s" , response , request )
99102 if response .response_type == StickResponseType .ACCEPT :
100- request .seq_id = response .seq_id
101- await request .subscribe_to_response (
102- self ._receiver .subscribe_to_stick_responses ,
103- self ._receiver .subscribe_to_node_responses ,
104- )
103+ if request .seq_id is not None :
104+ request .assign_error (
105+ BaseException (
106+ StickError (f"USB-Stick failed communication for { request } " )
107+ )
108+ )
109+ else :
110+ request .seq_id = response .seq_id
111+ await request .subscribe_to_response (
112+ self ._receiver .subscribe_to_stick_responses ,
113+ self ._receiver .subscribe_to_node_responses ,
114+ )
115+ _LOGGER .debug ("write_request_to_port | request has subscribed : %s" , request )
105116 elif response .response_type == StickResponseType .TIMEOUT :
106117 _LOGGER .warning (
107118 "USB-Stick directly responded with communication timeout for %s" ,
0 commit comments