1 """Viessmann ViCare sensor device."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from contextlib
import suppress
7 from dataclasses
import dataclass
10 from PyViCare.PyViCareDevice
import Device
as PyViCareDevice
11 from PyViCare.PyViCareDeviceConfig
import PyViCareDeviceConfig
12 from PyViCare.PyViCareHeatingDevice
import (
13 HeatingDeviceWithComponent
as PyViCareHeatingDeviceComponent,
15 from PyViCare.PyViCareUtils
import (
16 PyViCareInvalidDataError,
17 PyViCareNotSupportedFeatureError,
18 PyViCareRateLimitError,
23 BinarySensorDeviceClass,
25 BinarySensorEntityDescription,
31 from .const
import DEVICE_LIST, DOMAIN
32 from .entity
import ViCareEntity
33 from .types
import ViCareDevice, ViCareRequiredKeysMixin
42 _LOGGER = logging.getLogger(__name__)
45 @dataclass(frozen=True)
47 BinarySensorEntityDescription, ViCareRequiredKeysMixin
49 """Describes ViCare binary sensor entity."""
51 value_getter: Callable[[PyViCareDevice], bool]
54 CIRCUIT_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
56 key=
"circulationpump_active",
57 translation_key=
"circulation_pump",
58 device_class=BinarySensorDeviceClass.RUNNING,
59 value_getter=
lambda api: api.getCirculationPumpActive(),
62 key=
"frost_protection_active",
63 translation_key=
"frost_protection",
64 value_getter=
lambda api: api.getFrostProtectionActive(),
68 BURNER_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
71 translation_key=
"burner",
72 device_class=BinarySensorDeviceClass.RUNNING,
73 value_getter=
lambda api: api.getActive(),
77 COMPRESSOR_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
79 key=
"compressor_active",
80 translation_key=
"compressor",
81 device_class=BinarySensorDeviceClass.RUNNING,
82 value_getter=
lambda api: api.getActive(),
86 GLOBAL_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
88 key=
"solar_pump_active",
89 translation_key=
"solar_pump",
90 device_class=BinarySensorDeviceClass.RUNNING,
91 value_getter=
lambda api: api.getSolarPumpActive(),
94 key=
"charging_active",
95 translation_key=
"domestic_hot_water_charging",
96 device_class=BinarySensorDeviceClass.RUNNING,
97 value_getter=
lambda api: api.getDomesticHotWaterChargingActive(),
100 key=
"dhw_circulationpump_active",
101 translation_key=
"domestic_hot_water_circulation_pump",
102 device_class=BinarySensorDeviceClass.RUNNING,
103 value_getter=
lambda api: api.getDomesticHotWaterCirculationPumpActive(),
106 key=
"dhw_pump_active",
107 translation_key=
"domestic_hot_water_pump",
108 device_class=BinarySensorDeviceClass.RUNNING,
109 value_getter=
lambda api: api.getDomesticHotWaterPumpActive(),
115 device_list: list[ViCareDevice],
116 ) -> list[ViCareBinarySensor]:
117 """Create ViCare binary sensor entities for a device."""
119 entities: list[ViCareBinarySensor] = []
120 for device
in device_list:
129 for description
in GLOBAL_SENSORS
130 if is_supported(description.key, description, device.api)
133 for component_list, entity_description_list
in (
146 for component
in component_list
147 for description
in entity_description_list
148 if is_supported(description.key, description, component)
155 config_entry: ConfigEntry,
156 async_add_entities: AddEntitiesCallback,
158 """Create the ViCare binary sensor devices."""
159 device_list = hass.data[DOMAIN][config_entry.entry_id][DEVICE_LIST]
162 await hass.async_add_executor_job(
170 """Representation of a ViCare sensor."""
172 entity_description: ViCareBinarySensorEntityDescription
176 description: ViCareBinarySensorEntityDescription,
177 device_serial: str |
None,
178 device_config: PyViCareDeviceConfig,
179 device: PyViCareDevice,
180 component: PyViCareHeatingDeviceComponent |
None =
None,
182 """Initialize the sensor."""
184 description.key, device_serial, device_config, device, component
190 """Return True if entity is available."""
194 """Update state of sensor."""
196 with suppress(PyViCareNotSupportedFeatureError):
198 except requests.exceptions.ConnectionError:
199 _LOGGER.error(
"Unable to retrieve data from ViCare server")
201 _LOGGER.error(
"Unable to decode data from ViCare server")
202 except PyViCareRateLimitError
as limit_exception:
203 _LOGGER.error(
"Vicare API rate limit exceeded: %s", limit_exception)
204 except PyViCareInvalidDataError
as invalid_data_exception:
205 _LOGGER.error(
"Invalid data from Vicare server: %s", invalid_data_exception)
None __init__(self, ViCareBinarySensorEntityDescription description, str|None device_serial, PyViCareDeviceConfig device_config, PyViCareDevice device, PyViCareHeatingDeviceComponent|None component=None)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
list[ViCareBinarySensor] _build_entities(list[ViCareDevice] device_list)
str|None get_device_serial(PyViCareDevice device)
list[PyViCareHeatingDeviceComponent] get_compressors(PyViCareDevice device)
bool is_supported(str name, ViCareRequiredKeysMixin entity_description, vicare_device)
list[PyViCareHeatingDeviceComponent] get_circuits(PyViCareDevice device)
list[PyViCareHeatingDeviceComponent] get_burners(PyViCareDevice device)