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
|
@property
|
||||||
def status(self):
|
def status(self):
|
||||||
"""Return the status of the vacuum."""
|
"""Return the status of the vacuum."""
|
||||||
if self.supported_features & SUPPORT_STATUS == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
return self._status
|
return self._status
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed(self):
|
def fan_speed(self):
|
||||||
"""Return the status of the vacuum."""
|
"""Return the status of the vacuum."""
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
return self._fan_speed
|
return self._fan_speed
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed_list(self):
|
def fan_speed_list(self):
|
||||||
"""Return the status of the vacuum."""
|
"""Return the status of the vacuum."""
|
||||||
assert self.supported_features & SUPPORT_FAN_SPEED != 0
|
|
||||||
return FAN_SPEEDS
|
return FAN_SPEEDS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self):
|
||||||
"""Return the status of the vacuum."""
|
"""Return the status of the vacuum."""
|
||||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
return max(0, min(100, self._battery_level))
|
return max(0, min(100, self._battery_level))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -289,24 +279,16 @@ class StateDemoVacuum(StateVacuumEntity):
|
||||||
@property
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self):
|
||||||
"""Return the current battery level of the vacuum."""
|
"""Return the current battery level of the vacuum."""
|
||||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
return max(0, min(100, self._battery_level))
|
return max(0, min(100, self._battery_level))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed(self):
|
def fan_speed(self):
|
||||||
"""Return the current fan speed of the vacuum."""
|
"""Return the current fan speed of the vacuum."""
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
return self._fan_speed
|
return self._fan_speed
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed_list(self):
|
def fan_speed_list(self):
|
||||||
"""Return the list of supported fan speeds."""
|
"""Return the list of supported fan speeds."""
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
|
||||||
return
|
|
||||||
return FAN_SPEEDS
|
return FAN_SPEEDS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -395,33 +395,21 @@ class MqttVacuum(
|
||||||
@property
|
@property
|
||||||
def status(self):
|
def status(self):
|
||||||
"""Return a status string for the vacuum."""
|
"""Return a status string for the vacuum."""
|
||||||
if self.supported_features & SUPPORT_STATUS == 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return self._status
|
return self._status
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed(self):
|
def fan_speed(self):
|
||||||
"""Return the status of the vacuum."""
|
"""Return the status of the vacuum."""
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return self._fan_speed
|
return self._fan_speed
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed_list(self):
|
def fan_speed_list(self):
|
||||||
"""Return the status of the vacuum.
|
"""Return the status of the vacuum."""
|
||||||
|
|
||||||
No need to check SUPPORT_FAN_SPEED, this won't be called if fan_speed is None.
|
|
||||||
"""
|
|
||||||
return self._fan_speed_list
|
return self._fan_speed_list
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self):
|
||||||
"""Return the status of the vacuum."""
|
"""Return the status of the vacuum."""
|
||||||
if self.supported_features & SUPPORT_BATTERY == 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return max(0, min(100, self._battery_level))
|
return max(0, min(100, self._battery_level))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -275,24 +275,16 @@ class MqttStateVacuum(
|
||||||
@property
|
@property
|
||||||
def fan_speed(self):
|
def fan_speed(self):
|
||||||
"""Return fan speed of the vacuum."""
|
"""Return fan speed of the vacuum."""
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return self._state_attrs.get(FAN_SPEED, 0)
|
return self._state_attrs.get(FAN_SPEED, 0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed_list(self):
|
def fan_speed_list(self):
|
||||||
"""Return fan speed list of the vacuum.
|
"""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 self._fan_speed_list
|
return self._fan_speed_list
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self):
|
||||||
"""Return battery level of the vacuum."""
|
"""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)))
|
return max(0, min(100, self._state_attrs.get(BATTERY, 0)))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -146,16 +146,6 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
|
||||||
"""Flag vacuum cleaner robot features that are supported."""
|
"""Flag vacuum cleaner robot features that are supported."""
|
||||||
return SUPPORT_IROBOT
|
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
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self):
|
||||||
"""Return the battery level of the vacuum cleaner."""
|
"""Return the battery level of the vacuum cleaner."""
|
||||||
|
|
|
@ -147,6 +147,11 @@ class _BaseVacuum(Entity):
|
||||||
"""Return the battery level of the vacuum cleaner."""
|
"""Return the battery level of the vacuum cleaner."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def battery_icon(self):
|
||||||
|
"""Return the battery icon for the vacuum cleaner."""
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed(self):
|
def fan_speed(self):
|
||||||
"""Return the fan speed of the vacuum cleaner."""
|
"""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."""
|
"""Get the list of available fan speed steps of the vacuum cleaner."""
|
||||||
raise NotImplementedError()
|
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):
|
def stop(self, **kwargs):
|
||||||
"""Stop the vacuum cleaner."""
|
"""Stop the vacuum cleaner."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -246,27 +271,14 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
|
||||||
battery_level=self.battery_level, charging=charging
|
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
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
"""Return the state attributes of the vacuum cleaner."""
|
"""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
|
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
|
return data
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
|
@ -337,27 +349,6 @@ class StateVacuumEntity(_BaseVacuum):
|
||||||
battery_level=self.battery_level, charging=charging
|
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):
|
def start(self):
|
||||||
"""Start or resume the cleaning task."""
|
"""Start or resume the cleaning task."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue