1 """Support for TPLink binary sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from typing
import Final, cast
8 from kasa
import Feature
11 BinarySensorDeviceClass,
13 BinarySensorEntityDescription,
18 from .
import TPLinkConfigEntry
19 from .entity
import CoordinatedTPLinkFeatureEntity, TPLinkFeatureEntityDescription
22 @dataclass(frozen=True, kw_only=True)
24 BinarySensorEntityDescription, TPLinkFeatureEntityDescription
26 """Base class for a TPLink feature based sensor entity description."""
29 BINARY_SENSOR_DESCRIPTIONS: Final = (
32 device_class=BinarySensorDeviceClass.PROBLEM,
36 device_class=BinarySensorDeviceClass.BATTERY,
39 key=
"cloud_connection",
40 device_class=BinarySensorDeviceClass.CONNECTIVITY,
44 key=
"update_available",
45 device_class=BinarySensorDeviceClass.UPDATE,
48 key=
"temperature_warning",
51 key=
"humidity_warning",
55 device_class=BinarySensorDeviceClass.DOOR,
59 device_class=BinarySensorDeviceClass.MOISTURE,
62 key=
"motion_detected",
63 device_class=BinarySensorDeviceClass.MOTION,
67 BINARYSENSOR_DESCRIPTIONS_MAP = {desc.key: desc
for desc
in BINARY_SENSOR_DESCRIPTIONS}
72 config_entry: TPLinkConfigEntry,
73 async_add_entities: AddEntitiesCallback,
76 data = config_entry.runtime_data
77 parent_coordinator = data.parent_coordinator
78 children_coordinators = data.children_coordinators
79 device = parent_coordinator.device
81 entities = CoordinatedTPLinkFeatureEntity.entities_for_device_and_its_children(
84 coordinator=parent_coordinator,
85 feature_type=Feature.Type.BinarySensor,
86 entity_class=TPLinkBinarySensorEntity,
87 descriptions=BINARYSENSOR_DESCRIPTIONS_MAP,
88 child_coordinators=children_coordinators,
94 """Representation of a TPLink binary sensor."""
96 entity_description: TPLinkBinarySensorEntityDescription
100 """Update the entity's attributes."""
None _async_update_attrs(self)
None async_setup_entry(HomeAssistant hass, TPLinkConfigEntry config_entry, AddEntitiesCallback async_add_entities)