1 """Component for handling Air Quality data for your location."""
3 from __future__
import annotations
5 from datetime
import timedelta
7 from typing
import Final, final
18 from .const
import DOMAIN
20 _LOGGER: Final = logging.getLogger(__name__)
22 DATA_COMPONENT: HassKey[EntityComponent[AirQualityEntity]] =
HassKey(DOMAIN)
23 ENTITY_ID_FORMAT: Final = DOMAIN +
".{}"
24 PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
25 PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
28 ATTR_AQI: Final =
"air_quality_index"
29 ATTR_CO2: Final =
"carbon_dioxide"
30 ATTR_CO: Final =
"carbon_monoxide"
31 ATTR_N2O: Final =
"nitrogen_oxide"
32 ATTR_NO: Final =
"nitrogen_monoxide"
33 ATTR_NO2: Final =
"nitrogen_dioxide"
34 ATTR_OZONE: Final =
"ozone"
35 ATTR_PM_0_1: Final =
"particulate_matter_0_1"
36 ATTR_PM_10: Final =
"particulate_matter_10"
37 ATTR_PM_2_5: Final =
"particulate_matter_2_5"
38 ATTR_SO2: Final =
"sulphur_dioxide"
40 PROP_TO_ATTR: Final[dict[str, str]] = {
41 "air_quality_index": ATTR_AQI,
42 "carbon_dioxide": ATTR_CO2,
43 "carbon_monoxide": ATTR_CO,
44 "nitrogen_oxide": ATTR_N2O,
45 "nitrogen_monoxide": ATTR_NO,
46 "nitrogen_dioxide": ATTR_NO2,
48 "particulate_matter_0_1": ATTR_PM_0_1,
49 "particulate_matter_10": ATTR_PM_10,
50 "particulate_matter_2_5": ATTR_PM_2_5,
51 "sulphur_dioxide": ATTR_SO2,
57 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
58 """Set up the air quality component."""
59 component = hass.data[DATA_COMPONENT] = EntityComponent[AirQualityEntity](
60 _LOGGER, DOMAIN, hass, SCAN_INTERVAL
62 await component.async_setup(config)
67 """Set up a config entry."""
72 """Unload a config entry."""
77 """ABC for air quality data."""
81 """Return the particulate matter 2.5 level."""
82 raise NotImplementedError
86 """Return the particulate matter 10 level."""
91 """Return the particulate matter 0.1 level."""
96 """Return the Air Quality Index (AQI)."""
101 """Return the O3 (ozone) level."""
106 """Return the CO (carbon monoxide) level."""
111 """Return the CO2 (carbon dioxide) level."""
116 """Return the SO2 (sulphur dioxide) level."""
121 """Return the N2O (nitrogen oxide) level."""
126 """Return the NO (nitrogen monoxide) level."""
131 """Return the NO2 (nitrogen dioxide) level."""
137 """Return the state attributes."""
138 data: dict[str, str | int | float] = {}
140 for prop, attr
in PROP_TO_ATTR.items():
141 if (value := getattr(self, prop))
is not None:
148 """Return the current state."""
153 """Return the unit of measurement of this entity."""
154 return CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
StateType nitrogen_monoxide(self)
StateType carbon_monoxide(self)
StateType sulphur_dioxide(self)
StateType particulate_matter_0_1(self)
StateType particulate_matter_2_5(self)
StateType nitrogen_oxide(self)
StateType air_quality_index(self)
StateType particulate_matter_10(self)
StateType nitrogen_dioxide(self)
StateType carbon_dioxide(self)
str unit_of_measurement(self)
dict[str, str|int|float] state_attributes(self)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup(HomeAssistant hass, ConfigType config)