@@ -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
0 commit comments