1 """Sensor platform for Arve devices."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
6 from asyncarve
import ArveSensProData
11 SensorEntityDescription,
15 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
16 CONCENTRATION_PARTS_PER_MILLION,
23 from .coordinator
import ArveConfigEntry
24 from .entity
import ArveDeviceEntity
27 @dataclass(frozen=True, kw_only=True)
29 """Describes Arve device entity."""
31 value_fn: Callable[[ArveSensProData], float | int]
34 SENSORS: tuple[ArveDeviceEntityDescription, ...] = (
37 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
38 device_class=SensorDeviceClass.CO2,
39 value_fn=
lambda arve_data: arve_data.co2,
40 state_class=SensorStateClass.MEASUREMENT,
44 device_class=SensorDeviceClass.AQI,
45 value_fn=
lambda arve_data: arve_data.aqi,
46 state_class=SensorStateClass.MEASUREMENT,
50 native_unit_of_measurement=PERCENTAGE,
51 device_class=SensorDeviceClass.HUMIDITY,
52 value_fn=
lambda arve_data: arve_data.humidity,
53 state_class=SensorStateClass.MEASUREMENT,
57 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
58 device_class=SensorDeviceClass.PM10,
59 value_fn=
lambda arve_data: arve_data.pm10,
60 state_class=SensorStateClass.MEASUREMENT,
64 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
65 device_class=SensorDeviceClass.PM25,
66 value_fn=
lambda arve_data: arve_data.pm25,
67 state_class=SensorStateClass.MEASUREMENT,
71 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
72 device_class=SensorDeviceClass.TEMPERATURE,
73 value_fn=
lambda arve_data: arve_data.temperature,
74 state_class=SensorStateClass.MEASUREMENT,
78 translation_key=
"tvoc",
79 value_fn=
lambda arve_data: arve_data.tvoc,
80 state_class=SensorStateClass.MEASUREMENT,
86 hass: HomeAssistant, entry: ArveConfigEntry, async_add_entities: AddEntitiesCallback
88 """Set up Arve device based on a config entry."""
89 coordinator = entry.runtime_data
93 for description
in SENSORS
94 for sn
in coordinator.devices.sn
99 """Define an Arve device."""
101 entity_description: ArveDeviceEntityDescription
105 """State of the sensor."""
ArveDeviceInfo device(self)
int|float native_value(self)
None async_setup_entry(HomeAssistant hass, ArveConfigEntry entry, AddEntitiesCallback async_add_entities)