1 """Matter binary sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from chip.clusters
import Objects
as clusters
8 from chip.clusters.Objects
import uint
9 from chip.clusters.Types
import Nullable, NullValue
10 from matter_server.client.models
import device_types
13 BinarySensorDeviceClass,
15 BinarySensorEntityDescription,
22 from .entity
import MatterEntity, MatterEntityDescription
23 from .helpers
import get_matter
24 from .models
import MatterDiscoverySchema
29 config_entry: ConfigEntry,
30 async_add_entities: AddEntitiesCallback,
32 """Set up Matter binary sensor from Config Entry."""
34 matter.register_platform_handler(Platform.BINARY_SENSOR, async_add_entities)
37 @dataclass(frozen=True)
39 BinarySensorEntityDescription, MatterEntityDescription
41 """Describe Matter binary sensor entities."""
45 """Representation of a Matter binary sensor."""
47 entity_description: MatterBinarySensorEntityDescription
51 """Update from device."""
52 value: bool | uint | int | Nullable |
None
54 if value
in (
None, NullValue):
57 value = value_convert(value)
66 platform=Platform.BINARY_SENSOR,
68 key=
"HueMotionSensor",
69 device_class=BinarySensorDeviceClass.MOTION,
70 measurement_to_ha=
lambda x: (x & 1 == 1)
if x
is not None else None,
72 entity_class=MatterBinarySensor,
73 required_attributes=(clusters.OccupancySensing.Attributes.Occupancy,),
75 product_name=(
"Hue motion sensor",),
78 platform=Platform.BINARY_SENSOR,
80 key=
"OccupancySensor",
81 device_class=BinarySensorDeviceClass.OCCUPANCY,
83 measurement_to_ha=
lambda x: (x & 1 == 1)
if x
is not None else None,
85 entity_class=MatterBinarySensor,
86 required_attributes=(clusters.OccupancySensing.Attributes.Occupancy,),
89 platform=Platform.BINARY_SENSOR,
91 key=
"BatteryChargeLevel",
92 device_class=BinarySensorDeviceClass.BATTERY,
93 entity_category=EntityCategory.DIAGNOSTIC,
94 measurement_to_ha=
lambda x: x
95 != clusters.PowerSource.Enums.BatChargeLevelEnum.kOk,
97 entity_class=MatterBinarySensor,
98 required_attributes=(clusters.PowerSource.Attributes.BatChargeLevel,),
100 absent_attributes=(clusters.PowerSource.Attributes.BatPercentRemaining,),
104 platform=Platform.BINARY_SENSOR,
107 device_class=BinarySensorDeviceClass.DOOR,
109 measurement_to_ha=
lambda x:
not x,
111 entity_class=MatterBinarySensor,
112 required_attributes=(clusters.BooleanState.Attributes.StateValue,),
113 device_type=(device_types.ContactSensor,),
116 platform=Platform.BINARY_SENSOR,
118 key=
"WaterLeakDetector",
119 translation_key=
"water_leak",
120 device_class=BinarySensorDeviceClass.MOISTURE,
122 entity_class=MatterBinarySensor,
123 required_attributes=(clusters.BooleanState.Attributes.StateValue,),
124 device_type=(device_types.WaterLeakDetector,),
127 platform=Platform.BINARY_SENSOR,
129 key=
"WaterFreezeDetector",
130 translation_key=
"water_freeze",
131 device_class=BinarySensorDeviceClass.COLD,
133 entity_class=MatterBinarySensor,
134 required_attributes=(clusters.BooleanState.Attributes.StateValue,),
135 device_type=(device_types.WaterFreezeDetector,),
138 platform=Platform.BINARY_SENSOR,
141 translation_key=
"rain",
142 device_class=BinarySensorDeviceClass.MOISTURE,
144 entity_class=MatterBinarySensor,
145 required_attributes=(clusters.BooleanState.Attributes.StateValue,),
146 device_type=(device_types.RainSensor,),
149 platform=Platform.BINARY_SENSOR,
151 key=
"LockDoorStateSensor",
152 device_class=BinarySensorDeviceClass.DOOR,
154 clusters.DoorLock.Enums.DoorStateEnum.kDoorOpen:
True,
155 clusters.DoorLock.Enums.DoorStateEnum.kDoorJammed:
True,
156 clusters.DoorLock.Enums.DoorStateEnum.kDoorForcedOpen:
True,
157 clusters.DoorLock.Enums.DoorStateEnum.kDoorClosed:
False,
160 entity_class=MatterBinarySensor,
161 required_attributes=(clusters.DoorLock.Attributes.DoorState,),
162 featuremap_contains=clusters.DoorLock.Bitmaps.Feature.kDoorPositionSensor,
165 platform=Platform.BINARY_SENSOR,
167 key=
"SmokeCoAlarmDeviceMutedSensor",
168 measurement_to_ha=
lambda x: (
169 x == clusters.SmokeCoAlarm.Enums.MuteStateEnum.kMuted
171 translation_key=
"muted",
172 entity_category=EntityCategory.DIAGNOSTIC,
174 entity_class=MatterBinarySensor,
175 required_attributes=(clusters.SmokeCoAlarm.Attributes.DeviceMuted,),
178 platform=Platform.BINARY_SENSOR,
180 key=
"SmokeCoAlarmEndfOfServiceSensor",
181 measurement_to_ha=
lambda x: (
182 x == clusters.SmokeCoAlarm.Enums.EndOfServiceEnum.kExpired
184 translation_key=
"end_of_service",
185 device_class=BinarySensorDeviceClass.PROBLEM,
186 entity_category=EntityCategory.DIAGNOSTIC,
188 entity_class=MatterBinarySensor,
189 required_attributes=(clusters.SmokeCoAlarm.Attributes.EndOfServiceAlert,),
192 platform=Platform.BINARY_SENSOR,
194 key=
"SmokeCoAlarmBatteryAlertSensor",
195 measurement_to_ha=
lambda x: (
196 x != clusters.SmokeCoAlarm.Enums.AlarmStateEnum.kNormal
198 translation_key=
"battery_alert",
199 device_class=BinarySensorDeviceClass.BATTERY,
200 entity_category=EntityCategory.DIAGNOSTIC,
202 entity_class=MatterBinarySensor,
203 required_attributes=(clusters.SmokeCoAlarm.Attributes.BatteryAlert,),
206 platform=Platform.BINARY_SENSOR,
208 key=
"SmokeCoAlarmTestInProgressSensor",
209 translation_key=
"test_in_progress",
210 device_class=BinarySensorDeviceClass.RUNNING,
211 entity_category=EntityCategory.DIAGNOSTIC,
213 entity_class=MatterBinarySensor,
214 required_attributes=(clusters.SmokeCoAlarm.Attributes.TestInProgress,),
217 platform=Platform.BINARY_SENSOR,
219 key=
"SmokeCoAlarmHardwareFaultAlertSensor",
220 translation_key=
"hardware_fault",
221 device_class=BinarySensorDeviceClass.PROBLEM,
222 entity_category=EntityCategory.DIAGNOSTIC,
224 entity_class=MatterBinarySensor,
225 required_attributes=(clusters.SmokeCoAlarm.Attributes.HardwareFaultAlert,),
228 platform=Platform.BINARY_SENSOR,
230 key=
"SmokeCoAlarmSmokeStateSensor",
231 device_class=BinarySensorDeviceClass.SMOKE,
232 measurement_to_ha=
lambda x: (
233 x != clusters.SmokeCoAlarm.Enums.AlarmStateEnum.kNormal
236 entity_class=MatterBinarySensor,
237 required_attributes=(clusters.SmokeCoAlarm.Attributes.SmokeState,),
240 platform=Platform.BINARY_SENSOR,
242 key=
"SmokeCoAlarmInterconnectSmokeAlarmSensor",
243 device_class=BinarySensorDeviceClass.SMOKE,
244 measurement_to_ha=
lambda x: (
245 x != clusters.SmokeCoAlarm.Enums.AlarmStateEnum.kNormal
247 translation_key=
"interconnected_smoke_alarm",
249 entity_class=MatterBinarySensor,
250 required_attributes=(clusters.SmokeCoAlarm.Attributes.InterconnectSmokeAlarm,),
253 platform=Platform.BINARY_SENSOR,
255 key=
"SmokeCoAlarmInterconnectCOAlarmSensor",
256 device_class=BinarySensorDeviceClass.CO,
257 measurement_to_ha=
lambda x: (
258 x != clusters.SmokeCoAlarm.Enums.AlarmStateEnum.kNormal
260 translation_key=
"interconnected_co_alarm",
262 entity_class=MatterBinarySensor,
263 required_attributes=(clusters.SmokeCoAlarm.Attributes.InterconnectCOAlarm,),
None _update_from_device(self)
Any get_matter_attribute_value(self, type[ClusterAttributeDescriptor] attribute, bool null_as_none=True)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
MatterAdapter get_matter(HomeAssistant hass)