1 """Support for Overkiz binary sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from typing
import cast
9 from pyoverkiz.enums
import OverkizCommandParam, OverkizState
10 from pyoverkiz.types
import StateType
as OverkizStateType
13 BinarySensorDeviceClass,
15 BinarySensorEntityDescription,
21 from .
import HomeAssistantOverkizData
22 from .const
import DOMAIN, IGNORED_OVERKIZ_DEVICES
23 from .entity
import OverkizDescriptiveEntity
26 @dataclass(frozen=True, kw_only=True)
28 """Class to describe an Overkiz binary sensor."""
30 value_fn: Callable[[OverkizStateType], bool]
33 BINARY_SENSOR_DESCRIPTIONS: list[OverkizBinarySensorDescription] = [
36 key=OverkizState.CORE_RAIN,
38 icon=
"mdi:weather-rainy",
39 value_fn=
lambda state: state == OverkizCommandParam.DETECTED,
43 key=OverkizState.CORE_SMOKE,
45 device_class=BinarySensorDeviceClass.SMOKE,
46 value_fn=
lambda state: state == OverkizCommandParam.DETECTED,
50 key=OverkizState.CORE_WATER_DETECTION,
53 value_fn=
lambda state: state == OverkizCommandParam.DETECTED,
57 key=OverkizState.CORE_GAS_DETECTION,
59 device_class=BinarySensorDeviceClass.GAS,
60 value_fn=
lambda state: state == OverkizCommandParam.DETECTED,
65 key=OverkizState.CORE_OCCUPANCY,
67 device_class=BinarySensorDeviceClass.OCCUPANCY,
68 value_fn=
lambda state: state == OverkizCommandParam.PERSON_INSIDE,
72 key=OverkizState.CORE_VIBRATION,
74 device_class=BinarySensorDeviceClass.VIBRATION,
75 value_fn=
lambda state: state == OverkizCommandParam.DETECTED,
79 key=OverkizState.CORE_CONTACT,
81 device_class=BinarySensorDeviceClass.DOOR,
82 value_fn=
lambda state: state == OverkizCommandParam.OPEN,
86 key=OverkizState.CORE_ASSEMBLY,
88 device_class=BinarySensorDeviceClass.PROBLEM,
89 value_fn=
lambda state: state == OverkizCommandParam.OPEN,
93 key=OverkizState.IO_VIBRATION_DETECTED,
95 device_class=BinarySensorDeviceClass.VIBRATION,
96 value_fn=
lambda state: state == OverkizCommandParam.DETECTED,
100 key=OverkizState.IO_OPERATING_MODE_CAPABILITIES,
101 name=
"Energy Demand Status",
102 device_class=BinarySensorDeviceClass.HEAT,
103 value_fn=
lambda state: cast(dict, state).
get(
104 OverkizCommandParam.ENERGY_DEMAND_STATUS
109 key=OverkizState.CORE_HEATING_STATUS,
110 name=
"Heating status",
111 device_class=BinarySensorDeviceClass.HEAT,
112 value_fn=
lambda state: cast(str, state).lower()
113 in (OverkizCommandParam.ON, OverkizCommandParam.HEATING),
116 key=OverkizState.MODBUSLINK_DHW_ABSENCE_MODE,
119 lambda state: state
in (OverkizCommandParam.ON, OverkizCommandParam.PROG)
123 key=OverkizState.MODBUSLINK_DHW_BOOST_MODE,
126 lambda state: state
in (OverkizCommandParam.ON, OverkizCommandParam.PROG)
130 key=OverkizState.MODBUSLINK_DHW_MODE,
134 in (OverkizCommandParam.MANUAL, OverkizCommandParam.MANUAL_ECO_INACTIVE)
140 description.key: description
for description
in BINARY_SENSOR_DESCRIPTIONS
147 async_add_entities: AddEntitiesCallback,
149 """Set up the Overkiz binary sensors from a config entry."""
150 data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
151 entities: list[OverkizBinarySensor] = []
153 for device
in data.coordinator.data.values():
155 device.widget
in IGNORED_OVERKIZ_DEVICES
156 or device.ui_class
in IGNORED_OVERKIZ_DEVICES
166 for state
in device.definition.states
167 if (description := SUPPORTED_STATES.get(state.qualified_name))
174 """Representation of an Overkiz Binary Sensor."""
176 entity_description: OverkizBinarySensorDescription
180 """Return the state of the sensor."""
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)