1 """Support for Airthings sensors."""
3 from __future__
import annotations
5 from airthings
import AirthingsDevice
10 SensorEntityDescription,
14 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
15 CONCENTRATION_PARTS_PER_BILLION,
16 CONCENTRATION_PARTS_PER_MILLION,
18 SIGNAL_STRENGTH_DECIBELS,
29 from .
import AirthingsConfigEntry, AirthingsDataCoordinatorType
30 from .const
import DOMAIN
32 SENSORS: dict[str, SensorEntityDescription] = {
34 key=
"radonShortTermAvg",
35 native_unit_of_measurement=
"Bq/m³",
36 translation_key=
"radon",
40 device_class=SensorDeviceClass.TEMPERATURE,
41 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
45 device_class=SensorDeviceClass.HUMIDITY,
46 native_unit_of_measurement=PERCENTAGE,
50 device_class=SensorDeviceClass.ATMOSPHERIC_PRESSURE,
51 native_unit_of_measurement=UnitOfPressure.MBAR,
55 device_class=SensorDeviceClass.BATTERY,
56 native_unit_of_measurement=PERCENTAGE,
57 entity_category=EntityCategory.DIAGNOSTIC,
61 device_class=SensorDeviceClass.CO2,
62 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
66 device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS_PARTS,
67 native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
71 native_unit_of_measurement=PERCENTAGE,
72 translation_key=
"light",
76 translation_key=
"virus_risk",
80 translation_key=
"mold",
84 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
85 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
86 entity_registry_enabled_default=
False,
87 entity_category=EntityCategory.DIAGNOSTIC,
91 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
92 device_class=SensorDeviceClass.PM1,
96 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
97 device_class=SensorDeviceClass.PM25,
104 entry: AirthingsConfigEntry,
105 async_add_entities: AddEntitiesCallback,
107 """Set up the Airthings sensor."""
109 coordinator = entry.runtime_data
114 SENSORS[sensor_types],
116 for airthings_device
in coordinator.data.values()
117 for sensor_types
in airthings_device.sensor_types
118 if sensor_types
in SENSORS
124 CoordinatorEntity[AirthingsDataCoordinatorType], SensorEntity
126 """Representation of a Airthings Sensor device."""
128 _attr_state_class = SensorStateClass.MEASUREMENT
129 _attr_has_entity_name =
True
133 coordinator: AirthingsDataCoordinatorType,
134 airthings_device: AirthingsDevice,
135 entity_description: SensorEntityDescription,
137 """Initialize the sensor."""
142 self.
_attr_unique_id_attr_unique_id = f
"{airthings_device.device_id}_{entity_description.key}"
143 self.
_id_id = airthings_device.device_id
146 "https://dashboard.airthings.com/devices/"
147 f
"{airthings_device.device_id}"
149 identifiers={(DOMAIN, airthings_device.device_id)},
150 name=airthings_device.name,
151 manufacturer=
"Airthings",
152 model=airthings_device.product_name,
157 """Return the value reported by the sensor."""
162 """Check if device and sensor is available in data."""
None __init__(self, AirthingsDataCoordinatorType coordinator, AirthingsDevice airthings_device, SensorEntityDescription entity_description)
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, AirthingsConfigEntry entry, AddEntitiesCallback async_add_entities)