1 """Support for Roku sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from rokuecp.models
import Device
as RokuDevice
16 from .const
import DOMAIN
17 from .coordinator
import RokuDataUpdateCoordinator
18 from .entity
import RokuEntity
21 @dataclass(frozen=True, kw_only=True)
23 """Describes Roku sensor entity."""
25 value_fn: Callable[[RokuDevice], str |
None]
28 SENSORS: tuple[RokuSensorEntityDescription, ...] = (
31 translation_key=
"active_app",
32 entity_category=EntityCategory.DIAGNOSTIC,
33 value_fn=
lambda device: device.app.name
if device.app
else None,
37 translation_key=
"active_app_id",
38 entity_category=EntityCategory.DIAGNOSTIC,
39 value_fn=
lambda device: device.app.app_id
if device.app
else None,
47 async_add_entities: AddEntitiesCallback,
49 """Set up Roku sensor based on a config entry."""
50 coordinator: RokuDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
54 coordinator=coordinator,
55 description=description,
57 for description
in SENSORS
62 """Defines a Roku sensor entity."""
64 entity_description: RokuSensorEntityDescription
68 """Return the state of the sensor."""
str|None native_value(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)