Import camera (#64540)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2022-01-20 13:07:05 +01:00 committed by GitHub
parent dbc6e41264
commit f083b97f9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View File

@ -304,9 +304,7 @@ class CameraStreamTrait(_Trait):
async def execute(self, command, data, params, challenge): async def execute(self, command, data, params, challenge):
"""Execute a get camera stream command.""" """Execute a get camera stream command."""
url = await self.hass.components.camera.async_request_stream( url = await camera.async_request_stream(self.hass, self.state.entity_id, "hls")
self.state.entity_id, "hls"
)
self.stream_info = { self.stream_info = {
"cameraStreamAccessUrl": f"{get_url(self.hass)}{url}", "cameraStreamAccessUrl": f"{get_url(self.hass)}{url}",
"cameraStreamReceiverAppId": CAST_APP_ID_HOMEASSISTANT_MEDIA, "cameraStreamReceiverAppId": CAST_APP_ID_HOMEASSISTANT_MEDIA,

View File

@ -11,6 +11,7 @@ from pyhap.camera import (
) )
from pyhap.const import CATEGORY_CAMERA from pyhap.const import CATEGORY_CAMERA
from homeassistant.components import camera
from homeassistant.components.ffmpeg import get_ffmpeg_manager from homeassistant.components.ffmpeg import get_ffmpeg_manager
from homeassistant.const import STATE_ON from homeassistant.const import STATE_ON
from homeassistant.core import callback from homeassistant.core import callback
@ -317,8 +318,8 @@ class Camera(HomeAccessory, PyhapCamera):
if stream_source := self.config.get(CONF_STREAM_SOURCE): if stream_source := self.config.get(CONF_STREAM_SOURCE):
return stream_source return stream_source
try: try:
stream_source = await self.hass.components.camera.async_get_stream_source( stream_source = await camera.async_get_stream_source(
self.entity_id self.hass, self.entity_id
) )
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
_LOGGER.exception( _LOGGER.exception(
@ -471,7 +472,8 @@ class Camera(HomeAccessory, PyhapCamera):
async def async_get_snapshot(self, image_size): async def async_get_snapshot(self, image_size):
"""Return a jpeg of a snapshot from the camera.""" """Return a jpeg of a snapshot from the camera."""
image = await self.hass.components.camera.async_get_image( image = await camera.async_get_image(
self.hass,
self.entity_id, self.entity_id,
width=image_size["image-width"], width=image_size["image-width"],
height=image_size["image-height"], height=image_size["image-height"],

View File

@ -10,7 +10,7 @@ from aiohttp.web import HTTPBadRequest, Request, Response, json_response
from nacl.secret import SecretBox from nacl.secret import SecretBox
import voluptuous as vol import voluptuous as vol
from homeassistant.components import cloud, notify as hass_notify, tag from homeassistant.components import camera, cloud, notify as hass_notify, tag
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASSES as BINARY_SENSOR_CLASSES, DEVICE_CLASSES as BINARY_SENSOR_CLASSES,
) )
@ -265,19 +265,19 @@ async def webhook_fire_event(hass, config_entry, data):
@validate_schema({vol.Required(ATTR_CAMERA_ENTITY_ID): cv.string}) @validate_schema({vol.Required(ATTR_CAMERA_ENTITY_ID): cv.string})
async def webhook_stream_camera(hass, config_entry, data): async def webhook_stream_camera(hass, config_entry, data):
"""Handle a request to HLS-stream a camera.""" """Handle a request to HLS-stream a camera."""
if (camera := hass.states.get(data[ATTR_CAMERA_ENTITY_ID])) is None: if (camera_state := hass.states.get(data[ATTR_CAMERA_ENTITY_ID])) is None:
return webhook_response( return webhook_response(
{"success": False}, {"success": False},
registration=config_entry.data, registration=config_entry.data,
status=HTTPStatus.BAD_REQUEST, status=HTTPStatus.BAD_REQUEST,
) )
resp = {"mjpeg_path": f"/api/camera_proxy_stream/{camera.entity_id}"} resp = {"mjpeg_path": f"/api/camera_proxy_stream/{camera_state.entity_id}"}
if camera.attributes[ATTR_SUPPORTED_FEATURES] & CAMERA_SUPPORT_STREAM: if camera_state.attributes[ATTR_SUPPORTED_FEATURES] & CAMERA_SUPPORT_STREAM:
try: try:
resp["hls_path"] = await hass.components.camera.async_request_stream( resp["hls_path"] = await camera.async_request_stream(
camera.entity_id, "hls" hass, camera_state.entity_id, "hls"
) )
except HomeAssistantError: except HomeAssistantError:
resp["hls_path"] = None resp["hls_path"] = None