feat: shared DisplayCoordinator + optional API token
- Introduce DisplayCoordinator polling /api/display/monitors once per cycle and fan out to all per-display entities via CoordinatorEntity. Removes ~9x redundant requests per polling cycle that came from each binary_sensor/number/select/sensor/switch entity calling get_display_monitors() in its own async_update. - Optimistic write-through via coordinator.apply_optimistic(...) keeps sibling entities in sync after slider/select writes without an extra network round-trip. - Make CONF_TOKEN optional. The media server already supports running without auth (auth_enabled() returns False when api_tokens is empty), so the integration omits the Authorization header and ?token= query from REST/WS/album-art URLs when no token is configured. Server-side auth-enabled rejections still surface as invalid_auth in the UI. - Bump manifest version to 0.3.2. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,7 @@ from .const import (
|
||||
SERVICE_EXECUTE_SCRIPT,
|
||||
SERVICE_PLAY_MEDIA_FILE,
|
||||
)
|
||||
from .display_coordinator import DisplayCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -78,10 +79,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
await client.close()
|
||||
return False
|
||||
|
||||
# Create the shared display coordinator BEFORE platform setup so each
|
||||
# display platform's async_setup_entry can register against the same
|
||||
# data source instead of polling /api/display/monitors on its own.
|
||||
display_coordinator = DisplayCoordinator(hass, client)
|
||||
try:
|
||||
await display_coordinator.async_config_entry_first_refresh()
|
||||
except Exception as err: # noqa: BLE001 - first refresh wraps its own errors
|
||||
_LOGGER.warning("Initial display monitor fetch failed, will retry: %s", err)
|
||||
|
||||
# Store client in hass.data
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = {
|
||||
"client": client,
|
||||
"display_coordinator": display_coordinator,
|
||||
}
|
||||
|
||||
# Register services if not already registered
|
||||
|
||||
Reference in New Issue
Block a user