@@ -85,6 +85,28 @@ async def execute_command(self, command: Command):
85
85
86
86
await self .handle (command .name , response )
87
87
88
+ def set_status (self , * , available : bool = True , status : Optional [VacuumState ] = None ):
89
+ self .statusEvents .notify (StatusEvent (available , status ))
90
+
91
+ last_status = self .vacuum_status
92
+
93
+ if not available :
94
+ self .vacuum_status = None
95
+ elif status is not None :
96
+ self .vacuum_status = status
97
+
98
+ if last_status is None and available :
99
+ # bot was unavailable
100
+ if status is None :
101
+ self .statusEvents .request_refresh ()
102
+ self .errorEvents .request_refresh ()
103
+ self .fanSpeedEvents .request_refresh ()
104
+ self .cleanLogsEvents .request_refresh ()
105
+ self .waterEvents .request_refresh ()
106
+ self .batteryEvents .request_refresh ()
107
+ self .statsEvents .request_refresh ()
108
+ self .lifespanEvents .request_refresh ()
109
+
88
110
# ---------------------------- EVENT HANDLING ----------------------------
89
111
90
112
async def handle (self , event_name : str , event : dict , requested : bool = True ) -> None :
@@ -193,8 +215,7 @@ async def _handle_error(self, event: dict, event_data: dict):
193
215
description = ERROR_CODES .get (error )
194
216
if error != 0 :
195
217
_LOGGER .warning (f"Bot in error-state: code={ error } , description={ description } " )
196
- self .vacuum_status = VacuumState .STATE_ERROR
197
- self .statusEvents .notify (StatusEvent (True , self .vacuum_status ))
218
+ self .set_status (status = VacuumState .STATE_ERROR )
198
219
self .errorEvents .notify (ErrorEvent (error , description ))
199
220
else :
200
221
_LOGGER .warning (f"Could not process error event with received data: { event } " )
@@ -227,13 +248,11 @@ async def _handle_charge_state_requested(self, event_body: dict):
227
248
status = VacuumState .STATE_ERROR
228
249
229
250
if status :
230
- self .vacuum_status = status
231
- self .statusEvents .notify (StatusEvent (True , status ))
251
+ self .set_status (status = status )
232
252
233
253
async def _handle_charge_state (self , event_data : dict ):
234
254
if event_data .get ("isCharging" ) == 1 :
235
- self .vacuum_status = VacuumState .STATE_DOCKED
236
- self .statusEvents .notify (StatusEvent (True , self .vacuum_status ))
255
+ self .set_status (status = VacuumState .STATE_DOCKED )
237
256
238
257
async def _handle_life_span (self , event_data : dict ):
239
258
component : dict
@@ -295,8 +314,7 @@ async def _handle_clean_info(self, event_data: dict):
295
314
status = VacuumState .STATE_RETURNING
296
315
297
316
if status :
298
- self .vacuum_status = status
299
- self .statusEvents .notify (StatusEvent (True , status ))
317
+ self .set_status (status = status )
300
318
301
319
if self .vacuum_status == VacuumState .STATE_DOCKED :
302
320
self .cleanLogsEvents .request_refresh ()
0 commit comments