|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from dataclasses import asdict |
3 | 4 | from typing import Any |
4 | 5 |
|
5 | 6 | from homeassistant.components.sensor import ( |
@@ -106,6 +107,7 @@ async def async_setup_entry( |
106 | 107 | NovastarTempStatusSensor(entry, coordinator, device_info), |
107 | 108 | NovastarDeviceStatusSensor(entry, coordinator, device_info), |
108 | 109 | NovastarSignalStatusSensor(entry, coordinator, device_info), |
| 110 | + NovastarScreensSensor(entry, coordinator, device_info), |
109 | 111 | NovastarInputsSensor(entry, coordinator, device_info), |
110 | 112 | NovastarLayersSensor(entry, coordinator, device_info), |
111 | 113 | NovastarActiveLayerCountSensor(entry, coordinator, device_info), |
@@ -282,6 +284,66 @@ def native_value(self) -> str | None: |
282 | 284 | return None |
283 | 285 |
|
284 | 286 |
|
| 287 | +class NovastarScreensSensor(CoordinatorEntity[NovastarCoordinator], SensorEntity): |
| 288 | + """Sensor entity summarizing discovered screens.""" |
| 289 | + |
| 290 | + _attr_has_entity_name = True |
| 291 | + _attr_name = "Screens" |
| 292 | + _attr_translation_key = "screens" |
| 293 | + |
| 294 | + def __init__( |
| 295 | + self, |
| 296 | + entry: ConfigEntry, |
| 297 | + coordinator: NovastarCoordinator, |
| 298 | + device_info: NovastarDeviceInfo, |
| 299 | + ) -> None: |
| 300 | + """Initialize the screens sensor entity.""" |
| 301 | + super().__init__(coordinator) |
| 302 | + self._entry = entry |
| 303 | + self._device_info = device_info |
| 304 | + self._attr_unique_id = f"{entry.entry_id}_screens" |
| 305 | + |
| 306 | + @property |
| 307 | + def device_info(self): |
| 308 | + """Return device info.""" |
| 309 | + model = "H Series" |
| 310 | + if self._device_info.model_id: |
| 311 | + model = f"H Series (Model {self._device_info.model_id})" |
| 312 | + return { |
| 313 | + "identifiers": {(DOMAIN, self._entry.entry_id)}, |
| 314 | + "manufacturer": "Novastar", |
| 315 | + "model": model, |
| 316 | + "name": self._entry.data.get(CONF_NAME, DEFAULT_NAME), |
| 317 | + "sw_version": self._device_info.firmware, |
| 318 | + "serial_number": self._device_info.serial, |
| 319 | + } |
| 320 | + |
| 321 | + @property |
| 322 | + def available(self) -> bool: |
| 323 | + """Return True if entity is available.""" |
| 324 | + return self.coordinator.last_update_success |
| 325 | + |
| 326 | + @property |
| 327 | + def native_value(self) -> str: |
| 328 | + """Return summary as '<total> Total'.""" |
| 329 | + if not self.coordinator.data: |
| 330 | + return "0 Total" |
| 331 | + |
| 332 | + total = len(self.coordinator.data.screens) |
| 333 | + return f"{total} Total" |
| 334 | + |
| 335 | + @property |
| 336 | + def extra_state_attributes(self) -> dict[str, Any]: |
| 337 | + """Return full screens list.""" |
| 338 | + if not self.coordinator.data: |
| 339 | + return {"screens": []} |
| 340 | + |
| 341 | + return { |
| 342 | + "screen_count": len(self.coordinator.data.screens), |
| 343 | + "screens": [asdict(screen) for screen in self.coordinator.data.screens], |
| 344 | + } |
| 345 | + |
| 346 | + |
285 | 347 | class NovastarInputsSensor(CoordinatorEntity[NovastarCoordinator], SensorEntity): |
286 | 348 | """Sensor entity summarizing discovered inputs.""" |
287 | 349 |
|
|
0 commit comments