1 """Platform for Schlage binary_sensor integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
9 BinarySensorDeviceClass,
11 BinarySensorEntityDescription,
18 from .const
import DOMAIN
19 from .coordinator
import LockData, SchlageDataUpdateCoordinator
20 from .entity
import SchlageEntity
23 @dataclass(frozen=True, kw_only=True)
25 """Entity description for a Schlage binary_sensor."""
27 value_fn: Callable[[LockData], bool]
30 _DESCRIPTIONS: tuple[SchlageBinarySensorEntityDescription] = (
32 key=
"keypad_disabled",
33 translation_key=
"keypad_disabled",
34 device_class=BinarySensorDeviceClass.PROBLEM,
35 entity_category=EntityCategory.DIAGNOSTIC,
36 value_fn=
lambda data: data.lock.keypad_disabled(data.logs),
43 config_entry: ConfigEntry,
44 async_add_entities: AddEntitiesCallback,
46 """Set up binary_sensors based on a config entry."""
47 coordinator: SchlageDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
52 coordinator=coordinator,
53 description=description,
56 for device_id
in locks
57 for description
in _DESCRIPTIONS
61 coordinator.new_locks_callbacks.append(_add_new_locks)
65 """Schlage binary_sensor entity."""
67 entity_description: SchlageBinarySensorEntityDescription
71 coordinator: SchlageDataUpdateCoordinator,
72 description: SchlageBinarySensorEntityDescription,
75 """Initialize a SchlageBinarySensor."""
76 super().
__init__(coordinator, device_id)
82 """Return true if the binary_sensor is on."""
None __init__(self, SchlageDataUpdateCoordinator coordinator, SchlageBinarySensorEntityDescription description, str device_id)
LockData _lock_data(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None _add_new_locks(dict[str, LockData] locks)