diff --git a/homeassistant/components/demo/vacuum.py b/homeassistant/components/demo/vacuum.py index a5d85aa9bd6..528944ae27b 100644 --- a/homeassistant/components/demo/vacuum.py +++ b/homeassistant/components/demo/vacuum.py @@ -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 diff --git a/homeassistant/components/mqtt/vacuum/schema_legacy.py b/homeassistant/components/mqtt/vacuum/schema_legacy.py index c4259272bb3..b69565f7114 100644 --- a/homeassistant/components/mqtt/vacuum/schema_legacy.py +++ b/homeassistant/components/mqtt/vacuum/schema_legacy.py @@ -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 diff --git a/homeassistant/components/mqtt/vacuum/schema_state.py b/homeassistant/components/mqtt/vacuum/schema_state.py index 9049df45110..628f85614fe 100644 --- a/homeassistant/components/mqtt/vacuum/schema_state.py +++ b/homeassistant/components/mqtt/vacuum/schema_state.py @@ -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 diff --git a/homeassistant/components/roomba/irobot_base.py b/homeassistant/components/roomba/irobot_base.py index 035428192c0..8bc1e22547f 100644 --- a/homeassistant/components/roomba/irobot_base.py +++ b/homeassistant/components/roomba/irobot_base.py @@ -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.""" diff --git a/homeassistant/components/vacuum/__init__.py b/homeassistant/components/vacuum/__init__.py index 111fa64f988..ca5caec7ac1 100644 --- a/homeassistant/components/vacuum/__init__.py +++ b/homeassistant/components/vacuum/__init__.py @@ -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()