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/logger/*
- homeassistant/components/lovelace/* - homeassistant/components/lovelace/*
- homeassistant/components/media_source/* - homeassistant/components/media_source/*
- homeassistant/components/mjpeg/*
- homeassistant/components/mqtt/* - homeassistant/components/mqtt/*
- homeassistant/components/network/* - homeassistant/components/network/*
- homeassistant/components/onboarding/* - homeassistant/components/onboarding/*

View File

@ -5,13 +5,8 @@ import logging
from agent import AgentError from agent import AgentError
from homeassistant.components.camera import SUPPORT_ON_OFF from homeassistant.components.camera import SUPPORT_ON_OFF
from homeassistant.components.mjpeg.camera import ( from homeassistant.components.mjpeg.camera import MjpegCamera, filter_urllib3_logging
CONF_MJPEG_URL, from homeassistant.const import ATTR_ATTRIBUTION
CONF_STILL_IMAGE_URL,
MjpegCamera,
filter_urllib3_logging,
)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
from homeassistant.helpers import entity_platform from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
@ -70,16 +65,15 @@ class AgentCamera(MjpegCamera):
def __init__(self, device): def __init__(self, device):
"""Initialize as a subclass of MjpegCamera.""" """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.device = device
self._removed = False self._removed = False
self._attr_name = f"{device.client.name} {device.name}" self._attr_name = f"{device.client.name} {device.name}"
self._attr_unique_id = f"{device._client.unique}_{device.typeID}_{device.id}" 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( self._attr_device_info = DeviceInfo(
identifiers={(AGENT_DOMAIN, self.unique_id)}, identifiers={(AGENT_DOMAIN, self.unique_id)},
manufacturer="Agent", manufacturer="Agent",

View File

@ -2,20 +2,9 @@
from urllib.parse import urlencode from urllib.parse import urlencode
from homeassistant.components.camera import SUPPORT_STREAM from homeassistant.components.camera import SUPPORT_STREAM
from homeassistant.components.mjpeg.camera import ( from homeassistant.components.mjpeg.camera import MjpegCamera, filter_urllib3_logging
CONF_MJPEG_URL,
CONF_STILL_IMAGE_URL,
MjpegCamera,
filter_urllib3_logging,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import HTTP_DIGEST_AUTHENTICATION
CONF_AUTHENTICATION,
CONF_NAME,
CONF_PASSWORD,
CONF_USERNAME,
HTTP_DIGEST_AUTHENTICATION,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -47,15 +36,15 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
"""Initialize Axis Communications camera component.""" """Initialize Axis Communications camera component."""
AxisEntityBase.__init__(self, device) AxisEntityBase.__init__(self, device)
config = { MjpegCamera.__init__(
CONF_NAME: device.name, self,
CONF_USERNAME: device.username, name=device.name,
CONF_PASSWORD: device.password, username=device.username,
CONF_MJPEG_URL: self.mjpeg_source, password=device.password,
CONF_STILL_IMAGE_URL: self.image_source, mjpeg_url=self.mjpeg_source,
CONF_AUTHENTICATION: HTTP_DIGEST_AUTHENTICATION, still_image_url=self.image_source,
} authentication=HTTP_DIGEST_AUTHENTICATION,
MjpegCamera.__init__(self, config) )
self._attr_unique_id = f"{device.unique_id}-camera" 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] [HTTP_BASIC_AUTHENTICATION, HTTP_DIGEST_AUTHENTICATION]
), ),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, 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_USERNAME): cv.string,
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean, vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
} }
@ -71,13 +71,13 @@ async def async_setup_platform(
async_add_entities( async_add_entities(
[ [
MjpegCamera( MjpegCamera(
config[CONF_NAME], name=config[CONF_NAME],
config[CONF_AUTHENTICATION], authentication=config[CONF_AUTHENTICATION],
config.get(CONF_USERNAME), username=config.get(CONF_USERNAME),
config.get(CONF_PASSWORD), password=config[CONF_PASSWORD],
config[CONF_MJPEG_URL], mjpeg_url=config[CONF_MJPEG_URL],
config.get(CONF_STILL_IMAGE_URL), still_image_url=config.get(CONF_STILL_IMAGE_URL),
config[CONF_VERIFY_SSL], verify_ssl=config[CONF_VERIFY_SSL],
) )
] ]
) )
@ -116,13 +116,14 @@ class MjpegCamera(Camera):
def __init__( def __init__(
self, self,
*,
name: str, name: str,
authentication: str,
username: str | None,
password: str | None,
mjpeg_url: str, mjpeg_url: str,
still_image_url: str | None, still_image_url: str | None,
verify_ssl: bool, authentication: str | None = None,
username: str | None = None,
password: str = "",
verify_ssl: bool = True,
) -> None: ) -> None:
"""Initialize a MJPEG camera.""" """Initialize a MJPEG camera."""
super().__init__() super().__init__()

View File

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

View File

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