Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix deprecation warnings for alarm states #138

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions custom_components/hikvision_axpro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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 @@ -22,11 +25,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 @@ -251,7 +250,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 @@ -268,13 +267,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