2019-02-13 20:21:14 +00:00
|
|
|
"""Camera support for the Skybell HD Doorbell."""
|
2021-08-11 00:33:06 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2018-12-17 23:31:10 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
from homeassistant.components.camera import (
|
|
|
|
PLATFORM_SCHEMA,
|
|
|
|
Camera,
|
|
|
|
CameraEntityDescription,
|
|
|
|
)
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2018-12-17 23:31:10 +00:00
|
|
|
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
2022-01-05 16:34:47 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2018-12-17 23:31:10 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2022-06-05 02:37:08 +00:00
|
|
|
from homeassistant.helpers.entity import EntityDescription
|
2022-01-05 16:34:47 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2017-10-08 18:14:39 +00:00
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
from .const import (
|
|
|
|
CONF_ACTIVITY_NAME,
|
|
|
|
CONF_AVATAR_NAME,
|
|
|
|
DOMAIN,
|
|
|
|
IMAGE_ACTIVITY,
|
|
|
|
IMAGE_AVATAR,
|
|
|
|
)
|
|
|
|
from .coordinator import SkybellDataUpdateCoordinator
|
|
|
|
from .entity import SkybellEntity
|
2018-12-17 23:31:10 +00:00
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
# Deprecated in Home Assistant 2022.6
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
|
|
{
|
|
|
|
vol.Optional(CONF_MONITORED_CONDITIONS, default=[IMAGE_AVATAR]): vol.All(
|
|
|
|
cv.ensure_list, [vol.In([IMAGE_AVATAR, IMAGE_ACTIVITY])]
|
|
|
|
),
|
|
|
|
vol.Optional(CONF_ACTIVITY_NAME): cv.string,
|
|
|
|
vol.Optional(CONF_AVATAR_NAME): cv.string,
|
|
|
|
}
|
|
|
|
)
|
2018-12-17 23:31:10 +00:00
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
CAMERA_TYPES: tuple[CameraEntityDescription, ...] = (
|
|
|
|
CameraEntityDescription(key="activity", name="Last Activity"),
|
|
|
|
CameraEntityDescription(key="avatar", name="Camera"),
|
|
|
|
)
|
2017-10-08 18:14:39 +00:00
|
|
|
|
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
|
|
|
"""Set up Skybell switch."""
|
|
|
|
async_add_entities(
|
|
|
|
SkybellCamera(coordinator, description)
|
|
|
|
for description in CAMERA_TYPES
|
|
|
|
for coordinator in hass.data[DOMAIN][entry.entry_id]
|
|
|
|
)
|
2017-10-08 18:14:39 +00:00
|
|
|
|
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
class SkybellCamera(SkybellEntity, Camera):
|
2017-10-08 18:14:39 +00:00
|
|
|
"""A camera implementation for Skybell devices."""
|
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
coordinator: SkybellDataUpdateCoordinator,
|
|
|
|
description: EntityDescription,
|
|
|
|
) -> None:
|
2017-10-08 18:14:39 +00:00
|
|
|
"""Initialize a camera for a Skybell device."""
|
2022-06-05 02:37:08 +00:00
|
|
|
super().__init__(coordinator, description)
|
2017-10-08 18:14:39 +00:00
|
|
|
Camera.__init__(self)
|
2018-12-17 23:31:10 +00:00
|
|
|
|
2022-06-05 02:37:08 +00:00
|
|
|
async def async_camera_image(
|
2021-08-11 00:33:06 +00:00
|
|
|
self, width: int | None = None, height: int | None = None
|
|
|
|
) -> bytes | None:
|
2017-10-08 18:14:39 +00:00
|
|
|
"""Get the latest camera image."""
|
2022-06-05 02:37:08 +00:00
|
|
|
return self._device.images[self.entity_description.key]
|