Home Assistant Unofficial Reference 2024.12.1
roomba.py
Go to the documentation of this file.
1 """Class for Roomba devices."""
2 
3 import logging
4 
5 from homeassistant.components.vacuum import VacuumEntityFeature
6 
7 from .entity import SUPPORT_IROBOT, IRobotVacuum
8 
9 _LOGGER = logging.getLogger(__name__)
10 
11 ATTR_BIN_FULL = "bin_full"
12 ATTR_BIN_PRESENT = "bin_present"
13 
14 FAN_SPEED_AUTOMATIC = "Automatic"
15 FAN_SPEED_ECO = "Eco"
16 FAN_SPEED_PERFORMANCE = "Performance"
17 FAN_SPEEDS = [FAN_SPEED_AUTOMATIC, FAN_SPEED_ECO, FAN_SPEED_PERFORMANCE]
18 
19 # Only Roombas with CarpetBost can set their fanspeed
20 SUPPORT_ROOMBA_CARPET_BOOST = SUPPORT_IROBOT | VacuumEntityFeature.FAN_SPEED
21 
22 
23 class RoombaVacuum(IRobotVacuum): # pylint: disable=hass-enforce-class-module
24  """Basic Roomba robot (without carpet boost)."""
25 
26  @property
28  """Return the state attributes of the device."""
29  state_attrs = super().extra_state_attributes
30 
31  # Get bin state
32  bin_raw_state = self.vacuum_statevacuum_state.get("bin", {})
33  bin_state = {}
34  if bin_raw_state.get("present") is not None:
35  bin_state[ATTR_BIN_PRESENT] = bin_raw_state.get("present")
36  if bin_raw_state.get("full") is not None:
37  bin_state[ATTR_BIN_FULL] = bin_raw_state.get("full")
38  state_attrs.update(bin_state)
39 
40  return state_attrs
41 
42 
43 class RoombaVacuumCarpetBoost(RoombaVacuum): # pylint: disable=hass-enforce-class-module
44  """Roomba robot with carpet boost."""
45 
46  _attr_fan_speed_list = FAN_SPEEDS
47  _attr_supported_features = SUPPORT_ROOMBA_CARPET_BOOST
48 
49  @property
50  def fan_speed(self):
51  """Return the fan speed of the vacuum cleaner."""
52  fan_speed = None
53  carpet_boost = self.vacuum_statevacuum_state.get("carpetBoost")
54  high_perf = self.vacuum_statevacuum_state.get("vacHigh")
55  if carpet_boost is not None and high_perf is not None:
56  if carpet_boost:
57  fan_speed = FAN_SPEED_AUTOMATIC
58  elif high_perf:
59  fan_speed = FAN_SPEED_PERFORMANCE
60  else: # carpet_boost and high_perf are False
61  fan_speed = FAN_SPEED_ECO
62  return fan_speed
63 
64  async def async_set_fan_speed(self, fan_speed, **kwargs):
65  """Set fan speed."""
66  if fan_speed.capitalize() in FAN_SPEEDS:
67  fan_speed = fan_speed.capitalize()
68  _LOGGER.debug("Set fan speed to: %s", fan_speed)
69  high_perf = None
70  carpet_boost = None
71  if fan_speed == FAN_SPEED_AUTOMATIC:
72  high_perf = False
73  carpet_boost = True
74  elif fan_speed == FAN_SPEED_ECO:
75  high_perf = False
76  carpet_boost = False
77  elif fan_speed == FAN_SPEED_PERFORMANCE:
78  high_perf = True
79  carpet_boost = False
80  else:
81  _LOGGER.error("No such fan speed available: %s", fan_speed)
82  return
83  # The set_preference method does only accept string values
84  await self.hasshass.async_add_executor_job(
85  self.vacuumvacuum.set_preference, "carpetBoost", str(carpet_boost)
86  )
87  await self.hasshass.async_add_executor_job(
88  self.vacuumvacuum.set_preference, "vacHigh", str(high_perf)
89  )
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88