mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Use HassKey in camera (#126331)
This commit is contained in:
parent
1b4ba68e18
commit
37d527bd08
@ -373,9 +373,7 @@ def _async_get_rtsp_to_web_rtc_providers(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
) -> Iterable[RtspToWebRtcProviderType]:
|
) -> Iterable[RtspToWebRtcProviderType]:
|
||||||
"""Return registered RTSP to WebRTC providers."""
|
"""Return registered RTSP to WebRTC providers."""
|
||||||
providers: dict[str, RtspToWebRtcProviderType] = hass.data.get(
|
providers = hass.data.get(DATA_RTSP_TO_WEB_RTC, {})
|
||||||
DATA_RTSP_TO_WEB_RTC, {}
|
|
||||||
)
|
|
||||||
return providers.values()
|
return providers.values()
|
||||||
|
|
||||||
|
|
||||||
@ -952,8 +950,9 @@ async def websocket_get_prefs(
|
|||||||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle request for account info."""
|
"""Handle request for account info."""
|
||||||
prefs: CameraPreferences = hass.data[DATA_CAMERA_PREFS]
|
stream_prefs = await hass.data[DATA_CAMERA_PREFS].get_dynamic_stream_settings(
|
||||||
stream_prefs = await prefs.get_dynamic_stream_settings(msg["entity_id"])
|
msg["entity_id"]
|
||||||
|
)
|
||||||
connection.send_result(msg["id"], asdict(stream_prefs))
|
connection.send_result(msg["id"], asdict(stream_prefs))
|
||||||
|
|
||||||
|
|
||||||
@ -970,14 +969,14 @@ async def websocket_update_prefs(
|
|||||||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle request for account info."""
|
"""Handle request for account info."""
|
||||||
prefs: CameraPreferences = hass.data[DATA_CAMERA_PREFS]
|
|
||||||
|
|
||||||
changes = dict(msg)
|
changes = dict(msg)
|
||||||
changes.pop("id")
|
changes.pop("id")
|
||||||
changes.pop("type")
|
changes.pop("type")
|
||||||
entity_id = changes.pop("entity_id")
|
entity_id = changes.pop("entity_id")
|
||||||
try:
|
try:
|
||||||
entity_prefs = await prefs.async_update(entity_id, **changes)
|
entity_prefs = await hass.data[DATA_CAMERA_PREFS].async_update(
|
||||||
|
entity_id, **changes
|
||||||
|
)
|
||||||
except HomeAssistantError as ex:
|
except HomeAssistantError as ex:
|
||||||
_LOGGER.error("Error setting camera preferences: %s", ex)
|
_LOGGER.error("Error setting camera preferences: %s", ex)
|
||||||
connection.send_error(msg["id"], "update_failed", str(ex))
|
connection.send_error(msg["id"], "update_failed", str(ex))
|
||||||
|
@ -17,13 +17,16 @@ from homeassistant.util.hass_dict import HassKey
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
|
||||||
from . import Camera
|
from . import Camera, RtspToWebRtcProviderType
|
||||||
|
from .prefs import CameraPreferences
|
||||||
|
|
||||||
DOMAIN: Final = "camera"
|
DOMAIN: Final = "camera"
|
||||||
DOMAIN_DATA: HassKey[EntityComponent[Camera]] = HassKey(DOMAIN)
|
DOMAIN_DATA: HassKey[EntityComponent[Camera]] = HassKey(DOMAIN)
|
||||||
|
|
||||||
DATA_CAMERA_PREFS: Final = "camera_prefs"
|
DATA_CAMERA_PREFS: HassKey[CameraPreferences] = HassKey("camera_prefs")
|
||||||
DATA_RTSP_TO_WEB_RTC: Final = "rtsp_to_web_rtc"
|
DATA_RTSP_TO_WEB_RTC: HassKey[dict[str, RtspToWebRtcProviderType]] = HassKey(
|
||||||
|
"rtsp_to_web_rtc"
|
||||||
|
)
|
||||||
|
|
||||||
PREF_PRELOAD_STREAM: Final = "preload_stream"
|
PREF_PRELOAD_STREAM: Final = "preload_stream"
|
||||||
PREF_ORIENTATION: Final = "orientation"
|
PREF_ORIENTATION: Final = "orientation"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user