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:
@@ -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_BINARY_SENSORS
|
||||
from .foreground_coordinator import ForegroundCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -24,22 +26,33 @@ async def async_setup_entry(
|
||||
entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up per-display binary sensor entities."""
|
||||
coordinator: DisplayCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||
"display_coordinator"
|
||||
]
|
||||
|
||||
if not coordinator.data:
|
||||
return
|
||||
"""Set up display + foreground binary sensor entities."""
|
||||
store = hass.data[DOMAIN][entry.entry_id]
|
||||
display_coordinator: DisplayCoordinator = store["display_coordinator"]
|
||||
foreground_coordinator: ForegroundCoordinator | None = store.get(
|
||||
"foreground_coordinator"
|
||||
)
|
||||
|
||||
entities: list[Any] = []
|
||||
for monitor in coordinator.data.values():
|
||||
entities.append(DisplayPrimaryBinarySensor(coordinator, entry, monitor))
|
||||
entities.append(DisplayPowerControlBinarySensor(coordinator, entry, monitor))
|
||||
if display_coordinator.data:
|
||||
for monitor in display_coordinator.data.values():
|
||||
entities.append(
|
||||
DisplayPrimaryBinarySensor(display_coordinator, entry, monitor)
|
||||
)
|
||||
entities.append(
|
||||
DisplayPowerControlBinarySensor(display_coordinator, entry, monitor)
|
||||
)
|
||||
|
||||
if foreground_coordinator is not None:
|
||||
entities.extend(
|
||||
cls(foreground_coordinator, entry) for cls in FOREGROUND_BINARY_SENSORS
|
||||
)
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
_LOGGER.info("Added %d display binary sensor entities", len(entities))
|
||||
_LOGGER.info(
|
||||
"Added %d binary sensor entities (display + foreground)", len(entities)
|
||||
)
|
||||
|
||||
|
||||
class _DisplayBinarySensorBase(
|
||||
@@ -70,7 +83,7 @@ class _DisplayBinarySensorBase(
|
||||
class DisplayPrimaryBinarySensor(_DisplayBinarySensorBase):
|
||||
"""Indicates whether the display is the OS primary monitor."""
|
||||
|
||||
_attr_name = "Primary display"
|
||||
_attr_translation_key = "primary_display"
|
||||
_attr_icon = "mdi:monitor-star"
|
||||
|
||||
def __init__(
|
||||
@@ -90,7 +103,7 @@ class DisplayPrimaryBinarySensor(_DisplayBinarySensorBase):
|
||||
class DisplayPowerControlBinarySensor(_DisplayBinarySensorBase):
|
||||
"""Indicates whether DDC/CI power control is available for this display."""
|
||||
|
||||
_attr_name = "Power control supported"
|
||||
_attr_translation_key = "power_control_supported"
|
||||
_attr_icon = "mdi:power-plug"
|
||||
|
||||
def __init__(
|
||||
|
||||
Reference in New Issue
Block a user