diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ecbbc..2520707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ BREAKING CHANGE: subsystem IDs are changing due conflict of multi "instance" conflict Can break automations, dashboards or anything connected to "SubSystems IDs" +- **fix**: deprecation warnings for alarm states @uvera #136 #137 - **fix**: subsystem - duplicate IDs - **chore**: remove Deprecated option to use internal API lib diff --git a/custom_components/hikvision_axpro/__init__.py b/custom_components/hikvision_axpro/__init__.py index 5afe097..a2588b6 100644 --- a/custom_components/hikvision_axpro/__init__.py +++ b/custom_components/hikvision_axpro/__init__.py @@ -10,7 +10,10 @@ from async_timeout import timeout -from homeassistant.components.alarm_control_panel import SCAN_INTERVAL +from homeassistant.components.alarm_control_panel import ( + SCAN_INTERVAL, + AlarmControlPanelState, +) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_CODE_FORMAT, @@ -21,11 +24,7 @@ CONF_CODE, CONF_SCAN_INTERVAL, Platform, - STATE_ALARM_ARMED_HOME, - STATE_ALARM_ARMED_VACATION, - STATE_ALARM_ARMED_AWAY, - STATE_ALARM_DISARMED, - STATE_ALARM_TRIGGERED, SERVICE_RELOAD + SERVICE_RELOAD ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady @@ -248,7 +247,7 @@ def _update_relays_status(self) -> RelayStatusSearchResponse: def _update_data(self) -> None: """Fetch data from axpro via sync functions.""" - status = STATE_ALARM_DISARMED + status = AlarmControlPanelState.DISARMED status_json = self.axpro.subsystem_status() try: subsys_resp = SubSystemResponse.from_dict(status_json) @@ -265,13 +264,13 @@ def _update_data(self) -> None: if self.use_sub_systems and subsys.id != 1: continue if subsys.alarm: - status = STATE_ALARM_TRIGGERED + status = AlarmControlPanelState.TRIGGERED elif subsys.arming == Arming.AWAY: - status = STATE_ALARM_ARMED_AWAY + status = AlarmControlPanelState.ARMED_AWAY elif subsys.arming == Arming.STAY: - status = STATE_ALARM_ARMED_HOME + status = AlarmControlPanelState.ARMED_HOME elif subsys.arming == Arming.VACATION: - status = STATE_ALARM_ARMED_VACATION + status = AlarmControlPanelState.ARMED_VACATION _LOGGER.debug("SubSystem status: %s", subsys_resp) except: _LOGGER.warning("Error getting status: %s", status_json) diff --git a/custom_components/hikvision_axpro/alarm_control_panel.py b/custom_components/hikvision_axpro/alarm_control_panel.py index 02c92c9..6bbd603 100644 --- a/custom_components/hikvision_axpro/alarm_control_panel.py +++ b/custom_components/hikvision_axpro/alarm_control_panel.py @@ -3,8 +3,6 @@ import logging from homeassistant.config_entries import ConfigEntry -from homeassistant.const import STATE_ALARM_TRIGGERED, STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, \ - STATE_ALARM_ARMED_VACATION, STATE_ALARM_DISARMED from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity import DeviceInfo @@ -13,6 +11,7 @@ from homeassistant.components.alarm_control_panel import ( AlarmControlPanelEntity, AlarmControlPanelEntityFeature, + AlarmControlPanelState, CodeFormat, ) from homeassistant.helpers import device_registry as dr @@ -182,15 +181,15 @@ def name(self): def state(self): """Return the state of the device.""" if self.sys.alarm: - return STATE_ALARM_TRIGGERED + return AlarmControlPanelState.TRIGGERED if self.sys.arming == Arming.AWAY: - return STATE_ALARM_ARMED_AWAY + return AlarmControlPanelState.ARMED_AWAY if self.sys.arming == Arming.STAY: - return STATE_ALARM_ARMED_HOME + return AlarmControlPanelState.ARMED_HOME if self.sys.arming == Arming.VACATION: - return STATE_ALARM_ARMED_VACATION + return AlarmControlPanelState.ARMED_VACATION if self.sys.arming == Arming.DISARM: - return STATE_ALARM_DISARMED + return AlarmControlPanelState.DISARMED return None @property