1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

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):
"""Execute a get camera stream command."""
url = await self.hass.components.camera.async_request_stream(
self.state.entity_id, "hls"
)
url = await camera.async_request_stream(self.hass, self.state.entity_id, "hls")
self.stream_info = {
"cameraStreamAccessUrl": f"{get_url(self.hass)}{url}",
"cameraStreamReceiverAppId": CAST_APP_ID_HOMEASSISTANT_MEDIA,

View File

@ -11,6 +11,7 @@ from pyhap.camera import (
)
from pyhap.const import CATEGORY_CAMERA
from homeassistant.components import camera
from homeassistant.components.ffmpeg import get_ffmpeg_manager
from homeassistant.const import STATE_ON
from homeassistant.core import callback
@ -317,8 +318,8 @@ class Camera(HomeAccessory, PyhapCamera):
if stream_source := self.config.get(CONF_STREAM_SOURCE):
return stream_source
try:
stream_source = await self.hass.components.camera.async_get_stream_source(
self.entity_id
stream_source = await camera.async_get_stream_source(
self.hass, self.entity_id
)
except Exception: # pylint: disable=broad-except
_LOGGER.exception(
@ -471,7 +472,8 @@ class Camera(HomeAccessory, PyhapCamera):
async def async_get_snapshot(self, image_size):
"""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,
width=image_size["image-width"],
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
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 (
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})
async def webhook_stream_camera(hass, config_entry, data):
"""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(
{"success": False},
registration=config_entry.data,
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:
resp["hls_path"] = await hass.components.camera.async_request_stream(
camera.entity_id, "hls"
resp["hls_path"] = await camera.async_request_stream(
hass, camera_state.entity_id, "hls"
)
except HomeAssistantError:
resp["hls_path"] = None