mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Only load camera prefs once (#112064)
This commit is contained in:
parent
ec4331fc19
commit
dd1ad71166
@ -391,6 +391,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
)
|
||||
|
||||
prefs = CameraPreferences(hass)
|
||||
await prefs.async_load()
|
||||
hass.data[DATA_CAMERA_PREFS] = prefs
|
||||
|
||||
hass.http.register_view(CameraImageView(component))
|
||||
|
@ -29,6 +29,8 @@ class DynamicStreamSettings:
|
||||
class CameraPreferences:
|
||||
"""Handle camera preferences."""
|
||||
|
||||
_preload_prefs: dict[str, dict[str, bool | Orientation]]
|
||||
|
||||
def __init__(self, hass: HomeAssistant) -> None:
|
||||
"""Initialize camera prefs."""
|
||||
self._hass = hass
|
||||
@ -41,6 +43,10 @@ class CameraPreferences:
|
||||
str, DynamicStreamSettings
|
||||
] = {}
|
||||
|
||||
async def async_load(self) -> None:
|
||||
"""Initialize the camera preferences."""
|
||||
self._preload_prefs = await self._store.async_load() or {}
|
||||
|
||||
async def async_update(
|
||||
self,
|
||||
entity_id: str,
|
||||
@ -63,9 +69,8 @@ class CameraPreferences:
|
||||
if preload_stream is not UNDEFINED:
|
||||
if dynamic_stream_settings:
|
||||
dynamic_stream_settings.preload_stream = preload_stream
|
||||
preload_prefs = await self._store.async_load() or {}
|
||||
preload_prefs[entity_id] = {PREF_PRELOAD_STREAM: preload_stream}
|
||||
await self._store.async_save(preload_prefs)
|
||||
self._preload_prefs[entity_id] = {PREF_PRELOAD_STREAM: preload_stream}
|
||||
await self._store.async_save(self._preload_prefs)
|
||||
|
||||
if orientation is not UNDEFINED:
|
||||
if (registry := er.async_get(self._hass)).async_get(entity_id):
|
||||
@ -91,10 +96,10 @@ class CameraPreferences:
|
||||
# Get orientation setting from entity registry
|
||||
reg_entry = er.async_get(self._hass).async_get(entity_id)
|
||||
er_prefs: Mapping = reg_entry.options.get(DOMAIN, {}) if reg_entry else {}
|
||||
preload_prefs = await self._store.async_load() or {}
|
||||
settings = DynamicStreamSettings(
|
||||
preload_stream=cast(
|
||||
bool, preload_prefs.get(entity_id, {}).get(PREF_PRELOAD_STREAM, False)
|
||||
bool,
|
||||
self._preload_prefs.get(entity_id, {}).get(PREF_PRELOAD_STREAM, False),
|
||||
),
|
||||
orientation=er_prefs.get(PREF_ORIENTATION, Orientation.NO_TRANSFORM),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user