mirror of
https://github.com/home-assistant/core.git
synced 2025-11-16 22:40:44 +00:00
Add go2rtc and extend camera integration for better WebRTC support (#124410)
This commit is contained in:
28
homeassistant/components/camera/helper.py
Normal file
28
homeassistant/components/camera/helper.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Camera helper functions."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
from .const import DATA_COMPONENT
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import Camera
|
||||
|
||||
|
||||
def get_camera_from_entity_id(hass: HomeAssistant, entity_id: str) -> Camera:
|
||||
"""Get camera component from entity_id."""
|
||||
component = hass.data.get(DATA_COMPONENT)
|
||||
if component is None:
|
||||
raise HomeAssistantError("Camera integration not set up")
|
||||
|
||||
if (camera := component.get_entity(entity_id)) is None:
|
||||
raise HomeAssistantError("Camera not found")
|
||||
|
||||
if not camera.is_on:
|
||||
raise HomeAssistantError("Camera is off")
|
||||
|
||||
return camera
|
||||
Reference in New Issue
Block a user