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
|
|
|
import homeassistant.helpers.config_validation as cv
|
2018-06-12 06:01:26 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2017-10-07 08:59:46 +00:00
|
|
|
from homeassistant.components.alarm_control_panel import (
|
|
|
|
AlarmControlPanel, PLATFORM_SCHEMA)
|
2018-06-12 06:01:26 +00:00
|
|
|
from homeassistant.components.arlo import (
|
2019-02-14 21:09:22 +00:00
|
|
|
DATA_ARLO, ATTRIBUTION, SIGNAL_UPDATE_ARLO)
|
2017-10-07 08:59:46 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
ATTR_ATTRIBUTION, STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME,
|
2019-01-15 22:19:04 +00:00
|
|
|
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_NIGHT)
|
2017-10-07 08:07:38 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2017-10-07 08:59:46 +00:00
|
|
|
ARMED = 'armed'
|
|
|
|
|
2017-10-07 08:07:38 +00:00
|
|
|
CONF_HOME_MODE_NAME = 'home_mode_name'
|
2017-11-26 00:13:14 +00:00
|
|
|
CONF_AWAY_MODE_NAME = 'away_mode_name'
|
2019-01-15 22:19:04 +00:00
|
|
|
CONF_NIGHT_MODE_NAME = 'night_mode_name'
|
2017-10-07 08:59:46 +00:00
|
|
|
|
|
|
|
DEPENDENCIES = ['arlo']
|
|
|
|
|
|
|
|
DISARMED = 'disarmed'
|
|
|
|
|
2017-10-07 08:07:38 +00:00
|
|
|
ICON = 'mdi:security'
|
|
|
|
|
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
|
|
vol.Optional(CONF_HOME_MODE_NAME, default=ARMED): cv.string,
|
2017-11-26 00:13:14 +00:00
|
|
|
vol.Optional(CONF_AWAY_MODE_NAME, default=ARMED): cv.string,
|
2019-01-15 22:19:04 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
home_mode_name = config.get(CONF_HOME_MODE_NAME)
|
2017-11-26 00:13:14 +00:00
|
|
|
away_mode_name = config.get(CONF_AWAY_MODE_NAME)
|
2019-01-15 22:19:04 +00:00
|
|
|
night_mode_name = config.get(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:
|
2017-11-26 00:13:14 +00:00
|
|
|
base_stations.append(ArloBaseStation(base_station, home_mode_name,
|
2019-01-15 22:19:04 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
class ArloBaseStation(AlarmControlPanel):
|
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."""
|
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass, SIGNAL_UPDATE_ARLO, self._update_callback)
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
async def async_alarm_disarm(self, code=None):
|
2017-10-07 08:07:38 +00:00
|
|
|
"""Send disarm command."""
|
|
|
|
self._base_station.mode = DISARMED
|
|
|
|
|
2018-06-12 06:01:26 +00:00
|
|
|
async def async_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
|
|
|
|
2018-06-12 06:01:26 +00:00
|
|
|
async def async_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
|
|
|
|
|
2019-01-15 22:19:04 +00:00
|
|
|
async def async_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
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the state attributes."""
|
|
|
|
return {
|
2019-02-14 21:09:22 +00:00
|
|
|
ATTR_ATTRIBUTION: ATTRIBUTION,
|
2017-10-07 08:07:38 +00:00
|
|
|
'device_id': self._base_station.device_id
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|