Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Salda Smarty XP/XV Ventilation Unit Binary Sensors."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Callable
6 from dataclasses import dataclass
7 import logging
8 
9 from pysmarty2 import Smarty
10 
12  BinarySensorDeviceClass,
13  BinarySensorEntity,
14  BinarySensorEntityDescription,
15 )
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from .coordinator import SmartyConfigEntry, SmartyCoordinator
20 from .entity import SmartyEntity
21 
22 _LOGGER = logging.getLogger(__name__)
23 
24 
25 @dataclass(frozen=True, kw_only=True)
27  """Class describing Smarty binary sensor entities."""
28 
29  value_fn: Callable[[Smarty], bool]
30 
31 
32 ENTITIES: tuple[SmartyBinarySensorEntityDescription, ...] = (
34  key="alarm",
35  translation_key="alarm",
36  device_class=BinarySensorDeviceClass.PROBLEM,
37  value_fn=lambda smarty: smarty.alarm,
38  ),
40  key="warning",
41  translation_key="warning",
42  device_class=BinarySensorDeviceClass.PROBLEM,
43  value_fn=lambda smarty: smarty.warning,
44  ),
46  key="boost",
47  translation_key="boost_state",
48  value_fn=lambda smarty: smarty.boost,
49  ),
50 )
51 
52 
54  hass: HomeAssistant,
55  entry: SmartyConfigEntry,
56  async_add_entities: AddEntitiesCallback,
57 ) -> None:
58  """Set up the Smarty Binary Sensor Platform."""
59 
60  coordinator = entry.runtime_data
61 
63  SmartyBinarySensor(coordinator, description) for description in ENTITIES
64  )
65 
66 
68  """Representation of a Smarty Binary Sensor."""
69 
70  entity_description: SmartyBinarySensorEntityDescription
71 
72  def __init__(
73  self,
74  coordinator: SmartyCoordinator,
75  entity_description: SmartyBinarySensorEntityDescription,
76  ) -> None:
77  """Initialize the entity."""
78  super().__init__(coordinator)
79  self.entity_descriptionentity_description = entity_description
80  self._attr_unique_id_attr_unique_id = (
81  f"{coordinator.config_entry.entry_id}_{entity_description.key}"
82  )
83 
84  @property
85  def is_on(self) -> bool:
86  """Return the state of the binary sensor."""
87  return self.entity_descriptionentity_description.value_fn(self.coordinator.client)
None __init__(self, SmartyCoordinator coordinator, SmartyBinarySensorEntityDescription entity_description)
None async_setup_entry(HomeAssistant hass, SmartyConfigEntry entry, AddEntitiesCallback async_add_entities)