Skip to content

Commit

Permalink
Merge pull request #71 from natekspencer/dev
Browse files Browse the repository at this point in the history
Fix get_armed_state warning and adjust armed state map
  • Loading branch information
natekspencer authored Dec 13, 2022
2 parents 5821311 + 8a7ca82 commit 5904d29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
49 changes: 24 additions & 25 deletions custom_components/vivint/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

from vivintpy.enums import ArmedState

from homeassistant.components.alarm_control_panel import AlarmControlPanelEntity
from homeassistant.components.alarm_control_panel.const import (
SUPPORT_ALARM_ARM_AWAY,
SUPPORT_ALARM_ARM_HOME,
from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntity,
AlarmControlPanelEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_HOME,
STATE_ALARM_ARMING,
STATE_ALARM_DISARMED,
STATE_ALARM_PENDING,
STATE_ALARM_TRIGGERED,
)
from homeassistant.core import HomeAssistant
Expand All @@ -22,6 +23,20 @@
from .const import DOMAIN
from .hub import VivintEntity

ARMED_STATE_MAP = {
ArmedState.DISARMED: STATE_ALARM_DISARMED,
ArmedState.ARMING_AWAY_IN_EXIT_DELAY: STATE_ALARM_ARMING,
ArmedState.ARMING_STAY_IN_EXIT_DELAY: STATE_ALARM_ARMING,
ArmedState.ARMED_STAY: STATE_ALARM_ARMED_HOME,
ArmedState.ARMED_AWAY: STATE_ALARM_ARMED_AWAY,
ArmedState.ARMED_STAY_IN_ENTRY_DELAY: STATE_ALARM_PENDING,
ArmedState.ARMED_AWAY_IN_ENTRY_DELAY: STATE_ALARM_PENDING,
ArmedState.ALARM: STATE_ALARM_TRIGGERED,
ArmedState.ALARM_FIRE: STATE_ALARM_TRIGGERED,
ArmedState.DISABLED: STATE_ALARM_DISARMED,
ArmedState.WALK_TEST: STATE_ALARM_DISARMED,
}


async def async_setup_entry(
hass: HomeAssistant,
Expand All @@ -47,7 +62,10 @@ class VivintAlarmControlPanelEntity(VivintEntity, AlarmControlPanelEntity):

_attr_changed_by = None
_attr_code_arm_required = False
_attr_supported_features = SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY
_attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
)

@property
def unique_id(self) -> str:
Expand All @@ -57,26 +75,7 @@ def unique_id(self) -> str:
@property
def state(self) -> StateType:
"""Return the state of the alarm control panel."""
arm_state = self.device.get_armed_state()
if arm_state == ArmedState.DISARMED:
state = STATE_ALARM_DISARMED
elif arm_state in [
ArmedState.ARMED_STAY,
ArmedState.ARMING_STAY_IN_EXIT_DELAY,
ArmedState.ARMED_STAY_IN_ENTRY_DELAY,
]:
state = STATE_ALARM_ARMED_HOME
elif arm_state in [
ArmedState.ARMED_AWAY,
ArmedState.ARMING_AWAY_IN_EXIT_DELAY,
ArmedState.ARMED_AWAY_IN_ENTRY_DELAY,
]:
state = STATE_ALARM_ARMED_AWAY
elif arm_state in [ArmedState.ALARM, ArmedState.ALARM_FIRE]:
state = STATE_ALARM_TRIGGERED
else:
state = None
return state
return ARMED_STATE_MAP.get(self.device.state)

async def async_alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/vivint/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "vivint",
"name": "Vivint",
"version": "2022.12.2",
"version": "2022.12.3",
"config_flow": true,
"documentation": "https://github.com/natekspencer/hacs-vivint",
"issue_tracker": "https://github.com/natekspencer/hacs-vivint/issues",
Expand Down

0 comments on commit 5904d29

Please sign in to comment.