Skip to content

Commit

Permalink
fixed deprecated constants
Browse files Browse the repository at this point in the history
  • Loading branch information
guerrerotook committed Dec 16, 2024
1 parent 1112b6c commit 68128cb
Showing 1 changed file with 28 additions and 37 deletions.
65 changes: 28 additions & 37 deletions custom_components/securitas/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@
AlarmControlPanelEntityFeature,
CodeFormat,
)
from homeassistant.components.alarm_control_panel.const import AlarmControlPanelState
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_CODE,
CONF_SCAN_INTERVAL,
STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_CUSTOM_BYPASS,
STATE_ALARM_ARMED_HOME,
STATE_ALARM_ARMED_NIGHT,
STATE_ALARM_ARMING,
STATE_ALARM_DISARMED,
STATE_ALARM_DISARMING,
)
from homeassistant.const import CONF_CODE, CONF_SCAN_INTERVAL
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -46,18 +37,18 @@
)

STD_STATE_MAP = {
STATE_ALARM_DISARMED: SecDirAlarmState.TOTAL_DISARMED,
STATE_ALARM_ARMED_AWAY: SecDirAlarmState.TOTAL_ARMED,
STATE_ALARM_ARMED_NIGHT: SecDirAlarmState.NIGHT_ARMED,
STATE_ALARM_ARMED_HOME: SecDirAlarmState.INTERIOR_PARTIAL,
STATE_ALARM_ARMED_CUSTOM_BYPASS: SecDirAlarmState.EXTERIOR_ARMED,
AlarmControlPanelState.DISARMED: SecDirAlarmState.TOTAL_DISARMED,
AlarmControlPanelState.ARMED_AWAY: SecDirAlarmState.TOTAL_ARMED,
AlarmControlPanelState.ARMED_NIGHT: SecDirAlarmState.NIGHT_ARMED,
AlarmControlPanelState.ARMED_HOME: SecDirAlarmState.INTERIOR_PARTIAL,
AlarmControlPanelState.ARMED_CUSTOM_BYPASS: SecDirAlarmState.EXTERIOR_ARMED,
}
PERI_STATE_MAP = {
STATE_ALARM_DISARMED: SecDirAlarmState.TOTAL_DISARMED,
STATE_ALARM_ARMED_AWAY: SecDirAlarmState.TOTAL_ARMED,
STATE_ALARM_ARMED_NIGHT: SecDirAlarmState.INTERIOR_PARTIAL_AND_PERI,
STATE_ALARM_ARMED_HOME: SecDirAlarmState.INTERIOR_PARTIAL,
STATE_ALARM_ARMED_CUSTOM_BYPASS: SecDirAlarmState.EXTERIOR_ARMED,
AlarmControlPanelState.DISARMED: SecDirAlarmState.TOTAL_DISARMED,
AlarmControlPanelState.ARMED_AWAY: SecDirAlarmState.TOTAL_ARMED,
AlarmControlPanelState.ARMED_NIGHT: SecDirAlarmState.INTERIOR_PARTIAL_AND_PERI,
AlarmControlPanelState.ARMED_HOME: SecDirAlarmState.INTERIOR_PARTIAL,
AlarmControlPanelState.ARMED_CUSTOM_BYPASS: SecDirAlarmState.EXTERIOR_ARMED,
}

STATE_MAP = {
Expand Down Expand Up @@ -105,8 +96,8 @@ def __init__(
hass: HomeAssistant,
) -> None:
"""Initialize the Securitas alarm panel."""
self._state: str = STATE_ALARM_DISARMED
self._last_status: str = STATE_ALARM_DISARMED
self._state: str = AlarmControlPanelState.DISARMED
self._last_status: str = AlarmControlPanelState.DISARMED
self._changed_by: str = ""
self._device: str = installation.address
self.entity_id: str = f"securitas_direct.{installation.number}"
Expand Down Expand Up @@ -218,15 +209,15 @@ def update_status_alarm(self, status: CheckAlarmStatus | None = None) -> None:
# self._time = datetime.datetime.fromisoformat(status.protomResponseData)

if status.protomResponse == "D":
self._state = STATE_ALARM_DISARMED
self._state = AlarmControlPanelState.DISARMED
elif status.protomResponse == "T":
self._state = STATE_ALARM_ARMED_AWAY
self._state = AlarmControlPanelState.ARMED_AWAY
elif status.protomResponse == "Q":
self._state = STATE_ALARM_ARMED_NIGHT
self._state = AlarmControlPanelState.ARMED_NIGHT
elif status.protomResponse == "P":
self._state = STATE_ALARM_ARMED_HOME
self._state = AlarmControlPanelState.ARMED_HOME
elif status.protomResponse in ("E", "B", "C", "A"):
self._state = STATE_ALARM_ARMED_CUSTOM_BYPASS
self._state = AlarmControlPanelState.ARMED_CUSTOM_BYPASS

def check_code(self, code=None) -> bool:
"""Check that the code entered in the panel matches the code in the config."""
Expand All @@ -247,7 +238,7 @@ def check_code(self, code=None) -> bool:
async def async_alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command."""
if self.check_code(code):
self.__force_state(STATE_ALARM_DISARMING)
self.__force_state(AlarmControlPanelState.DISARMING)
disarm_status: DisarmStatus = DisarmStatus()
try:
disarm_status = await self.client.session.disarm_alarm(
Expand Down Expand Up @@ -293,26 +284,26 @@ async def set_arm_state(self, mode: str) -> None:
async def async_alarm_arm_home(self, code: str | None = None):
"""Send arm home command."""
if self.check_code(code):
self.__force_state(STATE_ALARM_ARMING)
await self.set_arm_state(STATE_ALARM_ARMED_HOME)
self.__force_state(AlarmControlPanelState.ARMING)
await self.set_arm_state(AlarmControlPanelState.ARMED_HOME)

async def async_alarm_arm_away(self, code: str | None = None):
"""Send arm away command."""
if self.check_code(code):
self.__force_state(STATE_ALARM_ARMING)
await self.set_arm_state(STATE_ALARM_ARMED_AWAY)
self.__force_state(AlarmControlPanelState.ARMING)
await self.set_arm_state(AlarmControlPanelState.ARMED_AWAY)

async def async_alarm_arm_night(self, code: str | None = None):
"""Send arm home command."""
if self.check_code(code):
self.__force_state(STATE_ALARM_ARMING)
await self.set_arm_state(STATE_ALARM_ARMED_NIGHT)
self.__force_state(AlarmControlPanelState.ARMING)
await self.set_arm_state(AlarmControlPanelState.ARMED_NIGHT)

async def async_alarm_arm_custom_bypass(self, code: str | None = None):
"""Send arm perimeter command."""
if self.check_code(code):
self.__force_state(STATE_ALARM_ARMING)
await self.set_arm_state(STATE_ALARM_ARMED_CUSTOM_BYPASS)
self.__force_state(AlarmControlPanelState.ARMING)
await self.set_arm_state(AlarmControlPanelState.ARMED_CUSTOM_BYPASS)

@property
def supported_features(self) -> int:
Expand Down

0 comments on commit 68128cb

Please sign in to comment.