feat: server telemetry, update entity, sync-clock controls

- Server device exposing CPU/RAM/GPU/temperature/battery sensors via
  /api/v1/system/performance, plus last-restart timestamp (cached with
  jitter threshold so the recorder doesn't see poll wobble) and version.
- Update entity backed by /api/v1/system/update — installs via
  /apply, hides the install button when the server reports
  can_auto_update=false.
- Sync-clock entities: reset button, speed number, running switch, and
  the event listener now refreshes on entity_changed events too.
- Bump manifest to 0.4.0.
This commit is contained in:
2026-04-27 01:35:42 +03:00
parent e8f2b5e528
commit a666d9eb9c
12 changed files with 1080 additions and 23 deletions
+58 -1
View File
@@ -25,13 +25,19 @@ async def async_setup_entry(
data = hass.data[DOMAIN][entry.entry_id]
coordinator: LedGrabCoordinator = data[DATA_COORDINATOR]
entities = []
entities: list[SwitchEntity] = []
if coordinator.data and "targets" in coordinator.data:
for target_id, target_data in coordinator.data["targets"].items():
entities.append(
LedGrabSwitch(coordinator, target_id, entry.entry_id)
)
if coordinator.data:
for clock in coordinator.data.get("sync_clocks", []):
entities.append(
LedGrabSyncClockSwitch(coordinator, clock["id"], entry.entry_id)
)
async_add_entities(entities)
@@ -107,3 +113,54 @@ class LedGrabSwitch(CoordinatorEntity, SwitchEntity):
if not self.coordinator.data:
return None
return self.coordinator.data.get("targets", {}).get(self._target_id)
class LedGrabSyncClockSwitch(CoordinatorEntity, SwitchEntity):
"""Running/paused control for a sync clock.
On = clock running (linked animations advance), off = paused (frozen).
"""
_attr_has_entity_name = True
_attr_icon = "mdi:clock-outline"
def __init__(
self,
coordinator: LedGrabCoordinator,
clock_id: str,
entry_id: str,
) -> None:
super().__init__(coordinator)
self._clock_id = clock_id
self._entry_id = entry_id
self._attr_unique_id = f"{clock_id}_running"
self._attr_translation_key = "sync_clock_running"
@property
def device_info(self) -> dict[str, Any]:
return {"identifiers": {(DOMAIN, self._clock_id)}}
@property
def is_on(self) -> bool:
clock = self._get_clock()
if not clock:
return False
return bool(clock.get("is_running", False))
@property
def available(self) -> bool:
return self._get_clock() is not None
async def async_turn_on(self, **kwargs: Any) -> None:
await self.coordinator.resume_sync_clock(self._clock_id)
async def async_turn_off(self, **kwargs: Any) -> None:
await self.coordinator.pause_sync_clock(self._clock_id)
def _get_clock(self) -> dict[str, Any] | None:
if not self.coordinator.data:
return None
for clock in self.coordinator.data.get("sync_clocks", []):
if clock.get("id") == self._clock_id:
return clock
return None