Skip to content

Commit

Permalink
fix: deprecation warnings for alarm states
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan <dusanuveric@protonmail.com>
  • Loading branch information
uvera authored and petrleocompel committed Dec 9, 2024
1 parent ecfdb67 commit c31c6a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 10 additions & 11 deletions custom_components/hikvision_axpro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions custom_components/hikvision_axpro/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +11,7 @@
from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntity,
AlarmControlPanelEntityFeature,
AlarmControlPanelState,
CodeFormat,
)
from homeassistant.helpers import device_registry as dr
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c31c6a0

Please sign in to comment.