Replace Alarm Control Panel FORMAT_ constants with CodeFormat enum (#69861)
This commit is contained in:
parent
81f3c82aef
commit
1e4aacaeb1
22 changed files with 65 additions and 47 deletions
|
@ -40,6 +40,7 @@ from .const import ( # noqa: F401
|
|||
SUPPORT_ALARM_ARM_VACATION,
|
||||
SUPPORT_ALARM_TRIGGER,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
|
||||
_LOGGER: Final = logging.getLogger(__name__)
|
||||
|
@ -129,12 +130,12 @@ class AlarmControlPanelEntity(Entity):
|
|||
entity_description: AlarmControlPanelEntityDescription
|
||||
_attr_changed_by: str | None = None
|
||||
_attr_code_arm_required: bool = True
|
||||
_attr_code_format: str | None = None
|
||||
_attr_code_format: CodeFormat | None = None
|
||||
_attr_supported_features: int
|
||||
|
||||
@property
|
||||
def code_format(self) -> str | None:
|
||||
"""Regex for code format or None if no code is required."""
|
||||
def code_format(self) -> CodeFormat | None:
|
||||
"""Code format or None if no code is required."""
|
||||
return self._attr_code_format
|
||||
|
||||
@property
|
||||
|
|
|
@ -2,11 +2,23 @@
|
|||
from enum import IntEnum
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.backports.enum import StrEnum
|
||||
|
||||
DOMAIN: Final = "alarm_control_panel"
|
||||
|
||||
ATTR_CHANGED_BY: Final = "changed_by"
|
||||
ATTR_CODE_ARM_REQUIRED: Final = "code_arm_required"
|
||||
|
||||
|
||||
class CodeFormat(StrEnum):
|
||||
"""Code formats for the Alarm Control Panel."""
|
||||
|
||||
TEXT = "text"
|
||||
NUMBER = "number"
|
||||
|
||||
|
||||
# These constants are deprecated as of Home Assistant 2022.5
|
||||
# Please use the CodeFormat enum instead.
|
||||
FORMAT_TEXT: Final = "text"
|
||||
FORMAT_NUMBER: Final = "number"
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
FORMAT_NUMBER,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -77,7 +77,7 @@ class AlarmDecoderAlarmPanel(AlarmControlPanelEntity):
|
|||
|
||||
_attr_name = "Alarm Panel"
|
||||
_attr_should_poll = False
|
||||
_attr_code_format = FORMAT_NUMBER
|
||||
_attr_code_format = CodeFormat.NUMBER
|
||||
_attr_supported_features = (
|
||||
AlarmControlPanelEntityFeature.ARM_HOME
|
||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
|
|
|
@ -13,8 +13,8 @@ from homeassistant.components import (
|
|||
vacuum,
|
||||
)
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
FORMAT_NUMBER,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
import homeassistant.components.climate.const as climate
|
||||
import homeassistant.components.media_player.const as media_player
|
||||
|
@ -1226,7 +1226,7 @@ class AlexaSecurityPanelController(AlexaCapability):
|
|||
|
||||
configuration["supportedArmStates"] = supported_arm_states
|
||||
|
||||
if code_format == FORMAT_NUMBER:
|
||||
if code_format == CodeFormat.NUMBER:
|
||||
configuration["supportedAuthorizationTypes"] = [{"type": "FOUR_DIGIT_PIN"}]
|
||||
|
||||
return configuration
|
||||
|
|
|
@ -96,7 +96,7 @@ class Concord232Alarm(alarm.AlarmControlPanelEntity):
|
|||
@property
|
||||
def code_format(self):
|
||||
"""Return the characters if code is defined."""
|
||||
return alarm.FORMAT_NUMBER
|
||||
return alarm.CodeFormat.NUMBER
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -18,9 +18,9 @@ from pydeconz.sensor import (
|
|||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
DOMAIN,
|
||||
FORMAT_NUMBER,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -120,7 +120,7 @@ class DeconzAlarmControlPanel(DeconzDevice, AlarmControlPanelEntity):
|
|||
TYPE = DOMAIN
|
||||
_device: AncillaryControl
|
||||
|
||||
_attr_code_format = FORMAT_NUMBER
|
||||
_attr_code_format = CodeFormat.NUMBER
|
||||
_attr_supported_features = (
|
||||
AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
| AlarmControlPanelEntityFeature.ARM_HOME
|
||||
|
|
|
@ -6,9 +6,9 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
ATTR_CHANGED_BY,
|
||||
FORMAT_NUMBER,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -164,7 +164,7 @@ class ElkArea(ElkAttachedEntity, AlarmControlPanelEntity, RestoreEntity):
|
|||
@property
|
||||
def code_format(self):
|
||||
"""Return the alarm code format."""
|
||||
return FORMAT_NUMBER
|
||||
return CodeFormat.NUMBER
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -6,9 +6,9 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
FORMAT_NUMBER,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
|
@ -145,7 +145,7 @@ class EnvisalinkAlarm(EnvisalinkDevice, AlarmControlPanelEntity):
|
|||
"""Regex for code format or None if no code is required."""
|
||||
if self._code:
|
||||
return None
|
||||
return FORMAT_NUMBER
|
||||
return CodeFormat.NUMBER
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -7,11 +7,10 @@ import re
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
FORMAT_NUMBER,
|
||||
FORMAT_TEXT,
|
||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
|
@ -177,8 +176,8 @@ class IFTTTAlarmPanel(AlarmControlPanelEntity):
|
|||
if self._code is None:
|
||||
return None
|
||||
if isinstance(self._code, str) and re.search("^\\d+$", self._code):
|
||||
return FORMAT_NUMBER
|
||||
return FORMAT_TEXT
|
||||
return CodeFormat.NUMBER
|
||||
return CodeFormat.TEXT
|
||||
|
||||
def alarm_disarm(self, code=None):
|
||||
"""Send disarm command."""
|
||||
|
|
|
@ -294,8 +294,8 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||
if self._code is None:
|
||||
return None
|
||||
if isinstance(self._code, str) and re.search("^\\d+$", self._code):
|
||||
return alarm.FORMAT_NUMBER
|
||||
return alarm.FORMAT_TEXT
|
||||
return alarm.CodeFormat.NUMBER
|
||||
return alarm.CodeFormat.TEXT
|
||||
|
||||
@property
|
||||
def code_arm_required(self):
|
||||
|
|
|
@ -319,8 +319,8 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||
if self._code is None:
|
||||
return None
|
||||
if isinstance(self._code, str) and re.search("^\\d+$", self._code):
|
||||
return alarm.FORMAT_NUMBER
|
||||
return alarm.FORMAT_TEXT
|
||||
return alarm.CodeFormat.NUMBER
|
||||
return alarm.CodeFormat.TEXT
|
||||
|
||||
@property
|
||||
def code_arm_required(self):
|
||||
|
|
|
@ -235,8 +235,8 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||
if (code := self._config.get(CONF_CODE)) is None:
|
||||
return None
|
||||
if code == REMOTE_CODE or (isinstance(code, str) and re.search("^\\d+$", code)):
|
||||
return alarm.FORMAT_NUMBER
|
||||
return alarm.FORMAT_TEXT
|
||||
return alarm.CodeFormat.NUMBER
|
||||
return alarm.CodeFormat.TEXT
|
||||
|
||||
@property
|
||||
def code_arm_required(self):
|
||||
|
|
|
@ -74,7 +74,7 @@ class NessAlarmPanel(alarm.AlarmControlPanelEntity):
|
|||
@property
|
||||
def code_format(self):
|
||||
"""Return the regex for code format or None if no code is required."""
|
||||
return alarm.FORMAT_NUMBER
|
||||
return alarm.CodeFormat.NUMBER
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -112,7 +112,7 @@ class NX584Alarm(alarm.AlarmControlPanelEntity):
|
|||
@property
|
||||
def code_format(self):
|
||||
"""Return one or more digits/characters."""
|
||||
return alarm.FORMAT_NUMBER
|
||||
return alarm.CodeFormat.NUMBER
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
import logging
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
FORMAT_NUMBER,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -132,7 +132,7 @@ class RiscoAlarm(AlarmControlPanelEntity, RiscoEntity):
|
|||
@property
|
||||
def code_format(self):
|
||||
"""Return one or more digits/characters."""
|
||||
return FORMAT_NUMBER
|
||||
return CodeFormat.NUMBER
|
||||
|
||||
def _validate_code(self, code):
|
||||
"""Validate given code."""
|
||||
|
|
|
@ -142,7 +142,7 @@ class SatelIntegraAlarmPanel(alarm.AlarmControlPanelEntity):
|
|||
@property
|
||||
def code_format(self):
|
||||
"""Return the regex for code format or None if no code is required."""
|
||||
return alarm.FORMAT_NUMBER
|
||||
return alarm.CodeFormat.NUMBER
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -20,10 +20,9 @@ from simplipy.websocket import (
|
|||
)
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
FORMAT_NUMBER,
|
||||
FORMAT_TEXT,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -130,9 +129,9 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
|
|||
|
||||
if code := self._simplisafe.entry.options.get(CONF_CODE):
|
||||
if code.isdigit():
|
||||
self._attr_code_format = FORMAT_NUMBER
|
||||
self._attr_code_format = CodeFormat.NUMBER
|
||||
else:
|
||||
self._attr_code_format = FORMAT_TEXT
|
||||
self._attr_code_format = CodeFormat.TEXT
|
||||
|
||||
self._last_event = None
|
||||
|
||||
|
|
|
@ -8,11 +8,10 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
ENTITY_ID_FORMAT,
|
||||
FORMAT_NUMBER,
|
||||
FORMAT_TEXT,
|
||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_CODE,
|
||||
|
@ -60,12 +59,12 @@ CONF_CODE_ARM_REQUIRED = "code_arm_required"
|
|||
CONF_CODE_FORMAT = "code_format"
|
||||
|
||||
|
||||
class CodeFormat(Enum):
|
||||
class TemplateCodeFormat(Enum):
|
||||
"""Class to represent different code formats."""
|
||||
|
||||
no_code = None
|
||||
number = FORMAT_NUMBER
|
||||
text = FORMAT_TEXT
|
||||
number = CodeFormat.NUMBER
|
||||
text = CodeFormat.TEXT
|
||||
|
||||
|
||||
ALARM_CONTROL_PANEL_SCHEMA = vol.Schema(
|
||||
|
@ -76,8 +75,8 @@ ALARM_CONTROL_PANEL_SCHEMA = vol.Schema(
|
|||
vol.Optional(CONF_ARM_HOME_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Optional(CONF_ARM_NIGHT_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Optional(CONF_CODE_ARM_REQUIRED, default=True): cv.boolean,
|
||||
vol.Optional(CONF_CODE_FORMAT, default=CodeFormat.number.name): cv.enum(
|
||||
CodeFormat
|
||||
vol.Optional(CONF_CODE_FORMAT, default=TemplateCodeFormat.number.name): cv.enum(
|
||||
TemplateCodeFormat
|
||||
),
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
|
|
|
@ -4,9 +4,9 @@ from __future__ import annotations
|
|||
import asyncio
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
FORMAT_NUMBER,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -32,7 +32,7 @@ class VerisureAlarm(
|
|||
):
|
||||
"""Representation of a Verisure alarm status."""
|
||||
|
||||
_attr_code_format = FORMAT_NUMBER
|
||||
_attr_code_format = CodeFormat.NUMBER
|
||||
_attr_name = "Verisure Alarm"
|
||||
_attr_supported_features = (
|
||||
AlarmControlPanelEntityFeature.ARM_HOME
|
||||
|
|
|
@ -4,9 +4,9 @@ import functools
|
|||
from zigpy.zcl.clusters.security import IasAce
|
||||
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
FORMAT_TEXT,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
CodeFormat,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -116,7 +116,7 @@ class ZHAAlarmControlPanel(ZhaEntity, AlarmControlPanelEntity):
|
|||
@property
|
||||
def code_format(self):
|
||||
"""Regex for code format or None if no code is required."""
|
||||
return FORMAT_TEXT
|
||||
return CodeFormat.TEXT
|
||||
|
||||
@property
|
||||
def changed_by(self):
|
||||
|
|
|
@ -24,12 +24,20 @@ _OBSOLETE_IMPORT: dict[str, list[ObsoleteImportMatch]] = {
|
|||
reason="replaced by AlarmControlPanelEntityFeature enum",
|
||||
constant=re.compile(r"^SUPPORT_(\w*)$"),
|
||||
),
|
||||
ObsoleteImportMatch(
|
||||
reason="replaced by CodeFormat enum",
|
||||
constant=re.compile(r"^FORMAT_(\w*)$"),
|
||||
),
|
||||
],
|
||||
"homeassistant.components.alarm_control_panel.const": [
|
||||
ObsoleteImportMatch(
|
||||
reason="replaced by AlarmControlPanelEntityFeature enum",
|
||||
constant=re.compile(r"^SUPPORT_(\w*)$"),
|
||||
),
|
||||
ObsoleteImportMatch(
|
||||
reason="replaced by CodeFormat enum",
|
||||
constant=re.compile(r"^FORMAT_(\w*)$"),
|
||||
),
|
||||
],
|
||||
"homeassistant.components.binarysensor": [
|
||||
ObsoleteImportMatch(
|
||||
|
|
|
@ -476,7 +476,7 @@ async def test_attributes_code_number(hass, mqtt_mock):
|
|||
state = hass.states.get("alarm_control_panel.test")
|
||||
assert (
|
||||
state.attributes.get(alarm_control_panel.ATTR_CODE_FORMAT)
|
||||
== alarm_control_panel.FORMAT_NUMBER
|
||||
== alarm_control_panel.CodeFormat.NUMBER
|
||||
)
|
||||
|
||||
|
||||
|
@ -491,7 +491,7 @@ async def test_attributes_remote_code_number(hass, mqtt_mock):
|
|||
state = hass.states.get("alarm_control_panel.test")
|
||||
assert (
|
||||
state.attributes.get(alarm_control_panel.ATTR_CODE_FORMAT)
|
||||
== alarm_control_panel.FORMAT_NUMBER
|
||||
== alarm_control_panel.CodeFormat.NUMBER
|
||||
)
|
||||
|
||||
|
||||
|
@ -506,7 +506,7 @@ async def test_attributes_code_text(hass, mqtt_mock):
|
|||
state = hass.states.get("alarm_control_panel.test")
|
||||
assert (
|
||||
state.attributes.get(alarm_control_panel.ATTR_CODE_FORMAT)
|
||||
== alarm_control_panel.FORMAT_TEXT
|
||||
== alarm_control_panel.CodeFormat.TEXT
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue