1 """Sensor for checking the air quality forecast around Norway."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as AIR_QUALITY_PLATFORM_SCHEMA,
22 _LOGGER = logging.getLogger(__name__)
25 CONF_FORECAST =
"forecast"
28 DEFAULT_NAME =
"Air quality Norway"
30 OVERRIDE_URL =
"https://aa015h6buqvih86i1.api.met.no/weatherapi/airqualityforecast/0.1/"
32 PLATFORM_SCHEMA = AIR_QUALITY_PLATFORM_SCHEMA.extend(
34 vol.Optional(CONF_FORECAST, default=DEFAULT_FORECAST): vol.Coerce(int),
35 vol.Optional(CONF_LATITUDE): cv.latitude,
36 vol.Optional(CONF_LONGITUDE): cv.longitude,
37 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
47 async_add_entities: AddEntitiesCallback,
48 discovery_info: DiscoveryInfoType |
None =
None,
50 """Set up the air_quality norway sensor."""
51 forecast = config.get(CONF_FORECAST)
52 latitude = config.get(CONF_LATITUDE, hass.config.latitude)
53 longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
54 name = config.get(CONF_NAME)
56 if None in (latitude, longitude):
57 _LOGGER.error(
"Latitude or longitude not set in Home Assistant config")
60 coordinates = {
"lat":
str(latitude),
"lon":
str(longitude)}
72 if isinstance(res, float):
80 """Representation of an air quality sensor."""
85 "https://luftkvalitet.miljostatus.no/, "
86 "delivered by the Norwegian Meteorological Institute."
89 def __init__(self, name, coordinates, forecast, session):
90 """Initialize the sensor."""
92 self.
_api_api = metno.AirQualityData(
93 coordinates, forecast, session, api_url=OVERRIDE_URL
98 """Return other details about the sensor state."""
100 "level": self.
_api_api.data.get(
"level"),
101 "location": self.
_api_api.data.get(
"location"),
106 """Return the name of the sensor."""
107 return self.
_name_name
112 """Return the Air Quality Index (AQI)."""
113 return self.
_api_api.data.get(
"aqi")
118 """Return the NO2 (nitrogen dioxide) level."""
119 return self.
_api_api.data.get(
"no2_concentration")
124 """Return the O3 (ozone) level."""
125 return self.
_api_api.data.get(
"o3_concentration")
130 """Return the particulate matter 2.5 level."""
131 return self.
_api_api.data.get(
"pm25_concentration")
136 """Return the particulate matter 10 level."""
137 return self.
_api_api.data.get(
"pm10_concentration")
141 """Return the unit of measurement of this entity, if any."""
142 return self.
_api_api.units.get(
"pm25_concentration")
145 """Update the sensor."""
def particulate_matter_10(self)
dict extra_state_attributes(self)
def nitrogen_dioxide(self)
def particulate_matter_2_5(self)
def air_quality_index(self)
def unit_of_measurement(self)
def __init__(self, name, coordinates, forecast, session)
IssData update(pyiss.ISS iss)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)