Use EntityFeature enums in template (#69583)
This commit is contained in:
parent
c8e06e2456
commit
c583df74e4
4 changed files with 33 additions and 49 deletions
|
@ -12,11 +12,7 @@ from homeassistant.components.alarm_control_panel import (
|
|||
FORMAT_TEXT,
|
||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
AlarmControlPanelEntity,
|
||||
)
|
||||
from homeassistant.components.alarm_control_panel.const import (
|
||||
SUPPORT_ALARM_ARM_AWAY,
|
||||
SUPPORT_ALARM_ARM_HOME,
|
||||
SUPPORT_ALARM_ARM_NIGHT,
|
||||
AlarmControlPanelEntityFeature,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_CODE,
|
||||
|
@ -173,13 +169,19 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity):
|
|||
"""Return the list of supported features."""
|
||||
supported_features = 0
|
||||
if self._arm_night_script is not None:
|
||||
supported_features = supported_features | SUPPORT_ALARM_ARM_NIGHT
|
||||
supported_features = (
|
||||
supported_features | AlarmControlPanelEntityFeature.ARM_NIGHT
|
||||
)
|
||||
|
||||
if self._arm_home_script is not None:
|
||||
supported_features = supported_features | SUPPORT_ALARM_ARM_HOME
|
||||
supported_features = (
|
||||
supported_features | AlarmControlPanelEntityFeature.ARM_HOME
|
||||
)
|
||||
|
||||
if self._arm_away_script is not None:
|
||||
supported_features = supported_features | SUPPORT_ALARM_ARM_AWAY
|
||||
supported_features = (
|
||||
supported_features | AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
)
|
||||
|
||||
return supported_features
|
||||
|
||||
|
|
|
@ -11,15 +11,8 @@ from homeassistant.components.cover import (
|
|||
DEVICE_CLASSES_SCHEMA,
|
||||
ENTITY_ID_FORMAT,
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_CLOSE,
|
||||
SUPPORT_CLOSE_TILT,
|
||||
SUPPORT_OPEN,
|
||||
SUPPORT_OPEN_TILT,
|
||||
SUPPORT_SET_POSITION,
|
||||
SUPPORT_SET_TILT_POSITION,
|
||||
SUPPORT_STOP,
|
||||
SUPPORT_STOP_TILT,
|
||||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_COVERS,
|
||||
|
@ -71,10 +64,10 @@ CONF_TILT_OPTIMISTIC = "tilt_optimistic"
|
|||
CONF_OPEN_AND_CLOSE = "open_or_close"
|
||||
|
||||
TILT_FEATURES = (
|
||||
SUPPORT_OPEN_TILT
|
||||
| SUPPORT_CLOSE_TILT
|
||||
| SUPPORT_STOP_TILT
|
||||
| SUPPORT_SET_TILT_POSITION
|
||||
CoverEntityFeature.OPEN_TILT
|
||||
| CoverEntityFeature.CLOSE_TILT
|
||||
| CoverEntityFeature.STOP_TILT
|
||||
| CoverEntityFeature.SET_TILT_POSITION
|
||||
)
|
||||
|
||||
COVER_SCHEMA = vol.All(
|
||||
|
@ -313,13 +306,13 @@ class CoverTemplate(TemplateEntity, CoverEntity):
|
|||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
supported_features = SUPPORT_OPEN | SUPPORT_CLOSE
|
||||
supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||
|
||||
if self._stop_script is not None:
|
||||
supported_features |= SUPPORT_STOP
|
||||
supported_features |= CoverEntityFeature.STOP
|
||||
|
||||
if self._position_script is not None:
|
||||
supported_features |= SUPPORT_SET_POSITION
|
||||
supported_features |= CoverEntityFeature.SET_POSITION
|
||||
|
||||
if self._tilt_script is not None:
|
||||
supported_features |= TILT_FEATURES
|
||||
|
|
|
@ -14,11 +14,8 @@ from homeassistant.components.fan import (
|
|||
DIRECTION_FORWARD,
|
||||
DIRECTION_REVERSE,
|
||||
ENTITY_ID_FORMAT,
|
||||
SUPPORT_DIRECTION,
|
||||
SUPPORT_OSCILLATE,
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_SET_SPEED,
|
||||
FanEntity,
|
||||
FanEntityFeature,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_ID,
|
||||
|
@ -199,13 +196,13 @@ class TemplateFan(TemplateEntity, FanEntity):
|
|||
self._preset_modes = config.get(CONF_PRESET_MODES)
|
||||
|
||||
if self._percentage_template:
|
||||
self._supported_features |= SUPPORT_SET_SPEED
|
||||
self._supported_features |= FanEntityFeature.SET_SPEED
|
||||
if self._preset_mode_template and self._preset_modes:
|
||||
self._supported_features |= SUPPORT_PRESET_MODE
|
||||
self._supported_features |= FanEntityFeature.PRESET_MODE
|
||||
if self._oscillating_template:
|
||||
self._supported_features |= SUPPORT_OSCILLATE
|
||||
self._supported_features |= FanEntityFeature.OSCILLATE
|
||||
if self._direction_template:
|
||||
self._supported_features |= SUPPORT_DIRECTION
|
||||
self._supported_features |= FanEntityFeature.DIRECTION
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
|
|
|
@ -21,16 +21,8 @@ from homeassistant.components.vacuum import (
|
|||
STATE_IDLE,
|
||||
STATE_PAUSED,
|
||||
STATE_RETURNING,
|
||||
SUPPORT_BATTERY,
|
||||
SUPPORT_CLEAN_SPOT,
|
||||
SUPPORT_FAN_SPEED,
|
||||
SUPPORT_LOCATE,
|
||||
SUPPORT_PAUSE,
|
||||
SUPPORT_RETURN_HOME,
|
||||
SUPPORT_START,
|
||||
SUPPORT_STATE,
|
||||
SUPPORT_STOP,
|
||||
StateVacuumEntity,
|
||||
VacuumEntityFeature,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_ENTITY_ID,
|
||||
|
@ -153,54 +145,54 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity):
|
|||
self._template = config.get(CONF_VALUE_TEMPLATE)
|
||||
self._battery_level_template = config.get(CONF_BATTERY_LEVEL_TEMPLATE)
|
||||
self._fan_speed_template = config.get(CONF_FAN_SPEED_TEMPLATE)
|
||||
self._supported_features = SUPPORT_START
|
||||
self._supported_features = VacuumEntityFeature.START
|
||||
|
||||
self._start_script = Script(hass, config[SERVICE_START], friendly_name, DOMAIN)
|
||||
|
||||
self._pause_script = None
|
||||
if pause_action := config.get(SERVICE_PAUSE):
|
||||
self._pause_script = Script(hass, pause_action, friendly_name, DOMAIN)
|
||||
self._supported_features |= SUPPORT_PAUSE
|
||||
self._supported_features |= VacuumEntityFeature.PAUSE
|
||||
|
||||
self._stop_script = None
|
||||
if stop_action := config.get(SERVICE_STOP):
|
||||
self._stop_script = Script(hass, stop_action, friendly_name, DOMAIN)
|
||||
self._supported_features |= SUPPORT_STOP
|
||||
self._supported_features |= VacuumEntityFeature.STOP
|
||||
|
||||
self._return_to_base_script = None
|
||||
if return_to_base_action := config.get(SERVICE_RETURN_TO_BASE):
|
||||
self._return_to_base_script = Script(
|
||||
hass, return_to_base_action, friendly_name, DOMAIN
|
||||
)
|
||||
self._supported_features |= SUPPORT_RETURN_HOME
|
||||
self._supported_features |= VacuumEntityFeature.RETURN_HOME
|
||||
|
||||
self._clean_spot_script = None
|
||||
if clean_spot_action := config.get(SERVICE_CLEAN_SPOT):
|
||||
self._clean_spot_script = Script(
|
||||
hass, clean_spot_action, friendly_name, DOMAIN
|
||||
)
|
||||
self._supported_features |= SUPPORT_CLEAN_SPOT
|
||||
self._supported_features |= VacuumEntityFeature.CLEAN_SPOT
|
||||
|
||||
self._locate_script = None
|
||||
if locate_action := config.get(SERVICE_LOCATE):
|
||||
self._locate_script = Script(hass, locate_action, friendly_name, DOMAIN)
|
||||
self._supported_features |= SUPPORT_LOCATE
|
||||
self._supported_features |= VacuumEntityFeature.LOCATE
|
||||
|
||||
self._set_fan_speed_script = None
|
||||
if set_fan_speed_action := config.get(SERVICE_SET_FAN_SPEED):
|
||||
self._set_fan_speed_script = Script(
|
||||
hass, set_fan_speed_action, friendly_name, DOMAIN
|
||||
)
|
||||
self._supported_features |= SUPPORT_FAN_SPEED
|
||||
self._supported_features |= VacuumEntityFeature.FAN_SPEED
|
||||
|
||||
self._state = None
|
||||
self._battery_level = None
|
||||
self._fan_speed = None
|
||||
|
||||
if self._template:
|
||||
self._supported_features |= SUPPORT_STATE
|
||||
self._supported_features |= VacuumEntityFeature.STATE
|
||||
if self._battery_level_template:
|
||||
self._supported_features |= SUPPORT_BATTERY
|
||||
self._supported_features |= VacuumEntityFeature.BATTERY
|
||||
|
||||
# List of valid fan speeds
|
||||
self._fan_speed_list = config[CONF_FAN_SPEED_LIST]
|
||||
|
|
Loading…
Add table
Reference in a new issue