Home Assistant Unofficial Reference 2024.12.1
vacuum.py
Go to the documentation of this file.
1 """Support for Wi-Fi enabled ROMY vacuum cleaner robots.
2 
3 For more details about this platform, please refer to the documentation
4 https://home-assistant.io/components/vacuum.romy/.
5 """
6 
7 from typing import Any
8 
9 from homeassistant.components.vacuum import StateVacuumEntity, VacuumEntityFeature
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.core import HomeAssistant, callback
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from .const import DOMAIN, LOGGER
15 from .coordinator import RomyVacuumCoordinator
16 from .entity import RomyEntity
17 
18 FAN_SPEED_NONE = "default"
19 FAN_SPEED_NORMAL = "normal"
20 FAN_SPEED_SILENT = "silent"
21 FAN_SPEED_INTENSIVE = "intensive"
22 FAN_SPEED_SUPER_SILENT = "super_silent"
23 FAN_SPEED_HIGH = "high"
24 FAN_SPEED_AUTO = "auto"
25 
26 FAN_SPEEDS: list[str] = [
27  FAN_SPEED_NONE,
28  FAN_SPEED_NORMAL,
29  FAN_SPEED_SILENT,
30  FAN_SPEED_INTENSIVE,
31  FAN_SPEED_SUPER_SILENT,
32  FAN_SPEED_HIGH,
33  FAN_SPEED_AUTO,
34 ]
35 
36 # Commonly supported features
37 SUPPORT_ROMY_ROBOT = (
38  VacuumEntityFeature.BATTERY
39  | VacuumEntityFeature.RETURN_HOME
40  | VacuumEntityFeature.STATE
41  | VacuumEntityFeature.START
42  | VacuumEntityFeature.STOP
43  | VacuumEntityFeature.FAN_SPEED
44 )
45 
46 
48  hass: HomeAssistant,
49  config_entry: ConfigEntry,
50  async_add_entities: AddEntitiesCallback,
51 ) -> None:
52  """Set up ROMY vacuum cleaner."""
53 
54  coordinator: RomyVacuumCoordinator = hass.data[DOMAIN][config_entry.entry_id]
55  async_add_entities([RomyVacuumEntity(coordinator)])
56 
57 
59  """Representation of a ROMY vacuum cleaner robot."""
60 
61  _attr_supported_features = SUPPORT_ROMY_ROBOT
62  _attr_fan_speed_list = FAN_SPEEDS
63  _attr_name = None
64 
65  def __init__(
66  self,
67  coordinator: RomyVacuumCoordinator,
68  ) -> None:
69  """Initialize the ROMY Robot."""
70  super().__init__(coordinator)
71  self._attr_unique_id_attr_unique_id = self.romyromyromy.unique_id
72 
73  @callback
74  def _handle_coordinator_update(self) -> None:
75  """Handle updated data from the coordinator."""
76  self._attr_fan_speed_attr_fan_speed = FAN_SPEEDS[self.romyromyromy.fan_speed]
77  self._attr_battery_level_attr_battery_level = self.romyromyromy.battery_level
78  self._attr_state_attr_state = self.romyromyromy.status
79 
80  self.async_write_ha_stateasync_write_ha_state()
81 
82  async def async_start(self, **kwargs: Any) -> None:
83  """Turn the vacuum on."""
84  LOGGER.debug("async_start")
85  await self.romyromyromy.async_clean_start_or_continue()
86 
87  async def async_stop(self, **kwargs: Any) -> None:
88  """Stop the vacuum cleaner."""
89  LOGGER.debug("async_stop")
90  await self.romyromyromy.async_stop()
91 
92  async def async_return_to_base(self, **kwargs: Any) -> None:
93  """Return vacuum back to base."""
94  LOGGER.debug("async_return_to_base")
95  await self.romyromyromy.async_return_to_base()
96 
97  async def async_set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
98  """Set fan speed."""
99  LOGGER.debug("async_set_fan_speed to %s", fan_speed)
100  await self.romyromyromy.async_set_fan_speed(FAN_SPEEDS.index(fan_speed))
None __init__(self, RomyVacuumCoordinator coordinator)
Definition: vacuum.py:68
None async_set_fan_speed(self, str fan_speed, **Any kwargs)
Definition: vacuum.py:97
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: vacuum.py:51