2019-02-13 21:21:14 +01:00
|
|
|
"""Support for Blink system camera control."""
|
2020-04-23 21:57:07 +02:00
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
2017-03-07 17:26:53 -05:00
|
|
|
|
2020-05-13 09:50:29 -04:00
|
|
|
from .const import DOMAIN, TYPE_CAMERA_ARMED, TYPE_MOTION_DETECTED
|
2019-03-20 22:56:46 -07:00
|
|
|
|
2020-05-13 09:50:29 -04:00
|
|
|
BINARY_SENSORS = {
|
|
|
|
TYPE_CAMERA_ARMED: ["Camera Armed", "mdi:verified"],
|
|
|
|
TYPE_MOTION_DETECTED: ["Motion Detected", "mdi:run-fast"],
|
|
|
|
}
|
2017-03-07 17:26:53 -05:00
|
|
|
|
2020-05-13 09:50:29 -04:00
|
|
|
|
|
|
|
async def async_setup_entry(hass, config, async_add_entities):
|
2017-03-26 15:50:40 +02:00
|
|
|
"""Set up the blink binary sensors."""
|
2020-05-13 09:50:29 -04:00
|
|
|
data = hass.data[DOMAIN][config.entry_id]
|
2017-03-07 17:26:53 -05:00
|
|
|
|
2020-05-13 09:50:29 -04:00
|
|
|
entities = []
|
2018-12-03 15:45:12 -05:00
|
|
|
for camera in data.cameras:
|
2020-05-13 09:50:29 -04:00
|
|
|
for sensor_type in BINARY_SENSORS:
|
|
|
|
entities.append(BlinkBinarySensor(data, camera, sensor_type))
|
|
|
|
async_add_entities(entities)
|
2017-03-07 17:26:53 -05:00
|
|
|
|
|
|
|
|
2020-04-23 21:57:07 +02:00
|
|
|
class BlinkBinarySensor(BinarySensorEntity):
|
2017-04-30 07:04:49 +02:00
|
|
|
"""Representation of a Blink binary sensor."""
|
2017-03-07 17:26:53 -05:00
|
|
|
|
2018-10-02 22:17:14 -04:00
|
|
|
def __init__(self, data, camera, sensor_type):
|
2017-03-07 17:26:53 -05:00
|
|
|
"""Initialize the sensor."""
|
|
|
|
self.data = data
|
2018-10-02 22:17:14 -04:00
|
|
|
self._type = sensor_type
|
|
|
|
name, icon = BINARY_SENSORS[sensor_type]
|
2020-05-13 09:50:29 -04:00
|
|
|
self._name = f"{DOMAIN} {camera} {name}"
|
2018-10-02 22:17:14 -04:00
|
|
|
self._icon = icon
|
2018-12-03 15:45:12 -05:00
|
|
|
self._camera = data.cameras[camera]
|
2018-10-02 22:17:14 -04:00
|
|
|
self._state = None
|
2019-09-03 17:09:59 +02:00
|
|
|
self._unique_id = f"{self._camera.serial}-{self._type}"
|
2017-03-07 17:26:53 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the blink sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return the status of the sensor."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Update sensor state."""
|
|
|
|
self.data.refresh()
|
2018-10-02 22:17:14 -04:00
|
|
|
self._state = self._camera.attributes[self._type]
|