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