Improve Vacuum Entity (#35554)
This commit is contained in:
parent
e61280095e
commit
7e67b6b568
5 changed files with 29 additions and 86 deletions
|
@ -126,31 +126,21 @@ class DemoVacuum(VacuumEntity):
|
|||
@property
|
||||
def status(self):
|
||||
"""Return the status of the vacuum."""
|
||||
if self.supported_features & SUPPORT_STATUS == 0:
|
||||
return
|
||||
|
||||
return self._status
|
||||
|
||||
@property
|
||||
def fan_speed(self):
|
||||
"""Return the status of the vacuum."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
||||
return
|
||||
|
||||
return self._fan_speed
|
||||
|
||||
@property
|
||||
def fan_speed_list(self):
|
||||
"""Return the status of the vacuum."""
|
||||
assert self.supported_features & SUPPORT_FAN_SPEED != 0
|
||||
return FAN_SPEEDS
|
||||
|
||||
@property
|
||||
def battery_level(self):
|
||||
"""Return the status of the vacuum."""
|
||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
||||
return
|
||||
|
||||
return max(0, min(100, self._battery_level))
|
||||
|
||||
@property
|
||||
|
@ -289,24 +279,16 @@ class StateDemoVacuum(StateVacuumEntity):
|
|||
@property
|
||||
def battery_level(self):
|
||||
"""Return the current battery level of the vacuum."""
|
||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
||||
return
|
||||
|
||||
return max(0, min(100, self._battery_level))
|
||||
|
||||
@property
|
||||
def fan_speed(self):
|
||||
"""Return the current fan speed of the vacuum."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
||||
return
|
||||
|
||||
return self._fan_speed
|
||||
|
||||
@property
|
||||
def fan_speed_list(self):
|
||||
"""Return the list of supported fan speeds."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
||||
return
|
||||
return FAN_SPEEDS
|
||||
|
||||
@property
|
||||
|
|
|
@ -395,33 +395,21 @@ class MqttVacuum(
|
|||
@property
|
||||
def status(self):
|
||||
"""Return a status string for the vacuum."""
|
||||
if self.supported_features & SUPPORT_STATUS == 0:
|
||||
return None
|
||||
|
||||
return self._status
|
||||
|
||||
@property
|
||||
def fan_speed(self):
|
||||
"""Return the status of the vacuum."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
||||
return None
|
||||
|
||||
return self._fan_speed
|
||||
|
||||
@property
|
||||
def fan_speed_list(self):
|
||||
"""Return the status of the vacuum.
|
||||
|
||||
No need to check SUPPORT_FAN_SPEED, this won't be called if fan_speed is None.
|
||||
"""
|
||||
"""Return the status of the vacuum."""
|
||||
return self._fan_speed_list
|
||||
|
||||
@property
|
||||
def battery_level(self):
|
||||
"""Return the status of the vacuum."""
|
||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
||||
return None
|
||||
|
||||
return max(0, min(100, self._battery_level))
|
||||
|
||||
@property
|
||||
|
|
|
@ -275,24 +275,16 @@ class MqttStateVacuum(
|
|||
@property
|
||||
def fan_speed(self):
|
||||
"""Return fan speed of the vacuum."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
||||
return None
|
||||
|
||||
return self._state_attrs.get(FAN_SPEED, 0)
|
||||
|
||||
@property
|
||||
def fan_speed_list(self):
|
||||
"""Return fan speed list of the vacuum.
|
||||
|
||||
No need to check SUPPORT_FAN_SPEED, this won't be called if fan_speed is None.
|
||||
"""
|
||||
"""Return fan speed list of the vacuum."""
|
||||
return self._fan_speed_list
|
||||
|
||||
@property
|
||||
def battery_level(self):
|
||||
"""Return battery level of the vacuum."""
|
||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
||||
return None
|
||||
return max(0, min(100, self._state_attrs.get(BATTERY, 0)))
|
||||
|
||||
@property
|
||||
|
|
|
@ -146,16 +146,6 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
|
|||
"""Flag vacuum cleaner robot features that are supported."""
|
||||
return SUPPORT_IROBOT
|
||||
|
||||
@property
|
||||
def fan_speed(self):
|
||||
"""Return the fan speed of the vacuum cleaner."""
|
||||
return None
|
||||
|
||||
@property
|
||||
def fan_speed_list(self):
|
||||
"""Get the list of available fan speed steps of the vacuum cleaner."""
|
||||
return []
|
||||
|
||||
@property
|
||||
def battery_level(self):
|
||||
"""Return the battery level of the vacuum cleaner."""
|
||||
|
|
|
@ -147,6 +147,11 @@ class _BaseVacuum(Entity):
|
|||
"""Return the battery level of the vacuum cleaner."""
|
||||
return None
|
||||
|
||||
@property
|
||||
def battery_icon(self):
|
||||
"""Return the battery icon for the vacuum cleaner."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def fan_speed(self):
|
||||
"""Return the fan speed of the vacuum cleaner."""
|
||||
|
@ -157,6 +162,26 @@ class _BaseVacuum(Entity):
|
|||
"""Get the list of available fan speed steps of the vacuum cleaner."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def capability_attributes(self):
|
||||
"""Return capability attributes."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED:
|
||||
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
"""Return the state attributes of the vacuum cleaner."""
|
||||
data = {}
|
||||
|
||||
if self.supported_features & SUPPORT_BATTERY:
|
||||
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
||||
data[ATTR_BATTERY_ICON] = self.battery_icon
|
||||
|
||||
if self.supported_features & SUPPORT_FAN_SPEED:
|
||||
data[ATTR_FAN_SPEED] = self.fan_speed
|
||||
|
||||
return data
|
||||
|
||||
def stop(self, **kwargs):
|
||||
"""Stop the vacuum cleaner."""
|
||||
raise NotImplementedError()
|
||||
|
@ -246,27 +271,14 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
|
|||
battery_level=self.battery_level, charging=charging
|
||||
)
|
||||
|
||||
@property
|
||||
def capability_attributes(self):
|
||||
"""Return capability attributes."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED:
|
||||
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
"""Return the state attributes of the vacuum cleaner."""
|
||||
data = {}
|
||||
data = super().state_attributes
|
||||
|
||||
if self.status is not None:
|
||||
if self.supported_features & SUPPORT_STATUS:
|
||||
data[ATTR_STATUS] = self.status
|
||||
|
||||
if self.battery_level is not None:
|
||||
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
||||
data[ATTR_BATTERY_ICON] = self.battery_icon
|
||||
|
||||
if self.fan_speed is not None:
|
||||
data[ATTR_FAN_SPEED] = self.fan_speed
|
||||
|
||||
return data
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
|
@ -337,27 +349,6 @@ class StateVacuumEntity(_BaseVacuum):
|
|||
battery_level=self.battery_level, charging=charging
|
||||
)
|
||||
|
||||
@property
|
||||
def capability_attributes(self):
|
||||
"""Return capability attributes."""
|
||||
if self.supported_features & SUPPORT_FAN_SPEED:
|
||||
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
"""Return the state attributes of the vacuum cleaner."""
|
||||
data = {}
|
||||
|
||||
if self.battery_level is not None:
|
||||
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
||||
data[ATTR_BATTERY_ICON] = self.battery_icon
|
||||
|
||||
if self.fan_speed is not None:
|
||||
data[ATTR_FAN_SPEED] = self.fan_speed
|
||||
data[ATTR_FAN_SPEED_LIST] = self.fan_speed_list
|
||||
|
||||
return data
|
||||
|
||||
def start(self):
|
||||
"""Start or resume the cleaning task."""
|
||||
raise NotImplementedError()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue