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:
@@ -44,10 +44,14 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
|
||||
CannotConnect: If connection fails
|
||||
InvalidAuth: If authentication fails
|
||||
"""
|
||||
# Token is optional: the media server can run without auth tokens, in which
|
||||
# case verify_token() returns "anonymous" and accepts unauthenticated calls.
|
||||
# If the server *does* have tokens configured, get_status() below will 401
|
||||
# and we surface that as "invalid_auth" in the UI.
|
||||
client = MediaServerClient(
|
||||
host=data[CONF_HOST],
|
||||
port=data[CONF_PORT],
|
||||
token=data[CONF_TOKEN],
|
||||
token=data.get(CONF_TOKEN, "") or "",
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -125,7 +129,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
mode=selector.NumberSelectorMode.BOX,
|
||||
)
|
||||
),
|
||||
vol.Required(CONF_TOKEN): selector.TextSelector(
|
||||
vol.Optional(CONF_TOKEN, default=""): selector.TextSelector(
|
||||
selector.TextSelectorConfig(
|
||||
type=selector.TextSelectorType.PASSWORD
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user