1 """Support for Toon binary sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
8 BinarySensorDeviceClass,
10 BinarySensorEntityDescription,
16 from .const
import DOMAIN
17 from .coordinator
import ToonDataUpdateCoordinator
19 ToonBoilerDeviceEntity,
20 ToonBoilerModuleDeviceEntity,
21 ToonDisplayDeviceEntity,
23 ToonRequiredKeysMixin,
28 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
30 """Set up a Toon binary sensor based on a config entry."""
31 coordinator = hass.data[DOMAIN][entry.entry_id]
34 description.cls(coordinator, description)
35 for description
in BINARY_SENSOR_ENTITIES
37 if coordinator.data.thermostat.have_opentherm_boiler:
40 description.cls(coordinator, description)
41 for description
in BINARY_SENSOR_ENTITIES_BOILER
49 """Defines an Toon binary sensor."""
51 entity_description: ToonBinarySensorEntityDescription
55 coordinator: ToonDataUpdateCoordinator,
56 description: ToonBinarySensorEntityDescription,
58 """Initialize the Toon sensor."""
65 f
"{DOMAIN}_{coordinator.data.agreement.agreement_id}_binary_sensor_{description.key}"
70 """Return the status of the binary sensor."""
71 section = getattr(self.coordinator.data, self.
entity_descriptionentity_description.section)
84 """Defines a Boiler binary sensor."""
87 class ToonDisplayBinarySensor(ToonBinarySensor, ToonDisplayDeviceEntity):
88 """Defines a Toon Display binary sensor."""
92 """Defines a Boiler module binary sensor."""
95 @dataclass(frozen=
True)
97 """Mixin for binary sensor required keys."""
99 cls: type[ToonBinarySensor]
102 @dataclass(frozen=True)
104 BinarySensorEntityDescription, ToonBinarySensorRequiredKeysMixin
106 """Describes Toon binary sensor entity."""
108 inverted: bool =
False
111 BINARY_SENSOR_ENTITIES = (
113 key=
"thermostat_info_boiler_connected_None",
114 name=
"Boiler Module Connection",
115 section=
"thermostat",
116 measurement=
"boiler_module_connected",
117 device_class=BinarySensorDeviceClass.CONNECTIVITY,
118 entity_registry_enabled_default=
False,
119 cls=ToonBoilerModuleBinarySensor,
122 key=
"thermostat_program_overridden",
123 name=
"Thermostat Program Override",
124 section=
"thermostat",
125 measurement=
"program_overridden",
126 icon=
"mdi:gesture-tap",
127 cls=ToonDisplayBinarySensor,
131 BINARY_SENSOR_ENTITIES_BOILER: tuple[ToonBinarySensorEntityDescription, ...] = (
133 key=
"thermostat_info_burner_info_1",
134 name=
"Boiler Heating",
135 section=
"thermostat",
136 measurement=
"heating",
138 entity_registry_enabled_default=
False,
139 cls=ToonBoilerBinarySensor,
142 key=
"thermostat_info_burner_info_2",
143 name=
"Hot Tap Water",
144 section=
"thermostat",
145 measurement=
"hot_tapwater",
146 icon=
"mdi:water-pump",
147 cls=ToonBoilerBinarySensor,
150 key=
"thermostat_info_burner_info_3",
151 name=
"Boiler Preheating",
152 section=
"thermostat",
153 measurement=
"pre_heating",
155 entity_registry_enabled_default=
False,
156 cls=ToonBoilerBinarySensor,
159 key=
"thermostat_info_burner_info_None",
160 name=
"Boiler Burner",
161 section=
"thermostat",
162 measurement=
"burner",
164 cls=ToonBoilerBinarySensor,
167 key=
"thermostat_info_error_found_255",
168 name=
"Boiler Status",
169 section=
"thermostat",
170 measurement=
"error_found",
171 device_class=BinarySensorDeviceClass.PROBLEM,
173 cls=ToonBoilerBinarySensor,
176 key=
"thermostat_info_ot_communication_error_0",
177 name=
"OpenTherm Connection",
178 section=
"thermostat",
179 measurement=
"opentherm_communication_error",
180 device_class=BinarySensorDeviceClass.PROBLEM,
181 icon=
"mdi:check-network-outline",
182 entity_registry_enabled_default=
False,
183 cls=ToonBoilerBinarySensor,
None __init__(self, ToonDataUpdateCoordinator coordinator, ToonBinarySensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)