Home Assistant Unofficial Reference 2024.12.1
braava.py
Go to the documentation of this file.
1 """Class for Braava 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_DETECTED_PAD = "detected_pad"
12 ATTR_LID_CLOSED = "lid_closed"
13 ATTR_TANK_PRESENT = "tank_present"
14 ATTR_TANK_LEVEL = "tank_level"
15 ATTR_PAD_WETNESS = "spray_amount"
16 
17 OVERLAP_STANDARD = 67
18 OVERLAP_DEEP = 85
19 OVERLAP_EXTENDED = 25
20 MOP_STANDARD = "Standard"
21 MOP_DEEP = "Deep"
22 MOP_EXTENDED = "Extended"
23 BRAAVA_MOP_BEHAVIORS = [MOP_STANDARD, MOP_DEEP, MOP_EXTENDED]
24 BRAAVA_SPRAY_AMOUNT = [1, 2, 3]
25 
26 # Braava Jets can set mopping behavior through fanspeed
27 SUPPORT_BRAAVA = SUPPORT_IROBOT | VacuumEntityFeature.FAN_SPEED
28 
29 
30 class BraavaJet(IRobotVacuum): # pylint: disable=hass-enforce-class-module
31  """Braava Jet."""
32 
33  _attr_supported_features = SUPPORT_BRAAVA
34 
35  def __init__(self, roomba, blid):
36  """Initialize the Roomba handler."""
37  super().__init__(roomba, blid)
38 
39  # Initialize fan speed list
40  self._attr_fan_speed_list_attr_fan_speed_list = [
41  f"{behavior}-{spray}"
42  for behavior in BRAAVA_MOP_BEHAVIORS
43  for spray in BRAAVA_SPRAY_AMOUNT
44  ]
45 
46  @property
47  def fan_speed(self):
48  """Return the fan speed of the vacuum cleaner."""
49  # Mopping behavior and spray amount as fan speed
50  rank_overlap = self.vacuum_statevacuum_state.get("rankOverlap", {})
51  behavior = None
52  if rank_overlap == OVERLAP_STANDARD:
53  behavior = MOP_STANDARD
54  elif rank_overlap == OVERLAP_DEEP:
55  behavior = MOP_DEEP
56  elif rank_overlap == OVERLAP_EXTENDED:
57  behavior = MOP_EXTENDED
58  pad_wetness = self.vacuum_statevacuum_state.get("padWetness", {})
59  # "disposable" and "reusable" values are always the same
60  pad_wetness_value = pad_wetness.get("disposable")
61  return f"{behavior}-{pad_wetness_value}"
62 
63  async def async_set_fan_speed(self, fan_speed, **kwargs):
64  """Set fan speed."""
65  try:
66  split = fan_speed.split("-", 1)
67  behavior = split[0]
68  spray = int(split[1])
69  if behavior.capitalize() in BRAAVA_MOP_BEHAVIORS:
70  behavior = behavior.capitalize()
71  except IndexError:
72  _LOGGER.error(
73  "Fan speed error: expected {behavior}-{spray_amount}, got '%s'",
74  fan_speed,
75  )
76  return
77  except ValueError:
78  _LOGGER.error("Spray amount error: expected integer, got '%s'", split[1])
79  return
80  if behavior not in BRAAVA_MOP_BEHAVIORS:
81  _LOGGER.error(
82  "Mop behavior error: expected one of %s, got '%s'",
83  str(BRAAVA_MOP_BEHAVIORS),
84  behavior,
85  )
86  return
87  if spray not in BRAAVA_SPRAY_AMOUNT:
88  _LOGGER.error(
89  "Spray amount error: expected one of %s, got '%d'",
90  str(BRAAVA_SPRAY_AMOUNT),
91  spray,
92  )
93  return
94 
95  overlap = 0
96  if behavior == MOP_STANDARD:
97  overlap = OVERLAP_STANDARD
98  elif behavior == MOP_DEEP:
99  overlap = OVERLAP_DEEP
100  else:
101  overlap = OVERLAP_EXTENDED
102  await self.hasshass.async_add_executor_job(
103  self.vacuumvacuum.set_preference, "rankOverlap", overlap
104  )
105  await self.hasshass.async_add_executor_job(
106  self.vacuumvacuum.set_preference,
107  "padWetness",
108  {"disposable": spray, "reusable": spray},
109  )
110 
111  @property
113  """Return the state attributes of the device."""
114  state_attrs = super().extra_state_attributes
115 
116  # Get Braava state
117  state = self.vacuum_statevacuum_state
118  detected_pad = state.get("detectedPad")
119  mop_ready = state.get("mopReady", {})
120  lid_closed = mop_ready.get("lidClosed")
121  tank_present = mop_ready.get("tankPresent")
122  tank_level = state.get("tankLvl")
123  state_attrs[ATTR_DETECTED_PAD] = detected_pad
124  state_attrs[ATTR_LID_CLOSED] = lid_closed
125  state_attrs[ATTR_TANK_PRESENT] = tank_present
126  state_attrs[ATTR_TANK_LEVEL] = tank_level
127 
128  return state_attrs
def async_set_fan_speed(self, fan_speed, **kwargs)
Definition: braava.py:63
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88