"""Shared helpers for daemon handlers.""" from typing import Any from daemon.server import refresh_state from lib.sync import SyncEvent, bus def emit_and_refresh( subsystem: str, payload: dict[str, Any] | None = None ) -> list[str]: """Emit a ``config_saved`` sync event and refresh the affected state. All mutation handlers end with the same tail: emit the event, refresh the source subsystem plus every subsystem the sync touched. Args: subsystem: Source subsystem name. payload: Event payload (e.g. ``{"action": "zone_created"}``). Returns: Subsystems affected by the sync event. """ sync_result = bus.emit(SyncEvent(subsystem, "config_saved", payload or {})) refresh_state([subsystem, *sync_result.affected_subsystems]) return sync_result.affected_subsystems