feat(foreground): foreground process sensors + translation key migration

Adds Home Assistant entities for the foreground-process feature shipped
in the media server, plus migrates existing display entities to use HA
translation keys (strings.json / translations/*) so per-language UI text
flows through the standard locale mechanism.

Foreground entities (all share one HA "Foreground" device linked to the
hub via via_device):
- sensor.foreground_process — process name as state + full payload
  (pid, exec path, window title, fullscreen flag, monitor, geometry,
  is_browser, browser_page_title, browser_url, error) as attributes
- sensor.window_title, sensor.pid, sensor.foreground_monitor,
  sensor.process_started (TIMESTAMP device class)
- binary_sensor.fullscreen, binary_sensor.minimized

Data flow:
- ForegroundCoordinator polls GET /api/foreground every 5s (HTTP fallback)
- media_player's WebSocket receiver forwards `foreground` /
  `foreground_update` push frames into the coordinator via
  apply_websocket_snapshot, so sensors update in near-real-time when WS
  is connected and fall back to polling otherwise

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-05-18 03:13:23 +03:00
parent ab0585278c
commit 9d277276b8
14 changed files with 463 additions and 32 deletions
@@ -25,6 +25,7 @@ from .const import (
SERVICE_PLAY_MEDIA_FILE,
)
from .display_coordinator import DisplayCoordinator
from .foreground_coordinator import ForegroundCoordinator
_LOGGER = logging.getLogger(__name__)
@@ -88,11 +89,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except Exception as err: # noqa: BLE001 - first refresh wraps its own errors
_LOGGER.warning("Initial display monitor fetch failed, will retry: %s", err)
# Foreground coordinator — shared by sensor + binary_sensor platforms and
# nudged by the media-player WebSocket receiver when it gets a push.
foreground_coordinator = ForegroundCoordinator(hass, client)
try:
await foreground_coordinator.async_config_entry_first_refresh()
except Exception as err: # noqa: BLE001
_LOGGER.warning("Initial foreground 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,
"foreground_coordinator": foreground_coordinator,
}
# Register services if not already registered