Optimize KC processing and add reactive HAOS state updates
- Optimize KC frame processing: downsample to 160x90 with cv2.resize before rectangle extraction, pre-compute pixel coords, vectorize smoothing with numpy arrays - Add WebSocket event stream for server state changes: processor manager fires events on start/stop, new /api/v1/events/ws endpoint streams them to connected clients - Add HAOS EventStreamListener that triggers coordinator refresh on state changes for near-instant switch updates - Reduce HAOS polling interval from 10s to 3s for fresher FPS metrics - Fix overlay button tooltips: flatten nested JSON keys in locale files to match flat dot-notation lookup used by t() function Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,8 +18,10 @@ from .const import (
|
||||
TARGET_TYPE_KEY_COLORS,
|
||||
DATA_COORDINATOR,
|
||||
DATA_WS_MANAGER,
|
||||
DATA_EVENT_LISTENER,
|
||||
)
|
||||
from .coordinator import WLEDScreenControllerCoordinator
|
||||
from .event_listener import EventStreamListener
|
||||
from .ws_manager import KeyColorsWebSocketManager
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -48,6 +50,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
ws_manager = KeyColorsWebSocketManager(hass, server_url, api_key)
|
||||
|
||||
event_listener = EventStreamListener(hass, server_url, api_key, coordinator)
|
||||
await event_listener.start()
|
||||
|
||||
# Create device entries for each target
|
||||
device_registry = dr.async_get(hass)
|
||||
if coordinator.data and "targets" in coordinator.data:
|
||||
@@ -73,6 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hass.data[DOMAIN][entry.entry_id] = {
|
||||
DATA_COORDINATOR: coordinator,
|
||||
DATA_WS_MANAGER: ws_manager,
|
||||
DATA_EVENT_LISTENER: event_listener,
|
||||
}
|
||||
|
||||
# Track target IDs to detect changes
|
||||
@@ -114,10 +120,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
ws_manager: KeyColorsWebSocketManager = hass.data[DOMAIN][entry.entry_id][
|
||||
DATA_WS_MANAGER
|
||||
]
|
||||
await ws_manager.shutdown()
|
||||
entry_data = hass.data[DOMAIN][entry.entry_id]
|
||||
await entry_data[DATA_WS_MANAGER].shutdown()
|
||||
await entry_data[DATA_EVENT_LISTENER].shutdown()
|
||||
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user