Fix integrations building on top of mjpeg (#66557)

pull/66571/head
Franck Nijhof 2022-02-15 15:24:52 +01:00 committed by GitHub
parent 52ebe58b14
commit cbdbb66475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 68 deletions

View File

@ -76,6 +76,7 @@ components: &components
- homeassistant/components/logger/*
- homeassistant/components/lovelace/*
- homeassistant/components/media_source/*
- homeassistant/components/mjpeg/*
- homeassistant/components/mqtt/*
- homeassistant/components/network/*
- homeassistant/components/onboarding/*

View File

@ -5,13 +5,8 @@ import logging
from agent import AgentError
from homeassistant.components.camera import SUPPORT_ON_OFF
from homeassistant.components.mjpeg.camera import (
CONF_MJPEG_URL,
CONF_STILL_IMAGE_URL,
MjpegCamera,
filter_urllib3_logging,
)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
from homeassistant.components.mjpeg.camera import MjpegCamera, filter_urllib3_logging
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity import DeviceInfo
@ -70,16 +65,15 @@ class AgentCamera(MjpegCamera):
def __init__(self, device):
"""Initialize as a subclass of MjpegCamera."""
device_info = {
CONF_NAME: device.name,
CONF_MJPEG_URL: f"{device.client._server_url}{device.mjpeg_image_url}&size={device.mjpegStreamWidth}x{device.mjpegStreamHeight}",
CONF_STILL_IMAGE_URL: f"{device.client._server_url}{device.still_image_url}&size={device.mjpegStreamWidth}x{device.mjpegStreamHeight}",
}
self.device = device
self._removed = False
self._attr_name = f"{device.client.name} {device.name}"
self._attr_unique_id = f"{device._client.unique}_{device.typeID}_{device.id}"
super().__init__(device_info)
super().__init__(
name=device.name,
mjpeg_url=f"{device.client._server_url}{device.mjpeg_image_url}&size={device.mjpegStreamWidth}x{device.mjpegStreamHeight}",
still_image_url=f"{device.client._server_url}{device.still_image_url}&size={device.mjpegStreamWidth}x{device.mjpegStreamHeight}",
)
self._attr_device_info = DeviceInfo(
identifiers={(AGENT_DOMAIN, self.unique_id)},
manufacturer="Agent",

View File

@ -2,20 +2,9 @@
from urllib.parse import urlencode
from homeassistant.components.camera import SUPPORT_STREAM
from homeassistant.components.mjpeg.camera import (
CONF_MJPEG_URL,
CONF_STILL_IMAGE_URL,
MjpegCamera,
filter_urllib3_logging,
)
from homeassistant.components.mjpeg.camera import MjpegCamera, filter_urllib3_logging
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_AUTHENTICATION,
CONF_NAME,
CONF_PASSWORD,
CONF_USERNAME,
HTTP_DIGEST_AUTHENTICATION,
)
from homeassistant.const import HTTP_DIGEST_AUTHENTICATION
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -47,15 +36,15 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
"""Initialize Axis Communications camera component."""
AxisEntityBase.__init__(self, device)
config = {
CONF_NAME: device.name,
CONF_USERNAME: device.username,
CONF_PASSWORD: device.password,
CONF_MJPEG_URL: self.mjpeg_source,
CONF_STILL_IMAGE_URL: self.image_source,
CONF_AUTHENTICATION: HTTP_DIGEST_AUTHENTICATION,
}
MjpegCamera.__init__(self, config)
MjpegCamera.__init__(
self,
name=device.name,
username=device.username,
password=device.password,
mjpeg_url=self.mjpeg_source,
still_image_url=self.image_source,
authentication=HTTP_DIGEST_AUTHENTICATION,
)
self._attr_unique_id = f"{device.unique_id}-camera"

View File

@ -49,7 +49,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
[HTTP_BASIC_AUTHENTICATION, HTTP_DIGEST_AUTHENTICATION]
),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PASSWORD): cv.string,
vol.Optional(CONF_PASSWORD, default=""): cv.string,
vol.Optional(CONF_USERNAME): cv.string,
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
}
@ -71,13 +71,13 @@ async def async_setup_platform(
async_add_entities(
[
MjpegCamera(
config[CONF_NAME],
config[CONF_AUTHENTICATION],
config.get(CONF_USERNAME),
config.get(CONF_PASSWORD),
config[CONF_MJPEG_URL],
config.get(CONF_STILL_IMAGE_URL),
config[CONF_VERIFY_SSL],
name=config[CONF_NAME],
authentication=config[CONF_AUTHENTICATION],
username=config.get(CONF_USERNAME),
password=config[CONF_PASSWORD],
mjpeg_url=config[CONF_MJPEG_URL],
still_image_url=config.get(CONF_STILL_IMAGE_URL),
verify_ssl=config[CONF_VERIFY_SSL],
)
]
)
@ -116,13 +116,14 @@ class MjpegCamera(Camera):
def __init__(
self,
*,
name: str,
authentication: str,
username: str | None,
password: str | None,
mjpeg_url: str,
still_image_url: str | None,
verify_ssl: bool,
authentication: str | None = None,
username: str | None = None,
password: str = "",
verify_ssl: bool = True,
) -> None:
"""Initialize a MJPEG camera."""
super().__init__()

View File

@ -27,7 +27,6 @@ import voluptuous as vol
from homeassistant.components.mjpeg.camera import (
CONF_MJPEG_URL,
CONF_STILL_IMAGE_URL,
CONF_VERIFY_SSL,
MjpegCamera,
)
from homeassistant.config_entries import ConfigEntry
@ -144,6 +143,8 @@ async def async_setup_entry(
class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
"""motionEye mjpeg camera."""
_name: str
def __init__(
self,
config_entry_id: str,
@ -173,10 +174,8 @@ class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
)
MjpegCamera.__init__(
self,
{
CONF_VERIFY_SSL: False,
**self._get_mjpeg_camera_properties_for_camera(camera),
},
verify_ssl=False,
**self._get_mjpeg_camera_properties_for_camera(camera),
)
@callback
@ -207,7 +206,7 @@ class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
return {
CONF_NAME: camera[KEY_NAME],
CONF_USERNAME: self._surveillance_username if auth is not None else None,
CONF_PASSWORD: self._surveillance_password if auth is not None else None,
CONF_PASSWORD: self._surveillance_password if auth is not None else "",
CONF_MJPEG_URL: streaming_url or "",
CONF_STILL_IMAGE_URL: self._client.get_camera_snapshot_url(camera),
CONF_AUTHENTICATION: auth,
@ -227,7 +226,10 @@ class MotionEyeMjpegCamera(MotionEyeEntity, MjpegCamera):
self._still_image_url = properties[CONF_STILL_IMAGE_URL]
self._authentication = properties[CONF_AUTHENTICATION]
if self._authentication == HTTP_BASIC_AUTHENTICATION:
if (
self._authentication == HTTP_BASIC_AUTHENTICATION
and self._username is not None
):
self._auth = aiohttp.BasicAuth(self._username, password=self._password)
def _is_acceptable_streaming_camera(self) -> bool:

View File

@ -3,13 +3,7 @@ from __future__ import annotations
import logging
from homeassistant.components.mjpeg.camera import (
CONF_MJPEG_URL,
CONF_STILL_IMAGE_URL,
MjpegCamera,
filter_urllib3_logging,
)
from homeassistant.const import CONF_NAME, CONF_VERIFY_SSL
from homeassistant.components.mjpeg.camera import MjpegCamera, filter_urllib3_logging
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -44,13 +38,12 @@ class ZoneMinderCamera(MjpegCamera):
def __init__(self, monitor, verify_ssl):
"""Initialize as a subclass of MjpegCamera."""
device_info = {
CONF_NAME: monitor.name,
CONF_MJPEG_URL: monitor.mjpeg_image_url,
CONF_STILL_IMAGE_URL: monitor.still_image_url,
CONF_VERIFY_SSL: verify_ssl,
}
super().__init__(device_info)
super().__init__(
name=monitor.name,
mjpeg_url=monitor.mjpeg_image_url,
still_image_url=monitor.still_image_url,
verify_ssl=verify_ssl,
)
self._is_recording = None
self._is_available = None
self._monitor = monitor