Add EntityFeature enum to Alarm Control Panel (#69044)
This commit is contained in:
parent
165e79be8f
commit
be7fc35dfa
5 changed files with 105 additions and 39 deletions
|
@ -27,13 +27,14 @@ from homeassistant.helpers.entity import Entity, EntityDescription
|
|||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
from .const import ( # noqa: F401
|
||||
SUPPORT_ALARM_ARM_AWAY,
|
||||
SUPPORT_ALARM_ARM_CUSTOM_BYPASS,
|
||||
SUPPORT_ALARM_ARM_HOME,
|
||||
SUPPORT_ALARM_ARM_NIGHT,
|
||||
SUPPORT_ALARM_ARM_VACATION,
|
||||
SUPPORT_ALARM_TRIGGER,
|
||||
AlarmControlPanelEntityFeature,
|
||||
)
|
||||
|
||||
_LOGGER: Final = logging.getLogger(__name__)
|
||||
|
@ -58,7 +59,7 @@ PLATFORM_SCHEMA_BASE: Final = cv.PLATFORM_SCHEMA_BASE
|
|||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Track states and offer events for sensors."""
|
||||
component = hass.data[DOMAIN] = EntityComponent(
|
||||
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
|
||||
await component.async_setup(config)
|
||||
|
@ -70,37 +71,37 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
SERVICE_ALARM_ARM_HOME,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_alarm_arm_home",
|
||||
[SUPPORT_ALARM_ARM_HOME],
|
||||
[AlarmControlPanelEntityFeature.ARM_HOME],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_AWAY,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_alarm_arm_away",
|
||||
[SUPPORT_ALARM_ARM_AWAY],
|
||||
[AlarmControlPanelEntityFeature.ARM_AWAY],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_NIGHT,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_alarm_arm_night",
|
||||
[SUPPORT_ALARM_ARM_NIGHT],
|
||||
[AlarmControlPanelEntityFeature.ARM_NIGHT],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_VACATION,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_alarm_arm_vacation",
|
||||
[SUPPORT_ALARM_ARM_VACATION],
|
||||
[AlarmControlPanelEntityFeature.ARM_VACATION],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_CUSTOM_BYPASS,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_alarm_arm_custom_bypass",
|
||||
[SUPPORT_ALARM_ARM_CUSTOM_BYPASS],
|
||||
[AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_TRIGGER,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_alarm_trigger",
|
||||
[SUPPORT_ALARM_TRIGGER],
|
||||
[AlarmControlPanelEntityFeature.TRIGGER],
|
||||
)
|
||||
|
||||
return True
|
||||
|
|
|
@ -1,7 +1,22 @@
|
|||
"""Provides the constants needed for component."""
|
||||
|
||||
from enum import IntEnum
|
||||
from typing import Final
|
||||
|
||||
|
||||
class AlarmControlPanelEntityFeature(IntEnum):
|
||||
"""Supported features of the alarm control panel entity."""
|
||||
|
||||
ARM_HOME = 1
|
||||
ARM_AWAY = 2
|
||||
ARM_NIGHT = 4
|
||||
TRIGGER = 8
|
||||
ARM_CUSTOM_BYPASS = 16
|
||||
ARM_VACATION = 32
|
||||
|
||||
|
||||
# These constants are deprecated as of Home Assistant 2022.5
|
||||
# Pleease use the AlarmControlPanelEntityFeature enum instead.
|
||||
SUPPORT_ALARM_ARM_HOME: Final = 1
|
||||
SUPPORT_ALARM_ARM_AWAY: Final = 2
|
||||
SUPPORT_ALARM_ARM_NIGHT: Final = 4
|
||||
|
|
|
@ -10,12 +10,7 @@ import voluptuous as vol
|
|||
|
||||
import homeassistant.components.alarm_control_panel as alarm
|
||||
from homeassistant.components.alarm_control_panel.const import (
|
||||
SUPPORT_ALARM_ARM_AWAY,
|
||||
SUPPORT_ALARM_ARM_CUSTOM_BYPASS,
|
||||
SUPPORT_ALARM_ARM_HOME,
|
||||
SUPPORT_ALARM_ARM_NIGHT,
|
||||
SUPPORT_ALARM_ARM_VACATION,
|
||||
SUPPORT_ALARM_TRIGGER,
|
||||
AlarmControlPanelEntityFeature,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_ARMING_TIME,
|
||||
|
@ -262,12 +257,12 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||
def supported_features(self) -> int:
|
||||
"""Return the list of supported features."""
|
||||
return (
|
||||
SUPPORT_ALARM_ARM_HOME
|
||||
| SUPPORT_ALARM_ARM_AWAY
|
||||
| SUPPORT_ALARM_ARM_NIGHT
|
||||
| SUPPORT_ALARM_ARM_VACATION
|
||||
| SUPPORT_ALARM_TRIGGER
|
||||
| SUPPORT_ALARM_ARM_CUSTOM_BYPASS
|
||||
AlarmControlPanelEntityFeature.ARM_HOME
|
||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
| AlarmControlPanelEntityFeature.ARM_NIGHT
|
||||
| AlarmControlPanelEntityFeature.ARM_VACATION
|
||||
| AlarmControlPanelEntityFeature.TRIGGER
|
||||
| AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -44,16 +44,51 @@ def entity_reg(hass):
|
|||
"set_state,features_reg,features_state,expected_action_types",
|
||||
[
|
||||
(False, 0, 0, ["disarm"]),
|
||||
(False, const.SUPPORT_ALARM_ARM_AWAY, 0, ["disarm", "arm_away"]),
|
||||
(False, const.SUPPORT_ALARM_ARM_HOME, 0, ["disarm", "arm_home"]),
|
||||
(False, const.SUPPORT_ALARM_ARM_NIGHT, 0, ["disarm", "arm_night"]),
|
||||
(False, const.SUPPORT_ALARM_TRIGGER, 0, ["disarm", "trigger"]),
|
||||
(
|
||||
False,
|
||||
const.AlarmControlPanelEntityFeature.ARM_AWAY,
|
||||
0,
|
||||
["disarm", "arm_away"],
|
||||
),
|
||||
(
|
||||
False,
|
||||
const.AlarmControlPanelEntityFeature.ARM_HOME,
|
||||
0,
|
||||
["disarm", "arm_home"],
|
||||
),
|
||||
(
|
||||
False,
|
||||
const.AlarmControlPanelEntityFeature.ARM_NIGHT,
|
||||
0,
|
||||
["disarm", "arm_night"],
|
||||
),
|
||||
(False, const.AlarmControlPanelEntityFeature.TRIGGER, 0, ["disarm", "trigger"]),
|
||||
(True, 0, 0, ["disarm"]),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_AWAY, ["disarm", "arm_away"]),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_HOME, ["disarm", "arm_home"]),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_NIGHT, ["disarm", "arm_night"]),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_VACATION, ["disarm", "arm_vacation"]),
|
||||
(True, 0, const.SUPPORT_ALARM_TRIGGER, ["disarm", "trigger"]),
|
||||
(
|
||||
True,
|
||||
0,
|
||||
const.AlarmControlPanelEntityFeature.ARM_AWAY,
|
||||
["disarm", "arm_away"],
|
||||
),
|
||||
(
|
||||
True,
|
||||
0,
|
||||
const.AlarmControlPanelEntityFeature.ARM_HOME,
|
||||
["disarm", "arm_home"],
|
||||
),
|
||||
(
|
||||
True,
|
||||
0,
|
||||
const.AlarmControlPanelEntityFeature.ARM_NIGHT,
|
||||
["disarm", "arm_night"],
|
||||
),
|
||||
(
|
||||
True,
|
||||
0,
|
||||
const.AlarmControlPanelEntityFeature.ARM_VACATION,
|
||||
["disarm", "arm_vacation"],
|
||||
),
|
||||
(True, 0, const.AlarmControlPanelEntityFeature.TRIGGER, ["disarm", "trigger"]),
|
||||
],
|
||||
)
|
||||
async def test_get_actions(
|
||||
|
|
|
@ -49,17 +49,37 @@ def calls(hass):
|
|||
"set_state,features_reg,features_state,expected_condition_types",
|
||||
[
|
||||
(False, 0, 0, []),
|
||||
(False, const.SUPPORT_ALARM_ARM_AWAY, 0, ["is_armed_away"]),
|
||||
(False, const.SUPPORT_ALARM_ARM_HOME, 0, ["is_armed_home"]),
|
||||
(False, const.SUPPORT_ALARM_ARM_NIGHT, 0, ["is_armed_night"]),
|
||||
(False, const.SUPPORT_ALARM_ARM_VACATION, 0, ["is_armed_vacation"]),
|
||||
(False, const.SUPPORT_ALARM_ARM_CUSTOM_BYPASS, 0, ["is_armed_custom_bypass"]),
|
||||
(False, const.AlarmControlPanelEntityFeature.ARM_AWAY, 0, ["is_armed_away"]),
|
||||
(False, const.AlarmControlPanelEntityFeature.ARM_HOME, 0, ["is_armed_home"]),
|
||||
(False, const.AlarmControlPanelEntityFeature.ARM_NIGHT, 0, ["is_armed_night"]),
|
||||
(
|
||||
False,
|
||||
const.AlarmControlPanelEntityFeature.ARM_VACATION,
|
||||
0,
|
||||
["is_armed_vacation"],
|
||||
),
|
||||
(
|
||||
False,
|
||||
const.AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS,
|
||||
0,
|
||||
["is_armed_custom_bypass"],
|
||||
),
|
||||
(True, 0, 0, []),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_AWAY, ["is_armed_away"]),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_HOME, ["is_armed_home"]),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_NIGHT, ["is_armed_night"]),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_VACATION, ["is_armed_vacation"]),
|
||||
(True, 0, const.SUPPORT_ALARM_ARM_CUSTOM_BYPASS, ["is_armed_custom_bypass"]),
|
||||
(True, 0, const.AlarmControlPanelEntityFeature.ARM_AWAY, ["is_armed_away"]),
|
||||
(True, 0, const.AlarmControlPanelEntityFeature.ARM_HOME, ["is_armed_home"]),
|
||||
(True, 0, const.AlarmControlPanelEntityFeature.ARM_NIGHT, ["is_armed_night"]),
|
||||
(
|
||||
True,
|
||||
0,
|
||||
const.AlarmControlPanelEntityFeature.ARM_VACATION,
|
||||
["is_armed_vacation"],
|
||||
),
|
||||
(
|
||||
True,
|
||||
0,
|
||||
const.AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS,
|
||||
["is_armed_custom_bypass"],
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_get_conditions(
|
||||
|
|
Loading…
Add table
Reference in a new issue