1 """Support for Salda Smarty XP/XV Ventilation Unit Sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from datetime
import datetime, timedelta
10 from pysmarty2
import Smarty
15 SensorEntityDescription,
22 from .coordinator
import SmartyConfigEntry, SmartyCoordinator
23 from .entity
import SmartyEntity
25 _LOGGER = logging.getLogger(__name__)
29 """Return the date when the filter needs to be replaced."""
30 if (days_left := smarty.filter_timer)
is not None:
31 return dt_util.now() +
timedelta(days=days_left)
35 @dataclass(frozen=True, kw_only=True)
37 """Class describing Smarty sensor."""
39 value_fn: Callable[[Smarty], float | datetime |
None]
42 ENTITIES: tuple[SmartySensorDescription, ...] = (
44 key=
"supply_air_temperature",
45 translation_key=
"supply_air_temperature",
46 device_class=SensorDeviceClass.TEMPERATURE,
47 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
48 value_fn=
lambda smarty: smarty.supply_air_temperature,
51 key=
"extract_air_temperature",
52 translation_key=
"extract_air_temperature",
53 device_class=SensorDeviceClass.TEMPERATURE,
54 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
55 value_fn=
lambda smarty: smarty.extract_air_temperature,
58 key=
"outdoor_air_temperature",
59 translation_key=
"outdoor_air_temperature",
60 device_class=SensorDeviceClass.TEMPERATURE,
61 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
62 value_fn=
lambda smarty: smarty.outdoor_air_temperature,
65 key=
"supply_fan_speed",
66 translation_key=
"supply_fan_speed",
67 native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
68 value_fn=
lambda smarty: smarty.supply_fan_speed,
71 key=
"extract_fan_speed",
72 translation_key=
"extract_fan_speed",
73 native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
74 value_fn=
lambda smarty: smarty.extract_fan_speed,
77 key=
"filter_days_left",
78 translation_key=
"filter_days_left",
79 device_class=SensorDeviceClass.TIMESTAMP,
80 value_fn=get_filter_days_left,
87 entry: SmartyConfigEntry,
88 async_add_entities: AddEntitiesCallback,
90 """Set up the Smarty Sensor Platform."""
92 coordinator = entry.runtime_data
95 SmartySensor(coordinator, description)
for description
in ENTITIES
100 """Representation of a Smarty Sensor."""
102 entity_description: SmartySensorDescription
106 coordinator: SmartyCoordinator,
107 entity_description: SmartySensorDescription,
109 """Initialize the entity."""
113 f
"{coordinator.config_entry.entry_id}_{entity_description.key}"
118 """Return the state of the sensor."""
float|datetime|None native_value(self)
None __init__(self, SmartyCoordinator coordinator, SmartySensorDescription entity_description)
datetime|None get_filter_days_left(Smarty smarty)
None async_setup_entry(HomeAssistant hass, SmartyConfigEntry entry, AddEntitiesCallback async_add_entities)