2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Arlo Alarm Control Panels."""
|
2017-10-07 08:07:38 +00:00
|
|
|
import logging
|
2017-10-07 08:59:46 +00:00
|
|
|
|
2017-10-07 08:07:38 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2017-10-07 08:59:46 +00:00
|
|
|
from homeassistant.components.alarm_control_panel import (
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA,
|
2020-04-25 16:05:28 +00:00
|
|
|
AlarmControlPanelEntity,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-25 23:42:53 +00:00
|
|
|
from homeassistant.components.alarm_control_panel.const import (
|
|
|
|
SUPPORT_ALARM_ARM_AWAY,
|
|
|
|
SUPPORT_ALARM_ARM_HOME,
|
|
|
|
SUPPORT_ALARM_ARM_NIGHT,
|
|
|
|
)
|
2017-10-07 08:59:46 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_ATTRIBUTION,
|
|
|
|
STATE_ALARM_ARMED_AWAY,
|
|
|
|
STATE_ALARM_ARMED_HOME,
|
|
|
|
STATE_ALARM_ARMED_NIGHT,
|
|
|
|
STATE_ALARM_DISARMED,
|
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
|
|
|
|
|
|
from . import ATTRIBUTION, DATA_ARLO, SIGNAL_UPDATE_ARLO
|
2017-10-07 08:07:38 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ARMED = "armed"
|
2017-10-07 08:59:46 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONF_HOME_MODE_NAME = "home_mode_name"
|
|
|
|
CONF_AWAY_MODE_NAME = "away_mode_name"
|
|
|
|
CONF_NIGHT_MODE_NAME = "night_mode_name"
|
2017-10-07 08:59:46 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DISARMED = "disarmed"
|
2017-10-07 08:59:46 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ICON = "mdi:security"
|
2017-10-07 08:07:38 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
vol.Optional(CONF_HOME_MODE_NAME, default=ARMED): cv.string,
|
|
|
|
vol.Optional(CONF_AWAY_MODE_NAME, default=ARMED): cv.string,
|
|
|
|
vol.Optional(CONF_NIGHT_MODE_NAME, default=ARMED): cv.string,
|
|
|
|
}
|
|
|
|
)
|
2017-10-07 08:07:38 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-10-07 08:59:46 +00:00
|
|
|
"""Set up the Arlo Alarm Control Panels."""
|
2018-06-12 06:01:26 +00:00
|
|
|
arlo = hass.data[DATA_ARLO]
|
2017-10-07 08:07:38 +00:00
|
|
|
|
2018-06-12 06:01:26 +00:00
|
|
|
if not arlo.base_stations:
|
2017-10-07 08:07:38 +00:00
|
|
|
return
|
|
|
|
|
2020-04-07 20:45:56 +00:00
|
|
|
home_mode_name = config[CONF_HOME_MODE_NAME]
|
|
|
|
away_mode_name = config[CONF_AWAY_MODE_NAME]
|
|
|
|
night_mode_name = config[CONF_NIGHT_MODE_NAME]
|
2017-10-07 08:07:38 +00:00
|
|
|
base_stations = []
|
2018-06-12 06:01:26 +00:00
|
|
|
for base_station in arlo.base_stations:
|
2019-07-31 19:25:30 +00:00
|
|
|
base_stations.append(
|
|
|
|
ArloBaseStation(
|
|
|
|
base_station, home_mode_name, away_mode_name, night_mode_name
|
|
|
|
)
|
|
|
|
)
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(base_stations, True)
|
2017-10-07 08:07:38 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:05:28 +00:00
|
|
|
class ArloBaseStation(AlarmControlPanelEntity):
|
2017-10-07 08:59:46 +00:00
|
|
|
"""Representation of an Arlo Alarm Control Panel."""
|
2017-10-07 08:07:38 +00:00
|
|
|
|
2019-01-15 22:19:04 +00:00
|
|
|
def __init__(self, data, home_mode_name, away_mode_name, night_mode_name):
|
2017-10-07 08:07:38 +00:00
|
|
|
"""Initialize the alarm control panel."""
|
|
|
|
self._base_station = data
|
|
|
|
self._home_mode_name = home_mode_name
|
2017-11-26 00:13:14 +00:00
|
|
|
self._away_mode_name = away_mode_name
|
2019-01-15 22:19:04 +00:00
|
|
|
self._night_mode_name = night_mode_name
|
2017-10-07 08:07:38 +00:00
|
|
|
self._state = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return icon."""
|
|
|
|
return ICON
|
|
|
|
|
2018-06-12 06:01:26 +00:00
|
|
|
async def async_added_to_hass(self):
|
|
|
|
"""Register callbacks."""
|
2020-04-02 16:25:33 +00:00
|
|
|
self.async_on_remove(
|
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass, SIGNAL_UPDATE_ARLO, self._update_callback
|
|
|
|
)
|
|
|
|
)
|
2018-06-12 06:01:26 +00:00
|
|
|
|
|
|
|
@callback
|
|
|
|
def _update_callback(self):
|
|
|
|
"""Call update method."""
|
|
|
|
self.async_schedule_update_ha_state(True)
|
|
|
|
|
2017-10-07 08:07:38 +00:00
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the device."""
|
|
|
|
return self._state
|
|
|
|
|
2019-11-25 23:42:53 +00:00
|
|
|
@property
|
|
|
|
def supported_features(self) -> int:
|
|
|
|
"""Return the list of supported features."""
|
|
|
|
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT
|
|
|
|
|
2017-10-08 07:26:16 +00:00
|
|
|
def update(self):
|
2017-10-07 08:07:38 +00:00
|
|
|
"""Update the state of the device."""
|
2018-06-12 06:01:26 +00:00
|
|
|
_LOGGER.debug("Updating Arlo Alarm Control Panel %s", self.name)
|
|
|
|
mode = self._base_station.mode
|
|
|
|
if mode:
|
|
|
|
self._state = self._get_state_from_mode(mode)
|
|
|
|
else:
|
|
|
|
self._state = None
|
|
|
|
|
2020-02-25 22:10:43 +00:00
|
|
|
def alarm_disarm(self, code=None):
|
2017-10-07 08:07:38 +00:00
|
|
|
"""Send disarm command."""
|
|
|
|
self._base_station.mode = DISARMED
|
|
|
|
|
2020-02-25 22:10:43 +00:00
|
|
|
def alarm_arm_away(self, code=None):
|
2017-11-26 00:13:14 +00:00
|
|
|
"""Send arm away command. Uses custom mode."""
|
|
|
|
self._base_station.mode = self._away_mode_name
|
2017-10-07 08:07:38 +00:00
|
|
|
|
2020-02-25 22:10:43 +00:00
|
|
|
def alarm_arm_home(self, code=None):
|
2017-10-07 08:07:38 +00:00
|
|
|
"""Send arm home command. Uses custom mode."""
|
|
|
|
self._base_station.mode = self._home_mode_name
|
|
|
|
|
2020-02-25 22:10:43 +00:00
|
|
|
def alarm_arm_night(self, code=None):
|
2019-01-15 22:27:56 +00:00
|
|
|
"""Send arm night command. Uses custom mode."""
|
2019-01-15 22:19:04 +00:00
|
|
|
self._base_station.mode = self._night_mode_name
|
|
|
|
|
2017-10-07 08:07:38 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the base station."""
|
|
|
|
return self._base_station.name
|
|
|
|
|
|
|
|
@property
|
2021-03-11 15:51:03 +00:00
|
|
|
def extra_state_attributes(self):
|
2017-10-07 08:07:38 +00:00
|
|
|
"""Return the state attributes."""
|
|
|
|
return {
|
2019-02-14 21:09:22 +00:00
|
|
|
ATTR_ATTRIBUTION: ATTRIBUTION,
|
2019-07-31 19:25:30 +00:00
|
|
|
"device_id": self._base_station.device_id,
|
2017-10-07 08:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _get_state_from_mode(self, mode):
|
2017-10-07 08:59:46 +00:00
|
|
|
"""Convert Arlo mode to Home Assistant state."""
|
2017-10-07 08:07:38 +00:00
|
|
|
if mode == ARMED:
|
|
|
|
return STATE_ALARM_ARMED_AWAY
|
2018-07-23 08:16:05 +00:00
|
|
|
if mode == DISARMED:
|
2017-10-07 08:07:38 +00:00
|
|
|
return STATE_ALARM_DISARMED
|
2018-07-23 08:16:05 +00:00
|
|
|
if mode == self._home_mode_name:
|
2017-10-07 08:07:38 +00:00
|
|
|
return STATE_ALARM_ARMED_HOME
|
2018-07-23 08:16:05 +00:00
|
|
|
if mode == self._away_mode_name:
|
2017-11-26 00:13:14 +00:00
|
|
|
return STATE_ALARM_ARMED_AWAY
|
2019-01-15 22:19:04 +00:00
|
|
|
if mode == self._night_mode_name:
|
|
|
|
return STATE_ALARM_ARMED_NIGHT
|
2018-06-12 06:01:26 +00:00
|
|
|
return mode
|