Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for IntelliFire Binary Sensors."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Callable
6 from dataclasses import dataclass
7 
9  BinarySensorDeviceClass,
10  BinarySensorEntity,
11  BinarySensorEntityDescription,
12 )
13 from homeassistant.config_entries import ConfigEntry
14 from homeassistant.const import EntityCategory
15 from homeassistant.core import HomeAssistant
16 from homeassistant.helpers.entity_platform import AddEntitiesCallback
17 
18 from . import IntellifireDataUpdateCoordinator
19 from .const import DOMAIN
20 from .entity import IntellifireEntity
21 
22 
23 @dataclass(frozen=True)
25  """Mixin for required keys."""
26 
27  value_fn: Callable[[IntellifireDataUpdateCoordinator], bool | None]
28 
29 
30 @dataclass(frozen=True)
32  BinarySensorEntityDescription, IntellifireBinarySensorRequiredKeysMixin
33 ):
34  """Describes a binary sensor entity."""
35 
36 
37 INTELLIFIRE_BINARY_SENSORS: tuple[IntellifireBinarySensorEntityDescription, ...] = (
39  key="on_off", # This is the sensor name
40  translation_key="flame", # This is the translation key
41  value_fn=lambda coordinator: coordinator.data.is_on,
42  ),
44  key="timer_on",
45  translation_key="timer_on",
46  value_fn=lambda coordinator: coordinator.data.timer_on,
47  ),
49  key="pilot_light_on",
50  translation_key="pilot_light_on",
51  value_fn=lambda coordinator: coordinator.data.pilot_on,
52  ),
54  key="thermostat_on",
55  translation_key="thermostat_on",
56  value_fn=lambda coordinator: coordinator.data.thermostat_on,
57  ),
59  key="error_pilot_flame",
60  translation_key="pilot_flame_error",
61  entity_category=EntityCategory.DIAGNOSTIC,
62  value_fn=lambda coordinator: coordinator.data.error_pilot_flame,
63  device_class=BinarySensorDeviceClass.PROBLEM,
64  ),
66  key="error_flame",
67  translation_key="flame_error",
68  entity_category=EntityCategory.DIAGNOSTIC,
69  value_fn=lambda coordinator: coordinator.data.error_flame,
70  device_class=BinarySensorDeviceClass.PROBLEM,
71  ),
73  key="error_fan_delay",
74  translation_key="fan_delay_error",
75  entity_category=EntityCategory.DIAGNOSTIC,
76  value_fn=lambda coordinator: coordinator.data.error_fan_delay,
77  device_class=BinarySensorDeviceClass.PROBLEM,
78  ),
80  key="error_maintenance",
81  translation_key="maintenance_error",
82  entity_category=EntityCategory.DIAGNOSTIC,
83  value_fn=lambda coordinator: coordinator.data.error_maintenance,
84  device_class=BinarySensorDeviceClass.PROBLEM,
85  ),
87  key="error_disabled",
88  translation_key="disabled_error",
89  entity_category=EntityCategory.DIAGNOSTIC,
90  value_fn=lambda coordinator: coordinator.data.error_disabled,
91  device_class=BinarySensorDeviceClass.PROBLEM,
92  ),
94  key="error_fan",
95  translation_key="fan_error",
96  entity_category=EntityCategory.DIAGNOSTIC,
97  value_fn=lambda coordinator: coordinator.data.error_fan,
98  device_class=BinarySensorDeviceClass.PROBLEM,
99  ),
101  key="error_lights",
102  translation_key="lights_error",
103  entity_category=EntityCategory.DIAGNOSTIC,
104  value_fn=lambda coordinator: coordinator.data.error_lights,
105  device_class=BinarySensorDeviceClass.PROBLEM,
106  ),
108  key="error_accessory",
109  translation_key="accessory_error",
110  entity_category=EntityCategory.DIAGNOSTIC,
111  value_fn=lambda coordinator: coordinator.data.error_accessory,
112  device_class=BinarySensorDeviceClass.PROBLEM,
113  ),
115  key="error_soft_lock_out",
116  translation_key="soft_lock_out_error",
117  entity_category=EntityCategory.DIAGNOSTIC,
118  value_fn=lambda coordinator: coordinator.data.error_soft_lock_out,
119  device_class=BinarySensorDeviceClass.PROBLEM,
120  ),
122  key="error_ecm_offline",
123  translation_key="ecm_offline_error",
124  entity_category=EntityCategory.DIAGNOSTIC,
125  value_fn=lambda coordinator: coordinator.data.error_ecm_offline,
126  device_class=BinarySensorDeviceClass.PROBLEM,
127  ),
129  key="error_offline",
130  translation_key="offline_error",
131  entity_category=EntityCategory.DIAGNOSTIC,
132  value_fn=lambda coordinator: coordinator.data.error_offline,
133  device_class=BinarySensorDeviceClass.PROBLEM,
134  ),
136  key="local_connectivity",
137  translation_key="local_connectivity",
138  entity_category=EntityCategory.DIAGNOSTIC,
139  device_class=BinarySensorDeviceClass.CONNECTIVITY,
140  value_fn=lambda coordinator: coordinator.fireplace.local_connectivity,
141  ),
143  key="cloud_connectivity",
144  translation_key="cloud_connectivity",
145  entity_category=EntityCategory.DIAGNOSTIC,
146  device_class=BinarySensorDeviceClass.CONNECTIVITY,
147  value_fn=lambda coordinator: coordinator.fireplace.cloud_connectivity,
148  ),
149 )
150 
151 
153  hass: HomeAssistant,
154  entry: ConfigEntry,
155  async_add_entities: AddEntitiesCallback,
156 ) -> None:
157  """Set up a IntelliFire On/Off Sensor."""
158  coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
159 
161  IntellifireBinarySensor(coordinator=coordinator, description=description)
162  for description in INTELLIFIRE_BINARY_SENSORS
163  )
164 
165 
167  """Extends IntellifireEntity with Binary Sensor specific logic."""
168 
169  entity_description: IntellifireBinarySensorEntityDescription
170 
171  @property
172  def is_on(self) -> bool | None:
173  """Use this to get the correct value."""
174  return self.entity_descriptionentity_description.value_fn(self.coordinator)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)