@@ -266,7 +266,15 @@ def __init__(self, item) -> None:
266266
267267 self ._attr_supported_features = self .vacuum .getHomeAssistantFeatures ()
268268 self ._attr_robovac_supported = self .vacuum .getRoboVacFeatures ()
269- self ._attr_fan_speed_list = self .vacuum .getFanSpeeds ()
269+
270+ fan_speeds = self .vacuum .getFanSpeeds ()
271+ self .fan_speed_map = {}
272+
273+ for speed in fan_speeds :
274+ self .fan_speed_map [friendly_text (speed )] = speed
275+
276+ self ._attr_fan_speed_list = list (self .fan_speed_map .keys ())
277+ _LOGGER .debug (self ._attr_fan_speed_list )
270278 self ._tuya_command_codes = self .vacuum .getCommandCodes ()
271279
272280 self ._attr_mode = None
@@ -285,19 +293,14 @@ def __init__(self, item) -> None:
285293 self .tuya_state = None
286294 self .tuyastatus = None
287295
296+ async def async_added_to_hass (self ):
297+ await self .async_forced_update ()
298+
288299 async def async_update (self ):
289300 """Synchronise state from the vacuum."""
290- if self .error_code == "UNSUPPORTED_MODEL" :
291- return
292-
293- if self .ip_address == "" :
294- self .error_code = "IP_ADDRESS"
295- return
296-
297301 try :
298- await self .vacuum . async_get ()
302+ await self .async_update_vacuum ()
299303 self .update_failures = 0
300- self .update_entity_values ()
301304 except TuyaException as e :
302305 self .update_failures += 1
303306 _LOGGER .warn (
@@ -308,6 +311,21 @@ async def async_update(self):
308311 if self .update_failures >= UPDATE_RETRIES :
309312 self .error_code = "CONNECTION_FAILED"
310313
314+ async def async_update_vacuum (self ):
315+ if self .error_code == "UNSUPPORTED_MODEL" :
316+ return
317+
318+ if self .ip_address == "" :
319+ self .error_code = "IP_ADDRESS"
320+ return
321+
322+ await self .vacuum .async_get ()
323+ self .update_entity_values ()
324+
325+ async def async_forced_update (self ):
326+ await self .async_update_vacuum ()
327+ self .async_write_ha_state ()
328+
311329 async def pushed_update_handler (self ):
312330 self .update_entity_values ()
313331 self .async_write_ha_state ()
@@ -327,8 +345,8 @@ def update_entity_values(self):
327345 self ._attr_mode = self .tuyastatus .get (
328346 self ._tuya_command_codes [RobovacCommand .MODE ]
329347 )
330- self ._attr_fan_speed = self . tuyastatus . get (
331- self ._tuya_command_codes [RobovacCommand .FAN_SPEED ]
348+ self ._attr_fan_speed = friendly_text (
349+ self .tuyastatus . get ( self . _tuya_command_codes [RobovacCommand .FAN_SPEED ], "" )
332350 )
333351
334352 if self .robovac_supported & RoboVacEntityFeature .CLEANING_AREA :
@@ -414,7 +432,11 @@ async def async_set_fan_speed(self, fan_speed, **kwargs):
414432 """Set fan speed."""
415433 _LOGGER .info ("Fan Speed Selected" )
416434 await self .vacuum .async_set (
417- {self ._tuya_command_codes [RobovacCommand .FAN_SPEED ]: fan_speed }
435+ {
436+ self ._tuya_command_codes [RobovacCommand .FAN_SPEED ]: self .fan_speed_map [
437+ fan_speed
438+ ]
439+ }
418440 )
419441
420442 async def async_send_command (
@@ -461,3 +483,9 @@ async def async_send_command(
461483
462484 async def async_will_remove_from_hass (self ):
463485 await self .vacuum .async_disable ()
486+
487+
488+ def friendly_text (input ):
489+ return " " .join (
490+ word [0 ].upper () + word [1 :] for word in input .replace ("_" , " " ).split ()
491+ )
0 commit comments