2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Blink system camera control."""
|
2017-03-07 22:26:53 +00:00
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
2018-10-03 02:17:14 +00:00
|
|
|
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
2017-03-07 22:26:53 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import BINARY_SENSORS, BLINK_DATA
|
|
|
|
|
2017-03-07 22:26:53 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-03-26 13:50:40 +00:00
|
|
|
"""Set up the blink binary sensors."""
|
2017-03-07 22:26:53 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2018-10-03 02:17:14 +00:00
|
|
|
data = hass.data[BLINK_DATA]
|
2017-03-07 22:26:53 +00:00
|
|
|
|
2018-10-03 02:17:14 +00:00
|
|
|
devs = []
|
2018-12-03 20:45:12 +00:00
|
|
|
for camera in data.cameras:
|
2018-10-03 02:17:14 +00:00
|
|
|
for sensor_type in discovery_info[CONF_MONITORED_CONDITIONS]:
|
|
|
|
devs.append(BlinkBinarySensor(data, camera, sensor_type))
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devs, True)
|
2017-03-07 22:26:53 +00:00
|
|
|
|
|
|
|
|
2018-10-03 02:17:14 +00:00
|
|
|
class BlinkBinarySensor(BinarySensorDevice):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Representation of a Blink binary sensor."""
|
2017-03-07 22:26:53 +00:00
|
|
|
|
2018-10-03 02:17:14 +00:00
|
|
|
def __init__(self, data, camera, sensor_type):
|
2017-03-07 22:26:53 +00:00
|
|
|
"""Initialize the sensor."""
|
|
|
|
self.data = data
|
2018-10-03 02:17:14 +00:00
|
|
|
self._type = sensor_type
|
|
|
|
name, icon = BINARY_SENSORS[sensor_type]
|
2019-09-03 15:09:59 +00:00
|
|
|
self._name = f"{BLINK_DATA} {camera} {name}"
|
2018-10-03 02:17:14 +00:00
|
|
|
self._icon = icon
|
2018-12-03 20:45:12 +00:00
|
|
|
self._camera = data.cameras[camera]
|
2018-10-03 02:17:14 +00:00
|
|
|
self._state = None
|
2019-09-03 15:09:59 +00:00
|
|
|
self._unique_id = f"{self._camera.serial}-{self._type}"
|
2017-03-07 22:26:53 +00: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-03 02:17:14 +00:00
|
|
|
self._state = self._camera.attributes[self._type]
|