2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Blink Alarm Control Panel."""
|
2018-10-03 02:17:14 +00:00
|
|
|
import logging
|
|
|
|
|
2020-04-25 16:05:28 +00:00
|
|
|
from homeassistant.components.alarm_control_panel import AlarmControlPanelEntity
|
2019-11-25 23:42:53 +00:00
|
|
|
from homeassistant.components.alarm_control_panel.const import SUPPORT_ALARM_ARM_AWAY
|
2022-01-03 09:57:25 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2018-10-03 02:17:14 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_ATTRIBUTION,
|
|
|
|
STATE_ALARM_ARMED_AWAY,
|
|
|
|
STATE_ALARM_DISARMED,
|
|
|
|
)
|
2022-01-03 09:57:25 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-12-21 11:06:08 +00:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
2022-01-03 09:57:25 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2021-12-21 11:06:08 +00:00
|
|
|
from .const import DEFAULT_ATTRIBUTION, DEFAULT_BRAND, DOMAIN
|
2018-10-03 02:17:14 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ICON = "mdi:security"
|
2018-10-03 02:17:14 +00:00
|
|
|
|
|
|
|
|
2022-01-03 09:57:25 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
2020-05-13 13:50:29 +00:00
|
|
|
"""Set up the Blink Alarm Control Panels."""
|
|
|
|
data = hass.data[DOMAIN][config.entry_id]
|
2018-10-03 02:17:14 +00:00
|
|
|
|
|
|
|
sync_modules = []
|
2018-12-03 20:45:12 +00:00
|
|
|
for sync_name, sync_module in data.sync.items():
|
|
|
|
sync_modules.append(BlinkSyncModule(data, sync_name, sync_module))
|
2020-05-13 13:50:29 +00:00
|
|
|
async_add_entities(sync_modules)
|
2018-10-03 02:17:14 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:05:28 +00:00
|
|
|
class BlinkSyncModule(AlarmControlPanelEntity):
|
2018-10-03 02:17:14 +00:00
|
|
|
"""Representation of a Blink Alarm Control Panel."""
|
|
|
|
|
2021-07-18 21:21:12 +00:00
|
|
|
_attr_icon = ICON
|
|
|
|
_attr_supported_features = SUPPORT_ALARM_ARM_AWAY
|
|
|
|
|
2018-12-03 20:45:12 +00:00
|
|
|
def __init__(self, data, name, sync):
|
2018-10-03 02:17:14 +00:00
|
|
|
"""Initialize the alarm control panel."""
|
|
|
|
self.data = data
|
2018-12-03 20:45:12 +00:00
|
|
|
self.sync = sync
|
2018-10-03 02:17:14 +00:00
|
|
|
self._name = name
|
2021-07-18 21:21:12 +00:00
|
|
|
self._attr_unique_id = sync.serial
|
|
|
|
self._attr_name = f"{DOMAIN} {name}"
|
2021-12-21 11:06:08 +00:00
|
|
|
self._attr_device_info = DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, sync.serial)}, name=name, manufacturer=DEFAULT_BRAND
|
|
|
|
)
|
2018-10-03 02:17:14 +00:00
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update the state of the device."""
|
|
|
|
_LOGGER.debug("Updating Blink Alarm Control Panel %s", self._name)
|
|
|
|
self.data.refresh()
|
2021-07-18 21:21:12 +00:00
|
|
|
self._attr_state = (
|
|
|
|
STATE_ALARM_ARMED_AWAY if self.sync.arm else STATE_ALARM_DISARMED
|
|
|
|
)
|
|
|
|
self.sync.attributes["network_info"] = self.data.networks
|
|
|
|
self.sync.attributes["associated_cameras"] = list(self.sync.cameras)
|
|
|
|
self.sync.attributes[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION
|
|
|
|
self._attr_extra_state_attributes = self.sync.attributes
|
2018-10-03 02:17:14 +00:00
|
|
|
|
|
|
|
def alarm_disarm(self, code=None):
|
|
|
|
"""Send disarm command."""
|
|
|
|
self.sync.arm = False
|
|
|
|
self.sync.refresh()
|
|
|
|
|
|
|
|
def alarm_arm_away(self, code=None):
|
|
|
|
"""Send arm command."""
|
|
|
|
self.sync.arm = True
|
|
|
|
self.sync.refresh()
|