2020-02-27 02:48:44 +00:00
|
|
|
"""Support for August doorbell camera."""
|
2021-08-11 00:33:06 +00:00
|
|
|
from __future__ import annotations
|
2018-02-18 08:24:51 +00:00
|
|
|
|
2021-03-22 05:35:12 +00:00
|
|
|
from yalexs.activity import ActivityType
|
|
|
|
from yalexs.util import update_doorbell_image_from_activity
|
2018-02-18 08:24:51 +00:00
|
|
|
|
|
|
|
from homeassistant.components.camera import Camera
|
2022-01-03 12:22:41 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2020-03-09 20:54:05 +00:00
|
|
|
from homeassistant.helpers import aiohttp_client
|
2022-01-03 12:22:41 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2018-02-18 08:24:51 +00:00
|
|
|
|
2022-01-04 23:32:11 +00:00
|
|
|
from . import AugustData
|
2022-03-15 18:05:56 +00:00
|
|
|
from .const import DEFAULT_NAME, DEFAULT_TIMEOUT, DOMAIN
|
2020-02-28 03:44:23 +00:00
|
|
|
from .entity import AugustEntityMixin
|
2018-02-18 08:24:51 +00:00
|
|
|
|
|
|
|
|
2022-01-03 12:22:41 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2018-02-18 08:24:51 +00:00
|
|
|
"""Set up August cameras."""
|
2022-03-15 18:05:56 +00:00
|
|
|
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
|
2021-04-25 09:32:34 +00:00
|
|
|
session = aiohttp_client.async_get_clientsession(hass)
|
|
|
|
async_add_entities(
|
2022-03-15 18:05:56 +00:00
|
|
|
AugustCamera(data, doorbell, session, DEFAULT_TIMEOUT)
|
|
|
|
for doorbell in data.doorbells
|
2021-04-25 09:32:34 +00:00
|
|
|
)
|
2018-02-18 08:24:51 +00:00
|
|
|
|
|
|
|
|
2020-02-28 03:44:23 +00:00
|
|
|
class AugustCamera(AugustEntityMixin, Camera):
|
2020-02-12 23:35:07 +00:00
|
|
|
"""An implementation of a August security camera."""
|
2018-02-18 08:24:51 +00:00
|
|
|
|
2021-04-25 09:32:34 +00:00
|
|
|
def __init__(self, data, device, session, timeout):
|
2020-02-12 23:35:07 +00:00
|
|
|
"""Initialize a August security camera."""
|
2020-02-28 03:44:23 +00:00
|
|
|
super().__init__(data, device)
|
2018-02-18 08:24:51 +00:00
|
|
|
self._timeout = timeout
|
2021-04-25 09:32:34 +00:00
|
|
|
self._session = session
|
2018-02-18 08:24:51 +00:00
|
|
|
self._image_url = None
|
|
|
|
self._image_content = None
|
2021-07-13 19:56:34 +00:00
|
|
|
self._attr_name = f"{device.device_name} Camera"
|
|
|
|
self._attr_unique_id = f"{self._device_id:s}_camera"
|
2018-02-18 08:24:51 +00:00
|
|
|
|
|
|
|
@property
|
2022-08-18 13:56:52 +00:00
|
|
|
def is_recording(self) -> bool:
|
2018-02-18 08:24:51 +00:00
|
|
|
"""Return true if the device is recording."""
|
2020-02-28 03:44:23 +00:00
|
|
|
return self._device.has_subscription
|
2018-02-18 08:24:51 +00:00
|
|
|
|
|
|
|
@property
|
2022-08-18 13:56:52 +00:00
|
|
|
def motion_detection_enabled(self) -> bool:
|
2018-02-18 08:24:51 +00:00
|
|
|
"""Return the camera motion detection status."""
|
|
|
|
return True
|
|
|
|
|
|
|
|
@property
|
|
|
|
def brand(self):
|
|
|
|
"""Return the camera brand."""
|
2020-02-25 18:18:15 +00:00
|
|
|
return DEFAULT_NAME
|
2018-02-18 08:24:51 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def model(self):
|
|
|
|
"""Return the camera model."""
|
2020-02-28 03:44:23 +00:00
|
|
|
return self._detail.model
|
2018-02-18 08:24:51 +00:00
|
|
|
|
2020-02-28 03:44:23 +00:00
|
|
|
@callback
|
|
|
|
def _update_from_data(self):
|
|
|
|
"""Get the latest state of the sensor."""
|
|
|
|
doorbell_activity = self._data.activity_stream.get_latest_device_activity(
|
2021-12-19 06:25:30 +00:00
|
|
|
self._device_id,
|
|
|
|
{ActivityType.DOORBELL_MOTION, ActivityType.DOORBELL_IMAGE_CAPTURE},
|
2020-02-26 07:43:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if doorbell_activity is not None:
|
2020-02-28 03:44:23 +00:00
|
|
|
update_doorbell_image_from_activity(self._detail, doorbell_activity)
|
2020-02-26 07:43:41 +00:00
|
|
|
|
2021-08-11 00:33:06 +00:00
|
|
|
async def async_camera_image(
|
|
|
|
self, width: int | None = None, height: int | None = None
|
|
|
|
) -> bytes | None:
|
2020-02-28 03:44:23 +00:00
|
|
|
"""Return bytes of camera image."""
|
|
|
|
self._update_from_data()
|
2020-02-25 18:18:15 +00:00
|
|
|
|
2020-02-28 03:44:23 +00:00
|
|
|
if self._image_url is not self._detail.image_url:
|
|
|
|
self._image_url = self._detail.image_url
|
2020-03-09 20:54:05 +00:00
|
|
|
self._image_content = await self._detail.async_get_doorbell_image(
|
2021-04-25 09:32:34 +00:00
|
|
|
self._session, timeout=self._timeout
|
2020-02-21 06:39:07 +00:00
|
|
|
)
|
2018-02-18 08:24:51 +00:00
|
|
|
return self._image_content
|