mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add EntityFeature enum to Vacuum (#69121)
This commit is contained in:
parent
cce19dc480
commit
2d37066ce5
@ -8,21 +8,9 @@ from homeassistant.components.vacuum import (
|
|||||||
STATE_IDLE,
|
STATE_IDLE,
|
||||||
STATE_PAUSED,
|
STATE_PAUSED,
|
||||||
STATE_RETURNING,
|
STATE_RETURNING,
|
||||||
SUPPORT_BATTERY,
|
|
||||||
SUPPORT_CLEAN_SPOT,
|
|
||||||
SUPPORT_FAN_SPEED,
|
|
||||||
SUPPORT_LOCATE,
|
|
||||||
SUPPORT_PAUSE,
|
|
||||||
SUPPORT_RETURN_HOME,
|
|
||||||
SUPPORT_SEND_COMMAND,
|
|
||||||
SUPPORT_START,
|
|
||||||
SUPPORT_STATE,
|
|
||||||
SUPPORT_STATUS,
|
|
||||||
SUPPORT_STOP,
|
|
||||||
SUPPORT_TURN_OFF,
|
|
||||||
SUPPORT_TURN_ON,
|
|
||||||
StateVacuumEntity,
|
StateVacuumEntity,
|
||||||
VacuumEntity,
|
VacuumEntity,
|
||||||
|
VacuumEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -30,44 +18,47 @@ from homeassistant.helpers import event
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
SUPPORT_MINIMAL_SERVICES = SUPPORT_TURN_ON | SUPPORT_TURN_OFF
|
SUPPORT_MINIMAL_SERVICES = VacuumEntityFeature.TURN_ON | VacuumEntityFeature.TURN_OFF
|
||||||
|
|
||||||
SUPPORT_BASIC_SERVICES = (
|
SUPPORT_BASIC_SERVICES = (
|
||||||
SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_STATUS | SUPPORT_BATTERY
|
VacuumEntityFeature.TURN_ON
|
||||||
|
| VacuumEntityFeature.TURN_OFF
|
||||||
|
| VacuumEntityFeature.STATUS
|
||||||
|
| VacuumEntityFeature.BATTERY
|
||||||
)
|
)
|
||||||
|
|
||||||
SUPPORT_MOST_SERVICES = (
|
SUPPORT_MOST_SERVICES = (
|
||||||
SUPPORT_TURN_ON
|
VacuumEntityFeature.TURN_ON
|
||||||
| SUPPORT_TURN_OFF
|
| VacuumEntityFeature.TURN_OFF
|
||||||
| SUPPORT_STOP
|
| VacuumEntityFeature.STOP
|
||||||
| SUPPORT_RETURN_HOME
|
| VacuumEntityFeature.RETURN_HOME
|
||||||
| SUPPORT_STATUS
|
| VacuumEntityFeature.STATUS
|
||||||
| SUPPORT_BATTERY
|
| VacuumEntityFeature.BATTERY
|
||||||
)
|
)
|
||||||
|
|
||||||
SUPPORT_ALL_SERVICES = (
|
SUPPORT_ALL_SERVICES = (
|
||||||
SUPPORT_TURN_ON
|
VacuumEntityFeature.TURN_ON
|
||||||
| SUPPORT_TURN_OFF
|
| VacuumEntityFeature.TURN_OFF
|
||||||
| SUPPORT_PAUSE
|
| VacuumEntityFeature.PAUSE
|
||||||
| SUPPORT_STOP
|
| VacuumEntityFeature.STOP
|
||||||
| SUPPORT_RETURN_HOME
|
| VacuumEntityFeature.RETURN_HOME
|
||||||
| SUPPORT_FAN_SPEED
|
| VacuumEntityFeature.FAN_SPEED
|
||||||
| SUPPORT_SEND_COMMAND
|
| VacuumEntityFeature.SEND_COMMAND
|
||||||
| SUPPORT_LOCATE
|
| VacuumEntityFeature.LOCATE
|
||||||
| SUPPORT_STATUS
|
| VacuumEntityFeature.STATUS
|
||||||
| SUPPORT_BATTERY
|
| VacuumEntityFeature.BATTERY
|
||||||
| SUPPORT_CLEAN_SPOT
|
| VacuumEntityFeature.CLEAN_SPOT
|
||||||
)
|
)
|
||||||
|
|
||||||
SUPPORT_STATE_SERVICES = (
|
SUPPORT_STATE_SERVICES = (
|
||||||
SUPPORT_STATE
|
VacuumEntityFeature.STATE
|
||||||
| SUPPORT_PAUSE
|
| VacuumEntityFeature.PAUSE
|
||||||
| SUPPORT_STOP
|
| VacuumEntityFeature.STOP
|
||||||
| SUPPORT_RETURN_HOME
|
| VacuumEntityFeature.RETURN_HOME
|
||||||
| SUPPORT_FAN_SPEED
|
| VacuumEntityFeature.FAN_SPEED
|
||||||
| SUPPORT_BATTERY
|
| VacuumEntityFeature.BATTERY
|
||||||
| SUPPORT_CLEAN_SPOT
|
| VacuumEntityFeature.CLEAN_SPOT
|
||||||
| SUPPORT_START
|
| VacuumEntityFeature.START
|
||||||
)
|
)
|
||||||
|
|
||||||
FAN_SPEEDS = ["min", "medium", "high", "max"]
|
FAN_SPEEDS = ["min", "medium", "high", "max"]
|
||||||
@ -167,7 +158,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the vacuum on."""
|
"""Turn the vacuum on."""
|
||||||
if self.supported_features & SUPPORT_TURN_ON == 0:
|
if self.supported_features & VacuumEntityFeature.TURN_ON == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = True
|
self._state = True
|
||||||
@ -178,7 +169,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the vacuum off."""
|
"""Turn the vacuum off."""
|
||||||
if self.supported_features & SUPPORT_TURN_OFF == 0:
|
if self.supported_features & VacuumEntityFeature.TURN_OFF == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = False
|
self._state = False
|
||||||
@ -187,7 +178,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def stop(self, **kwargs):
|
def stop(self, **kwargs):
|
||||||
"""Stop the vacuum."""
|
"""Stop the vacuum."""
|
||||||
if self.supported_features & SUPPORT_STOP == 0:
|
if self.supported_features & VacuumEntityFeature.STOP == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = False
|
self._state = False
|
||||||
@ -196,7 +187,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def clean_spot(self, **kwargs):
|
def clean_spot(self, **kwargs):
|
||||||
"""Perform a spot clean-up."""
|
"""Perform a spot clean-up."""
|
||||||
if self.supported_features & SUPPORT_CLEAN_SPOT == 0:
|
if self.supported_features & VacuumEntityFeature.CLEAN_SPOT == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = True
|
self._state = True
|
||||||
@ -207,7 +198,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def locate(self, **kwargs):
|
def locate(self, **kwargs):
|
||||||
"""Locate the vacuum (usually by playing a song)."""
|
"""Locate the vacuum (usually by playing a song)."""
|
||||||
if self.supported_features & SUPPORT_LOCATE == 0:
|
if self.supported_features & VacuumEntityFeature.LOCATE == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._status = "Hi, I'm over here!"
|
self._status = "Hi, I'm over here!"
|
||||||
@ -215,7 +206,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def start_pause(self, **kwargs):
|
def start_pause(self, **kwargs):
|
||||||
"""Start, pause or resume the cleaning task."""
|
"""Start, pause or resume the cleaning task."""
|
||||||
if self.supported_features & SUPPORT_PAUSE == 0:
|
if self.supported_features & VacuumEntityFeature.PAUSE == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = not self._state
|
self._state = not self._state
|
||||||
@ -229,7 +220,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def set_fan_speed(self, fan_speed, **kwargs):
|
def set_fan_speed(self, fan_speed, **kwargs):
|
||||||
"""Set the vacuum's fan speed."""
|
"""Set the vacuum's fan speed."""
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
if self.supported_features & VacuumEntityFeature.FAN_SPEED == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
if fan_speed in self.fan_speed_list:
|
if fan_speed in self.fan_speed_list:
|
||||||
@ -238,7 +229,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def return_to_base(self, **kwargs):
|
def return_to_base(self, **kwargs):
|
||||||
"""Tell the vacuum to return to its dock."""
|
"""Tell the vacuum to return to its dock."""
|
||||||
if self.supported_features & SUPPORT_RETURN_HOME == 0:
|
if self.supported_features & VacuumEntityFeature.RETURN_HOME == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = False
|
self._state = False
|
||||||
@ -248,7 +239,7 @@ class DemoVacuum(VacuumEntity):
|
|||||||
|
|
||||||
def send_command(self, command, params=None, **kwargs):
|
def send_command(self, command, params=None, **kwargs):
|
||||||
"""Send a command to the vacuum."""
|
"""Send a command to the vacuum."""
|
||||||
if self.supported_features & SUPPORT_SEND_COMMAND == 0:
|
if self.supported_features & VacuumEntityFeature.SEND_COMMAND == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._status = f"Executing {command}({params})"
|
self._status = f"Executing {command}({params})"
|
||||||
@ -310,7 +301,7 @@ class StateDemoVacuum(StateVacuumEntity):
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start or resume the cleaning task."""
|
"""Start or resume the cleaning task."""
|
||||||
if self.supported_features & SUPPORT_START == 0:
|
if self.supported_features & VacuumEntityFeature.START == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._state != STATE_CLEANING:
|
if self._state != STATE_CLEANING:
|
||||||
@ -321,7 +312,7 @@ class StateDemoVacuum(StateVacuumEntity):
|
|||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
"""Pause the cleaning task."""
|
"""Pause the cleaning task."""
|
||||||
if self.supported_features & SUPPORT_PAUSE == 0:
|
if self.supported_features & VacuumEntityFeature.PAUSE == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._state == STATE_CLEANING:
|
if self._state == STATE_CLEANING:
|
||||||
@ -330,7 +321,7 @@ class StateDemoVacuum(StateVacuumEntity):
|
|||||||
|
|
||||||
def stop(self, **kwargs):
|
def stop(self, **kwargs):
|
||||||
"""Stop the cleaning task, do not return to dock."""
|
"""Stop the cleaning task, do not return to dock."""
|
||||||
if self.supported_features & SUPPORT_STOP == 0:
|
if self.supported_features & VacuumEntityFeature.STOP == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = STATE_IDLE
|
self._state = STATE_IDLE
|
||||||
@ -338,7 +329,7 @@ class StateDemoVacuum(StateVacuumEntity):
|
|||||||
|
|
||||||
def return_to_base(self, **kwargs):
|
def return_to_base(self, **kwargs):
|
||||||
"""Return dock to charging base."""
|
"""Return dock to charging base."""
|
||||||
if self.supported_features & SUPPORT_RETURN_HOME == 0:
|
if self.supported_features & VacuumEntityFeature.RETURN_HOME == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = STATE_RETURNING
|
self._state = STATE_RETURNING
|
||||||
@ -348,7 +339,7 @@ class StateDemoVacuum(StateVacuumEntity):
|
|||||||
|
|
||||||
def clean_spot(self, **kwargs):
|
def clean_spot(self, **kwargs):
|
||||||
"""Perform a spot clean-up."""
|
"""Perform a spot clean-up."""
|
||||||
if self.supported_features & SUPPORT_CLEAN_SPOT == 0:
|
if self.supported_features & VacuumEntityFeature.CLEAN_SPOT == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = STATE_CLEANING
|
self._state = STATE_CLEANING
|
||||||
@ -358,7 +349,7 @@ class StateDemoVacuum(StateVacuumEntity):
|
|||||||
|
|
||||||
def set_fan_speed(self, fan_speed, **kwargs):
|
def set_fan_speed(self, fan_speed, **kwargs):
|
||||||
"""Set the vacuum's fan speed."""
|
"""Set the vacuum's fan speed."""
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED == 0:
|
if self.supported_features & VacuumEntityFeature.FAN_SPEED == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
if fan_speed in self.fan_speed_list:
|
if fan_speed in self.fan_speed_list:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Support for vacuum cleaner robots (botvacs)."""
|
"""Support for vacuum cleaner robots (botvacs)."""
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from enum import IntEnum
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
from typing import final
|
from typing import final
|
||||||
@ -71,6 +72,28 @@ STATES = [STATE_CLEANING, STATE_DOCKED, STATE_RETURNING, STATE_ERROR]
|
|||||||
|
|
||||||
DEFAULT_NAME = "Vacuum cleaner robot"
|
DEFAULT_NAME = "Vacuum cleaner robot"
|
||||||
|
|
||||||
|
|
||||||
|
class VacuumEntityFeature(IntEnum):
|
||||||
|
"""Supported features of the vacuum entity."""
|
||||||
|
|
||||||
|
TURN_ON = 1
|
||||||
|
TURN_OFF = 2
|
||||||
|
PAUSE = 4
|
||||||
|
STOP = 8
|
||||||
|
RETURN_HOME = 16
|
||||||
|
FAN_SPEED = 32
|
||||||
|
BATTERY = 64
|
||||||
|
STATUS = 128
|
||||||
|
SEND_COMMAND = 256
|
||||||
|
LOCATE = 512
|
||||||
|
CLEAN_SPOT = 1024
|
||||||
|
MAP = 2048
|
||||||
|
STATE = 4096
|
||||||
|
START = 8192
|
||||||
|
|
||||||
|
|
||||||
|
# These SUPPORT_* constants are deprecated as of Home Assistant 2022.5.
|
||||||
|
# Please use the VacuumEntityFeature enum instead.
|
||||||
SUPPORT_TURN_ON = 1
|
SUPPORT_TURN_ON = 1
|
||||||
SUPPORT_TURN_OFF = 2
|
SUPPORT_TURN_OFF = 2
|
||||||
SUPPORT_PAUSE = 4
|
SUPPORT_PAUSE = 4
|
||||||
@ -178,7 +201,7 @@ class _BaseVacuum(Entity):
|
|||||||
@property
|
@property
|
||||||
def capability_attributes(self):
|
def capability_attributes(self):
|
||||||
"""Return capability attributes."""
|
"""Return capability attributes."""
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED:
|
if self.supported_features & VacuumEntityFeature.FAN_SPEED:
|
||||||
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
|
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -186,11 +209,11 @@ class _BaseVacuum(Entity):
|
|||||||
"""Return the state attributes of the vacuum cleaner."""
|
"""Return the state attributes of the vacuum cleaner."""
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
if self.supported_features & SUPPORT_BATTERY:
|
if self.supported_features & VacuumEntityFeature.BATTERY:
|
||||||
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
||||||
data[ATTR_BATTERY_ICON] = self.battery_icon
|
data[ATTR_BATTERY_ICON] = self.battery_icon
|
||||||
|
|
||||||
if self.supported_features & SUPPORT_FAN_SPEED:
|
if self.supported_features & VacuumEntityFeature.FAN_SPEED:
|
||||||
data[ATTR_FAN_SPEED] = self.fan_speed
|
data[ATTR_FAN_SPEED] = self.fan_speed
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -297,7 +320,7 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
|
|||||||
"""Return the state attributes of the vacuum cleaner."""
|
"""Return the state attributes of the vacuum cleaner."""
|
||||||
data = super().state_attributes
|
data = super().state_attributes
|
||||||
|
|
||||||
if self.supported_features & SUPPORT_STATUS:
|
if self.supported_features & VacuumEntityFeature.STATUS:
|
||||||
data[ATTR_STATUS] = self.status
|
data[ATTR_STATUS] = self.status
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user