@@ -150,6 +150,7 @@ def __init__(
150150 coordinator .duid_slug ,
151151 coordinator ,
152152 )
153+ self ._status_trait = coordinator .properties_api .status
153154 self ._home_trait = coordinator .properties_api .home
154155 self ._maps_trait = coordinator .properties_api .maps
155156
@@ -176,31 +177,37 @@ def _handle_coordinator_update(self) -> None:
176177 @property
177178 def fan_speed_list (self ) -> list [str ]:
178179 """Get the list of available fan speeds."""
179- return [mode .value for mode in self ._device_status .fan_speed_options ]
180+ if self .coordinator .data is None :
181+ return []
182+ return [mode .value for mode in self ._status_trait .fan_speed_options ]
180183
181184 @property
182185 def activity (self ) -> VacuumActivity | None :
183186 """Return the status of the vacuum cleaner."""
184- assert self ._device_status .state is not None
185- return STATE_CODE_TO_STATE .get (self ._device_status .state )
187+ if self .coordinator .data is None or self ._status_trait .state is None :
188+ return None
189+ return STATE_CODE_TO_STATE .get (self ._status_trait .state )
186190
187191 @property
188192 def fan_speed (self ) -> str | None :
189193 """Return the fan speed of the vacuum cleaner."""
190- return self ._device_status .fan_speed_name
194+ if self .coordinator .data is None :
195+ return None
196+ return self ._status_trait .fan_speed_name
191197
192198 async def async_start (self ) -> None :
193199 """Start the vacuum."""
194- if self ._device_status .in_returning == 1 :
195- await self .send (RoborockCommand .APP_CHARGE )
196- elif self ._device_status .in_cleaning == 2 :
197- await self .send (RoborockCommand .RESUME_ZONED_CLEAN )
198- elif self ._device_status .in_cleaning == 3 :
199- await self .send (RoborockCommand .RESUME_SEGMENT_CLEAN )
200- elif self ._device_status .in_cleaning == 4 :
201- await self .send (RoborockCommand .APP_RESUME_BUILD_MAP )
202- else :
203- await self .send (RoborockCommand .APP_START )
200+ command = RoborockCommand .APP_START
201+ if self .coordinator .data is not None :
202+ if self ._status_trait .in_returning == 1 :
203+ command = RoborockCommand .APP_CHARGE
204+ elif self ._status_trait .in_cleaning == 2 :
205+ command = RoborockCommand .RESUME_ZONED_CLEAN
206+ elif self ._status_trait .in_cleaning == 3 :
207+ command = RoborockCommand .RESUME_SEGMENT_CLEAN
208+ elif self ._status_trait .in_cleaning == 4 :
209+ command = RoborockCommand .APP_RESUME_BUILD_MAP
210+ await self .send (command )
204211
205212 async def async_pause (self ) -> None :
206213 """Pause the vacuum."""
@@ -224,10 +231,15 @@ async def async_locate(self, **kwargs: Any) -> None:
224231
225232 async def async_set_fan_speed (self , fan_speed : str , ** kwargs : Any ) -> None :
226233 """Set vacuum fan speed."""
234+ if self .coordinator .data is None :
235+ raise HomeAssistantError (
236+ translation_domain = DOMAIN ,
237+ translation_key = "update_options_failed" ,
238+ )
227239 await self .send (
228240 RoborockCommand .SET_CUSTOM_MODE ,
229241 [
230- {v : k for k , v in self ._device_status .fan_speed_mapping .items ()}[
242+ {v : k for k , v in self ._status_trait .fan_speed_mapping .items ()}[
231243 fan_speed
232244 ]
233245 ],
0 commit comments