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
+22 -13
View File
@@ -15,6 +15,8 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN
from .display_coordinator import DisplayCoordinator
from .display_device import display_device_info
from .foreground import FOREGROUND_SENSORS
from .foreground_coordinator import ForegroundCoordinator
_LOGGER = logging.getLogger(__name__)
@@ -24,30 +26,37 @@ async def async_setup_entry(
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up per-display sensor entities."""
coordinator: DisplayCoordinator = hass.data[DOMAIN][entry.entry_id][
"display_coordinator"
]
"""Set up display + foreground sensor entities."""
store = hass.data[DOMAIN][entry.entry_id]
display_coordinator: DisplayCoordinator = store["display_coordinator"]
foreground_coordinator: ForegroundCoordinator | None = store.get(
"foreground_coordinator"
)
if not coordinator.data:
return
entities: list[Any] = []
entities = [
DisplayResolutionSensor(coordinator, entry, monitor)
for monitor in coordinator.data.values()
if monitor.get("resolution")
]
if display_coordinator.data:
entities.extend(
DisplayResolutionSensor(display_coordinator, entry, monitor)
for monitor in display_coordinator.data.values()
if monitor.get("resolution")
)
if foreground_coordinator is not None:
entities.extend(
cls(foreground_coordinator, entry) for cls in FOREGROUND_SENSORS
)
if entities:
async_add_entities(entities)
_LOGGER.info("Added %d display sensor entities", len(entities))
_LOGGER.info("Added %d sensor entities (display + foreground)", len(entities))
class DisplayResolutionSensor(CoordinatorEntity[DisplayCoordinator], SensorEntity):
"""Diagnostic sensor reporting the EDID-derived display resolution."""
_attr_has_entity_name = True
_attr_name = "Resolution"
_attr_translation_key = "resolution"
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:monitor-screenshot"