2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Blink system camera."""
|
2017-03-07 22:26:53 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.camera import Camera
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import BLINK_DATA, DEFAULT_BRAND
|
|
|
|
|
2018-01-21 06:35:38 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_VIDEO_CLIP = "video"
|
|
|
|
ATTR_IMAGE = "image"
|
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-04-30 05:04:49 +00:00
|
|
|
"""Set up a Blink Camera."""
|
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]
|
|
|
|
devs = []
|
2018-12-03 20:45:12 +00:00
|
|
|
for name, camera in data.cameras.items():
|
2018-10-03 02:17:14 +00:00
|
|
|
devs.append(BlinkCamera(data, name, camera))
|
2017-03-07 22:26:53 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devs)
|
2017-03-07 22:26:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BlinkCamera(Camera):
|
|
|
|
"""An implementation of a Blink Camera."""
|
|
|
|
|
2018-10-03 02:17:14 +00:00
|
|
|
def __init__(self, data, name, camera):
|
2017-03-07 22:26:53 +00:00
|
|
|
"""Initialize a camera."""
|
|
|
|
super().__init__()
|
|
|
|
self.data = data
|
2019-09-03 15:09:59 +00:00
|
|
|
self._name = f"{BLINK_DATA} {name}"
|
2018-10-03 02:17:14 +00:00
|
|
|
self._camera = camera
|
2019-09-03 15:09:59 +00:00
|
|
|
self._unique_id = f"{camera.serial}-camera"
|
2017-03-07 22:26:53 +00:00
|
|
|
self.response = None
|
2018-10-03 02:17:14 +00:00
|
|
|
self.current_image = None
|
|
|
|
self.last_image = None
|
2018-01-21 06:35:38 +00:00
|
|
|
_LOGGER.debug("Initialized blink camera %s", self._name)
|
2017-03-07 22:26:53 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Return the camera name."""
|
2017-03-07 22:26:53 +00:00
|
|
|
return self._name
|
|
|
|
|
2018-10-17 06:38:03 +00:00
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return the unique camera id."""
|
|
|
|
return self._unique_id
|
|
|
|
|
2018-10-03 02:17:14 +00:00
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the camera attributes."""
|
|
|
|
return self._camera.attributes
|
|
|
|
|
|
|
|
def enable_motion_detection(self):
|
|
|
|
"""Enable motion detection for the camera."""
|
|
|
|
self._camera.set_motion_detect(True)
|
|
|
|
|
|
|
|
def disable_motion_detection(self):
|
|
|
|
"""Disable motion detection for the camera."""
|
|
|
|
self._camera.set_motion_detect(False)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def motion_detection_enabled(self):
|
|
|
|
"""Return the state of the camera."""
|
2018-10-17 06:38:03 +00:00
|
|
|
return self._camera.motion_enabled
|
2018-10-03 02:17:14 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def brand(self):
|
|
|
|
"""Return the camera brand."""
|
|
|
|
return DEFAULT_BRAND
|
2017-03-07 22:26:53 +00:00
|
|
|
|
|
|
|
def camera_image(self):
|
2017-09-23 15:15:46 +00:00
|
|
|
"""Return a still image response from the camera."""
|
2018-10-03 02:17:14 +00:00
|
|
|
return self._camera.image_from_cache.content
|