@@ -138,16 +138,22 @@ def handle_select(rlist: list, wlist: list, *args: Any) -> list:
138138
139139
140140@pytest .fixture (name = "mqtt_client" )
141- def mqtt_client (mock_create_connection : None , mock_select : None ) -> Generator [RoborockMqttClientV1 , None , None ]:
141+ async def mqtt_client (mock_create_connection : None , mock_select : None ) -> Generator [RoborockMqttClientV1 , None , None ]:
142142 user_data = UserData .from_dict (USER_DATA )
143143 home_data = HomeData .from_dict (HOME_DATA_RAW )
144144 device_info = DeviceData (
145145 device = home_data .devices [0 ],
146146 model = home_data .products [0 ].model ,
147147 )
148148 client = RoborockMqttClientV1 (user_data , device_info )
149- yield client
150- # Clean up any resources after the test
149+ try :
150+ yield client
151+ finally :
152+ if not client .is_connected ():
153+ try :
154+ await client .async_release ()
155+ except Exception :
156+ pass
151157
152158
153159@pytest .fixture (name = "mock_rest" , autouse = True )
@@ -226,11 +232,19 @@ def handle_write(data: bytes) -> None:
226232
227233
228234@pytest .fixture (name = "local_client" )
229- def local_client_fixture (mock_create_local_connection : None ) -> Generator [RoborockLocalClientV1 , None , None ]:
235+ async def local_client_fixture (mock_create_local_connection : None ) -> Generator [RoborockLocalClientV1 , None , None ]:
230236 home_data = HomeData .from_dict (HOME_DATA_RAW )
231237 device_info = DeviceData (
232238 device = home_data .devices [0 ],
233239 model = home_data .products [0 ].model ,
234240 host = TEST_LOCAL_API_HOST ,
235241 )
236- yield RoborockLocalClientV1 (device_info )
242+ client = RoborockLocalClientV1 (device_info )
243+ try :
244+ yield client
245+ finally :
246+ if not client .is_connected ():
247+ try :
248+ await client .async_release ()
249+ except Exception :
250+ pass
0 commit comments