1 """Plugwise Binary Sensor component for Home Assistant."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from dataclasses
import dataclass
9 from plugwise.constants
import BinarySensorType
12 BinarySensorDeviceClass,
14 BinarySensorEntityDescription,
20 from .
import PlugwiseConfigEntry
21 from .coordinator
import PlugwiseDataUpdateCoordinator
22 from .entity
import PlugwiseEntity
24 SEVERITIES = [
"other",
"info",
"warning",
"error"]
27 @dataclass(frozen=True)
29 """Describes a Plugwise binary sensor entity."""
34 BINARY_SENSORS: tuple[PlugwiseBinarySensorEntityDescription, ...] = (
37 translation_key=
"low_battery",
38 device_class=BinarySensorDeviceClass.BATTERY,
39 entity_category=EntityCategory.DIAGNOSTIC,
42 key=
"compressor_state",
43 translation_key=
"compressor_state",
44 entity_category=EntityCategory.DIAGNOSTIC,
47 key=
"cooling_enabled",
48 translation_key=
"cooling_enabled",
49 entity_category=EntityCategory.DIAGNOSTIC,
53 translation_key=
"dhw_state",
54 entity_category=EntityCategory.DIAGNOSTIC,
58 translation_key=
"flame_state",
60 entity_category=EntityCategory.DIAGNOSTIC,
64 translation_key=
"heating_state",
65 entity_category=EntityCategory.DIAGNOSTIC,
69 translation_key=
"cooling_state",
70 entity_category=EntityCategory.DIAGNOSTIC,
73 key=
"secondary_boiler_state",
74 translation_key=
"secondary_boiler_state",
75 entity_category=EntityCategory.DIAGNOSTIC,
78 key=
"plugwise_notification",
79 translation_key=
"plugwise_notification",
80 entity_category=EntityCategory.DIAGNOSTIC,
87 entry: PlugwiseConfigEntry,
88 async_add_entities: AddEntitiesCallback,
90 """Set up the Smile binary_sensors from a config entry."""
91 coordinator = entry.runtime_data
94 def _add_entities() -> None:
96 if not coordinator.new_devices:
101 for device_id
in coordinator.new_devices
103 binary_sensors := coordinator.data.devices[device_id].
get(
107 for description
in BINARY_SENSORS
108 if description.key
in binary_sensors
112 entry.async_on_unload(coordinator.async_add_listener(_add_entities))
116 """Represent Smile Binary Sensors."""
118 entity_description: PlugwiseBinarySensorEntityDescription
122 coordinator: PlugwiseDataUpdateCoordinator,
124 description: PlugwiseBinarySensorEntityDescription,
126 """Initialise the binary_sensor."""
127 super().
__init__(coordinator, device_id)
133 """Return true if the binary sensor is on."""
138 """Return entity specific state attributes."""
142 attrs: dict[str, list[str]] = {f
"{severity}_msg": []
for severity
in SEVERITIES}
143 if notify := self.coordinator.data.gateway[
"notifications"]:
144 for details
in notify.values():
145 for msg_type, msg
in details.items():
146 msg_type = msg_type.lower()
147 if msg_type
not in SEVERITIES:
149 attrs[f
"{msg_type}_msg"].append(msg)
None __init__(self, PlugwiseDataUpdateCoordinator coordinator, str device_id, PlugwiseBinarySensorEntityDescription description)
Mapping[str, Any]|None extra_state_attributes(self)
GwEntityData device(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, PlugwiseConfigEntry entry, AddEntitiesCallback async_add_entities)