1 """Support for Ecoforest sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
9 from pyecoforest.models.device
import Alarm, Device, State
14 SensorEntityDescription,
27 from .const
import DOMAIN
28 from .coordinator
import EcoforestCoordinator
29 from .entity
import EcoforestEntity
31 _LOGGER = logging.getLogger(__name__)
33 STATUS_TYPE = [s.value
for s
in State]
34 ALARM_TYPE = [a.value
for a
in Alarm] + [
"none"]
37 @dataclass(frozen=True, kw_only=True)
39 """Describes Ecoforest sensor entity."""
41 value_fn: Callable[[Device], StateType]
44 SENSOR_TYPES: tuple[EcoforestSensorEntityDescription, ...] = (
47 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
48 device_class=SensorDeviceClass.TEMPERATURE,
49 value_fn=
lambda data: data.environment_temperature,
52 key=
"cpu_temperature",
53 translation_key=
"cpu_temperature",
54 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
55 device_class=SensorDeviceClass.TEMPERATURE,
56 entity_registry_enabled_default=
False,
57 value_fn=
lambda data: data.cpu_temperature,
60 key=
"gas_temperature",
61 translation_key=
"gas_temperature",
62 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
63 device_class=SensorDeviceClass.TEMPERATURE,
64 entity_registry_enabled_default=
False,
65 value_fn=
lambda data: data.gas_temperature,
68 key=
"ntc_temperature",
69 translation_key=
"ntc_temperature",
70 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
71 device_class=SensorDeviceClass.TEMPERATURE,
72 entity_registry_enabled_default=
False,
73 value_fn=
lambda data: data.ntc_temperature,
77 translation_key=
"status",
78 device_class=SensorDeviceClass.ENUM,
80 value_fn=
lambda data: data.state.value,
84 translation_key=
"alarm",
85 device_class=SensorDeviceClass.ENUM,
87 value_fn=
lambda data: data.alarm.value
if data.alarm
else "none",
91 translation_key=
"depression",
92 native_unit_of_measurement=UnitOfPressure.PA,
93 device_class=SensorDeviceClass.ATMOSPHERIC_PRESSURE,
94 entity_registry_enabled_default=
False,
95 value_fn=
lambda data: data.depression,
99 translation_key=
"working_hours",
100 native_unit_of_measurement=UnitOfTime.HOURS,
101 device_class=SensorDeviceClass.DURATION,
102 entity_registry_enabled_default=
False,
103 value_fn=
lambda data: data.working_hours,
107 translation_key=
"ignitions",
108 native_unit_of_measurement=
"ignitions",
109 entity_registry_enabled_default=
False,
110 value_fn=
lambda data: data.ignitions,
114 translation_key=
"live_pulse",
115 native_unit_of_measurement=UnitOfTime.SECONDS,
116 device_class=SensorDeviceClass.DURATION,
117 entity_registry_enabled_default=
False,
118 value_fn=
lambda data: data.live_pulse,
122 translation_key=
"pulse_offset",
123 native_unit_of_measurement=UnitOfTime.SECONDS,
124 device_class=SensorDeviceClass.DURATION,
125 entity_registry_enabled_default=
False,
126 value_fn=
lambda data: data.pulse_offset,
130 translation_key=
"extractor",
131 native_unit_of_measurement=PERCENTAGE,
132 entity_registry_enabled_default=
False,
133 value_fn=
lambda data: data.extractor,
136 key=
"convecto_air_flow",
137 translation_key=
"convecto_air_flow",
138 native_unit_of_measurement=PERCENTAGE,
139 entity_registry_enabled_default=
False,
140 value_fn=
lambda data: data.convecto_air_flow,
146 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
148 """Set up the Ecoforest sensor platform."""
149 coordinator: EcoforestCoordinator = hass.data[DOMAIN][entry.entry_id]
152 EcoforestSensor(coordinator, description)
for description
in SENSOR_TYPES
159 """Representation of an Ecoforest sensor."""
161 entity_description: EcoforestSensorEntityDescription
165 """Return the state of the sensor."""
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)