Alarm trigger support for Point (#21207)
This commit is contained in:
parent
966fd1034d
commit
73099caede
1 changed files with 48 additions and 6 deletions
|
@ -1,16 +1,25 @@
|
||||||
"""Support for Minut Point."""
|
"""Support for Minut Point."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.alarm_control_panel import (DOMAIN,
|
from homeassistant.components.alarm_control_panel import (
|
||||||
AlarmControlPanel)
|
DOMAIN, AlarmControlPanel)
|
||||||
from homeassistant.const import (STATE_ALARM_ARMED_AWAY, STATE_ALARM_DISARMED)
|
|
||||||
from homeassistant.components.point.const import (
|
from homeassistant.components.point.const import (
|
||||||
DOMAIN as POINT_DOMAIN, POINT_DISCOVERY_NEW)
|
DOMAIN as POINT_DOMAIN, POINT_DISCOVERY_NEW, SIGNAL_WEBHOOK)
|
||||||
|
from homeassistant.const import (
|
||||||
|
STATE_ALARM_ARMED_AWAY, STATE_ALARM_DISARMED, STATE_ALARM_TRIGGERED)
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
EVENT_MAP = {
|
||||||
|
'off': STATE_ALARM_DISARMED,
|
||||||
|
'alarm_silenced': STATE_ALARM_ARMED_AWAY,
|
||||||
|
'alarm_grace_period_expired': STATE_ALARM_TRIGGERED,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up a Point's alarm_control_panel based on a config entry."""
|
"""Set up a Point's alarm_control_panel based on a config entry."""
|
||||||
async def async_discover_home(home_id):
|
async def async_discover_home(home_id):
|
||||||
|
@ -30,6 +39,32 @@ class MinutPointAlarmControl(AlarmControlPanel):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
self._client = point_client
|
self._client = point_client
|
||||||
self._home_id = home_id
|
self._home_id = home_id
|
||||||
|
self._async_unsub_hook_dispatcher_connect = None
|
||||||
|
self._changed_by = None
|
||||||
|
|
||||||
|
async def async_added_to_hass(self):
|
||||||
|
"""Call when entity is added to HOme Assistant."""
|
||||||
|
await super().async_added_to_hass()
|
||||||
|
self._async_unsub_hook_dispatcher_connect = async_dispatcher_connect(
|
||||||
|
self.hass, SIGNAL_WEBHOOK, self._webhook_event)
|
||||||
|
|
||||||
|
async def async_will_remove_from_hass(self):
|
||||||
|
"""Disconnect dispatcher listener when removed."""
|
||||||
|
await super().async_will_remove_from_hass()
|
||||||
|
if self._async_unsub_hook_dispatcher_connect:
|
||||||
|
self._async_unsub_hook_dispatcher_connect()
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _webhook_event(self, data, webhook):
|
||||||
|
"""Process new event from the webhook."""
|
||||||
|
_type = data.get('event', {}).get('type')
|
||||||
|
_device_id = data.get('event', {}).get('device_id')
|
||||||
|
if _device_id not in self._home['devices'] or _type not in EVENT_MAP:
|
||||||
|
return
|
||||||
|
_LOGGER.debug("Recieved webhook: %s", _type)
|
||||||
|
self._home['alarm_status'] = EVENT_MAP[_type]
|
||||||
|
self._changed_by = _device_id
|
||||||
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _home(self):
|
def _home(self):
|
||||||
|
@ -44,8 +79,15 @@ class MinutPointAlarmControl(AlarmControlPanel):
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return state of the device."""
|
"""Return state of the device."""
|
||||||
return STATE_ALARM_DISARMED if self._home[
|
return EVENT_MAP.get(
|
||||||
'alarm_status'] == 'off' else STATE_ALARM_ARMED_AWAY
|
self._home['alarm_status'],
|
||||||
|
STATE_ALARM_ARMED_AWAY,
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def changed_by(self):
|
||||||
|
"""Return the user the last change was triggered by."""
|
||||||
|
return self._changed_by
|
||||||
|
|
||||||
def alarm_disarm(self, code=None):
|
def alarm_disarm(self, code=None):
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue