1 """Tedee sensor entities."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
6 from aiotedee
import TedeeLock
7 from aiotedee.lock
import TedeeLockState
10 BinarySensorDeviceClass,
12 BinarySensorEntityDescription,
18 from .coordinator
import TedeeConfigEntry
19 from .entity
import TedeeDescriptionEntity
22 @dataclass(frozen=True, kw_only=True)
24 BinarySensorEntityDescription,
26 """Describes Tedee binary sensor entity."""
28 is_on_fn: Callable[[TedeeLock], bool |
None]
31 ENTITIES: tuple[TedeeBinarySensorEntityDescription, ...] = (
34 device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
35 is_on_fn=
lambda lock: lock.is_charging,
36 entity_category=EntityCategory.DIAGNOSTIC,
40 translation_key=
"semi_locked",
41 is_on_fn=
lambda lock: lock.state == TedeeLockState.HALF_OPEN,
42 entity_category=EntityCategory.DIAGNOSTIC,
45 key=
"pullspring_enabled",
46 translation_key=
"pullspring_enabled",
47 is_on_fn=
lambda lock: lock.is_enabled_pullspring,
48 entity_category=EntityCategory.DIAGNOSTIC,
52 translation_key=
"uncalibrated",
53 is_on_fn=
lambda lock: lock.state == TedeeLockState.UNCALIBRATED,
54 device_class=BinarySensorDeviceClass.PROBLEM,
55 entity_category=EntityCategory.DIAGNOSTIC,
56 entity_registry_enabled_default=
False,
63 entry: TedeeConfigEntry,
64 async_add_entities: AddEntitiesCallback,
66 """Set up the Tedee sensor entity."""
67 coordinator = entry.runtime_data
71 for lock
in coordinator.data.values()
72 for entity_description
in ENTITIES
75 def _async_add_new_lock(lock_id: int) ->
None:
76 lock = coordinator.data[lock_id]
79 for entity_description
in ENTITIES
82 coordinator.new_lock_callbacks.append(_async_add_new_lock)
86 """Tedee sensor entity."""
88 entity_description: TedeeBinarySensorEntityDescription
92 """Return true if the binary sensor is on."""
None async_setup_entry(HomeAssistant hass, TedeeConfigEntry entry, AddEntitiesCallback async_add_entities)