Don't require code to arm SimpliSafe (#118759)

This commit is contained in:
Aaron Bach 2024-06-03 23:20:37 -06:00 committed by GitHub
parent 553311cc7d
commit d43d12905d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,11 +26,9 @@ from simplipy.websocket import (
from homeassistant.components.alarm_control_panel import ( from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntity, AlarmControlPanelEntity,
AlarmControlPanelEntityFeature, AlarmControlPanelEntityFeature,
CodeFormat,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_CODE,
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_HOME,
STATE_ALARM_ARMING, STATE_ALARM_ARMING,
@ -124,11 +122,12 @@ async def async_setup_entry(
class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity): class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
"""Representation of a SimpliSafe alarm.""" """Representation of a SimpliSafe alarm."""
_attr_code_arm_required = False
_attr_name = None
_attr_supported_features = ( _attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY | AlarmControlPanelEntityFeature.ARM_AWAY
) )
_attr_name = None
def __init__(self, simplisafe: SimpliSafe, system: SystemType) -> None: def __init__(self, simplisafe: SimpliSafe, system: SystemType) -> None:
"""Initialize the SimpliSafe alarm.""" """Initialize the SimpliSafe alarm."""
@ -138,30 +137,9 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
additional_websocket_events=WEBSOCKET_EVENTS_TO_LISTEN_FOR, additional_websocket_events=WEBSOCKET_EVENTS_TO_LISTEN_FOR,
) )
if code := self._simplisafe.entry.options.get(CONF_CODE):
if code.isdigit():
self._attr_code_format = CodeFormat.NUMBER
else:
self._attr_code_format = CodeFormat.TEXT
self._last_event = None self._last_event = None
self._set_state_from_system_data() self._set_state_from_system_data()
@callback
def _is_code_valid(self, code: str | None, state: str) -> bool:
"""Validate that a code matches the required one."""
if not self._simplisafe.entry.options.get(CONF_CODE):
return True
if not code or code != self._simplisafe.entry.options[CONF_CODE]:
LOGGER.warning(
"Incorrect alarm code entered (target state: %s): %s", state, code
)
return False
return True
@callback @callback
def _set_state_from_system_data(self) -> None: def _set_state_from_system_data(self) -> None:
"""Set the state based on the latest REST API data.""" """Set the state based on the latest REST API data."""
@ -176,9 +154,6 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
async def async_alarm_disarm(self, code: str | None = None) -> None: async def async_alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command.""" """Send disarm command."""
if not self._is_code_valid(code, STATE_ALARM_DISARMED):
return
try: try:
await self._system.async_set_off() await self._system.async_set_off()
except SimplipyError as err: except SimplipyError as err:
@ -191,9 +166,6 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
async def async_alarm_arm_home(self, code: str | None = None) -> None: async def async_alarm_arm_home(self, code: str | None = None) -> None:
"""Send arm home command.""" """Send arm home command."""
if not self._is_code_valid(code, STATE_ALARM_ARMED_HOME):
return
try: try:
await self._system.async_set_home() await self._system.async_set_home()
except SimplipyError as err: except SimplipyError as err:
@ -206,9 +178,6 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
async def async_alarm_arm_away(self, code: str | None = None) -> None: async def async_alarm_arm_away(self, code: str | None = None) -> None:
"""Send arm away command.""" """Send arm away command."""
if not self._is_code_valid(code, STATE_ALARM_ARMED_AWAY):
return
try: try:
await self._system.async_set_away() await self._system.async_set_away()
except SimplipyError as err: except SimplipyError as err: