"""In-memory state controller'а.""" from __future__ import annotations import asyncio from dataclasses import dataclass, field @dataclass class InstanceState: name: str active_layout: str # Future: fps_out, dropped_frames, motion_cameras, last_event_ts @dataclass class ControllerState: instances: dict[str, InstanceState] = field(default_factory=dict) _lock: asyncio.Lock = field(default_factory=asyncio.Lock) async def set_layout(self, instance: str, layout: str) -> None: async with self._lock: st = self.instances.get(instance) if st is None: st = InstanceState(name=instance, active_layout=layout) self.instances[instance] = st else: st.active_layout = layout async def get_layout(self, instance: str) -> str | None: async with self._lock: st = self.instances.get(instance) return st.active_layout if st else None