Skip to content

Commit

Permalink
Use backend-provided fan speed presets for Xiaomi vacuums
Browse files Browse the repository at this point in the history
This needs input from Xiaomi vacuum owners to verify that it does not break anything.
I have personally tested this on rockrobo v1 (old mapping).

Related issues/PRs:
home-assistant#32821
home-assistant#31268
home-assistant#27268

This is a WIP as it requires a new upstream release.
The PR is rytilahti/python-miio#643
  • Loading branch information
rytilahti committed Mar 15, 2020
1 parent 1391f90 commit a4453f7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions homeassistant/components/xiaomi_miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
extra=vol.ALLOW_EXTRA,
)

FAN_SPEEDS = {"Silent": 38, "Standard": 60, "Medium": 77, "Turbo": 90, "Gentle": 105}

ATTR_CLEAN_START = "clean_start"
ATTR_CLEAN_STOP = "clean_stop"
ATTR_CLEANING_TIME = "cleaning_time"
Expand Down Expand Up @@ -246,6 +244,7 @@ def __init__(self, name, vacuum):
self.clean_history = None
self.dnd_state = None
self.last_clean = None
self._fan_speeds = None

@property
def name(self):
Expand Down Expand Up @@ -281,14 +280,14 @@ def fan_speed(self):
"""Return the fan speed of the vacuum cleaner."""
if self.vacuum_state is not None:
speed = self.vacuum_state.fanspeed
if speed in FAN_SPEEDS.values():
return [key for key, value in FAN_SPEEDS.items() if value == speed][0]
if speed in self._fan_speeds.values():
return [key for key, value in self._fan_speeds.items() if value == speed][0]
return speed

@property
def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner."""
return list(sorted(FAN_SPEEDS.keys(), key=lambda s: FAN_SPEEDS[s]))
return list(self._fan_speeds)

@property
def device_state_attributes(self):
Expand Down Expand Up @@ -372,8 +371,8 @@ async def async_stop(self, **kwargs):

async def async_set_fan_speed(self, fan_speed, **kwargs):
"""Set fan speed."""
if fan_speed.capitalize() in FAN_SPEEDS:
fan_speed = FAN_SPEEDS[fan_speed.capitalize()]
if fan_speed.capitalize() in self._fan_speeds:
fan_speed = self._fan_speeds[fan_speed.capitalize()]
else:
try:
fan_speed = int(fan_speed)
Expand Down Expand Up @@ -453,6 +452,8 @@ def update(self):
state = self._vacuum.status()
self.vacuum_state = state

self._fan_speeds = self._vacuum.fan_speed_presets()

self.consumable_state = self._vacuum.consumable_status()
self.clean_history = self._vacuum.clean_history()
self.last_clean = self._vacuum.last_clean_details()
Expand Down

0 comments on commit a4453f7

Please sign in to comment.