1 """Tedee sensor entities."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
6 from aiotedee
import TedeeLock
11 SensorEntityDescription,
18 from .coordinator
import TedeeConfigEntry
19 from .entity
import TedeeDescriptionEntity
22 @dataclass(frozen=True, kw_only=True)
24 """Describes Tedee sensor entity."""
26 value_fn: Callable[[TedeeLock], float |
None]
29 ENTITIES: tuple[TedeeSensorEntityDescription, ...] = (
32 device_class=SensorDeviceClass.BATTERY,
33 native_unit_of_measurement=PERCENTAGE,
34 state_class=SensorStateClass.MEASUREMENT,
35 value_fn=
lambda lock: lock.battery_level,
36 entity_category=EntityCategory.DIAGNOSTIC,
39 key=
"pullspring_duration",
40 translation_key=
"pullspring_duration",
41 device_class=SensorDeviceClass.DURATION,
42 native_unit_of_measurement=UnitOfTime.SECONDS,
43 state_class=SensorStateClass.MEASUREMENT,
44 value_fn=
lambda lock: lock.duration_pullspring,
45 entity_category=EntityCategory.DIAGNOSTIC,
52 entry: TedeeConfigEntry,
53 async_add_entities: AddEntitiesCallback,
55 """Set up the Tedee sensor entity."""
56 coordinator = entry.runtime_data
60 for lock
in coordinator.data.values()
61 for entity_description
in ENTITIES
64 def _async_add_new_lock(lock_id: int) ->
None:
65 lock = coordinator.data[lock_id]
68 for entity_description
in ENTITIES
71 coordinator.new_lock_callbacks.append(_async_add_new_lock)
75 """Tedee sensor entity."""
77 entity_description: TedeeSensorEntityDescription
81 """Return the state of the sensor."""
float|None native_value(self)
None async_setup_entry(HomeAssistant hass, TedeeConfigEntry entry, AddEntitiesCallback async_add_entities)