2022-03-05 07:37:58 +00:00
|
|
|
"""Support for Android IP Webcam Cameras."""
|
2024-03-08 13:51:32 +00:00
|
|
|
|
2022-03-05 07:37:58 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from homeassistant.components.mjpeg import MjpegCamera, filter_urllib3_logging
|
2022-08-09 12:08:46 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import (
|
|
|
|
CONF_HOST,
|
|
|
|
CONF_PASSWORD,
|
|
|
|
CONF_USERNAME,
|
|
|
|
HTTP_BASIC_AUTHENTICATION,
|
|
|
|
)
|
2022-03-05 07:37:58 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2023-08-11 02:04:26 +00:00
|
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
2022-03-05 07:37:58 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
2022-08-09 12:08:46 +00:00
|
|
|
from .const import DOMAIN
|
|
|
|
from .coordinator import AndroidIPCamDataUpdateCoordinator
|
2022-03-05 07:37:58 +00:00
|
|
|
|
2022-08-09 12:08:46 +00:00
|
|
|
|
|
|
|
async def async_setup_entry(
|
2022-03-05 07:37:58 +00:00
|
|
|
hass: HomeAssistant,
|
2022-08-09 12:08:46 +00:00
|
|
|
config_entry: ConfigEntry,
|
2022-03-05 07:37:58 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2022-08-09 12:08:46 +00:00
|
|
|
"""Set up the IP Webcam camera from config entry."""
|
2022-03-05 07:37:58 +00:00
|
|
|
filter_urllib3_logging()
|
2022-08-09 12:08:46 +00:00
|
|
|
coordinator: AndroidIPCamDataUpdateCoordinator = hass.data[DOMAIN][
|
|
|
|
config_entry.entry_id
|
|
|
|
]
|
|
|
|
|
|
|
|
async_add_entities([IPWebcamCamera(coordinator)])
|
2022-03-05 07:37:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class IPWebcamCamera(MjpegCamera):
|
|
|
|
"""Representation of a IP Webcam camera."""
|
|
|
|
|
2022-08-09 12:08:46 +00:00
|
|
|
_attr_has_entity_name = True
|
|
|
|
|
|
|
|
def __init__(self, coordinator: AndroidIPCamDataUpdateCoordinator) -> None:
|
2022-03-05 07:37:58 +00:00
|
|
|
"""Initialize the camera."""
|
|
|
|
super().__init__(
|
2022-08-09 12:08:46 +00:00
|
|
|
mjpeg_url=coordinator.cam.mjpeg_url,
|
|
|
|
still_image_url=coordinator.cam.image_url,
|
2022-03-05 07:37:58 +00:00
|
|
|
authentication=HTTP_BASIC_AUTHENTICATION,
|
2022-08-09 12:08:46 +00:00
|
|
|
username=coordinator.config_entry.data.get(CONF_USERNAME),
|
|
|
|
password=coordinator.config_entry.data.get(CONF_PASSWORD, ""),
|
|
|
|
)
|
|
|
|
self._attr_unique_id = f"{coordinator.config_entry.entry_id}-camera"
|
|
|
|
self._attr_device_info = DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
|
2023-10-06 16:10:32 +00:00
|
|
|
name=coordinator.config_entry.data[CONF_HOST],
|
2022-03-05 07:37:58 +00:00
|
|
|
)
|