Use HassKey in camera (#126331)

This commit is contained in:
epenet 2024-09-21 13:16:22 +02:00 committed by GitHub
parent 1b4ba68e18
commit 37d527bd08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 11 deletions

View File

@ -373,9 +373,7 @@ def _async_get_rtsp_to_web_rtc_providers(
hass: HomeAssistant,
) -> Iterable[RtspToWebRtcProviderType]:
"""Return registered RTSP to WebRTC providers."""
providers: dict[str, RtspToWebRtcProviderType] = hass.data.get(
DATA_RTSP_TO_WEB_RTC, {}
)
providers = hass.data.get(DATA_RTSP_TO_WEB_RTC, {})
return providers.values()
@ -952,8 +950,9 @@ async def websocket_get_prefs(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle request for account info."""
prefs: CameraPreferences = hass.data[DATA_CAMERA_PREFS]
stream_prefs = await prefs.get_dynamic_stream_settings(msg["entity_id"])
stream_prefs = await hass.data[DATA_CAMERA_PREFS].get_dynamic_stream_settings(
msg["entity_id"]
)
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]
) -> None:
"""Handle request for account info."""
prefs: CameraPreferences = hass.data[DATA_CAMERA_PREFS]
changes = dict(msg)
changes.pop("id")
changes.pop("type")
entity_id = changes.pop("entity_id")
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:
_LOGGER.error("Error setting camera preferences: %s", ex)
connection.send_error(msg["id"], "update_failed", str(ex))

View File

@ -17,13 +17,16 @@ from homeassistant.util.hass_dict import HassKey
if TYPE_CHECKING:
from homeassistant.helpers.entity_component import EntityComponent
from . import Camera
from . import Camera, RtspToWebRtcProviderType
from .prefs import CameraPreferences
DOMAIN: Final = "camera"
DOMAIN_DATA: HassKey[EntityComponent[Camera]] = HassKey(DOMAIN)
DATA_CAMERA_PREFS: Final = "camera_prefs"
DATA_RTSP_TO_WEB_RTC: Final = "rtsp_to_web_rtc"
DATA_CAMERA_PREFS: HassKey[CameraPreferences] = HassKey("camera_prefs")
DATA_RTSP_TO_WEB_RTC: HassKey[dict[str, RtspToWebRtcProviderType]] = HassKey(
"rtsp_to_web_rtc"
)
PREF_PRELOAD_STREAM: Final = "preload_stream"
PREF_ORIENTATION: Final = "orientation"