Fix date observed is not sent by AirNow (#101921) (#101977)

* Fix mixed up keys

These were accidentally the wrong values, but never passed on
to the end user.

* Fix date observed is not sent by AirNow (#101921)
This commit is contained in:
Whitney Young 2023-10-15 10:48:47 -07:00 committed by GitHub
parent 36fcf198b1
commit 2c3067b9c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View File

@ -9,8 +9,9 @@ ATTR_API_CAT_DESCRIPTION = "Name"
ATTR_API_O3 = "O3" ATTR_API_O3 = "O3"
ATTR_API_PM25 = "PM2.5" ATTR_API_PM25 = "PM2.5"
ATTR_API_POLLUTANT = "Pollutant" ATTR_API_POLLUTANT = "Pollutant"
ATTR_API_REPORT_DATE = "HourObserved" ATTR_API_REPORT_DATE = "DateObserved"
ATTR_API_REPORT_HOUR = "DateObserved" ATTR_API_REPORT_HOUR = "HourObserved"
ATTR_API_REPORT_TZ = "LocalTimeZone"
ATTR_API_STATE = "StateCode" ATTR_API_STATE = "StateCode"
ATTR_API_STATION = "ReportingArea" ATTR_API_STATION = "ReportingArea"
ATTR_API_STATION_LATITUDE = "Latitude" ATTR_API_STATION_LATITUDE = "Latitude"

View File

@ -20,6 +20,7 @@ from .const import (
ATTR_API_POLLUTANT, ATTR_API_POLLUTANT,
ATTR_API_REPORT_DATE, ATTR_API_REPORT_DATE,
ATTR_API_REPORT_HOUR, ATTR_API_REPORT_HOUR,
ATTR_API_REPORT_TZ,
ATTR_API_STATE, ATTR_API_STATE,
ATTR_API_STATION, ATTR_API_STATION,
ATTR_API_STATION_LATITUDE, ATTR_API_STATION_LATITUDE,
@ -83,6 +84,7 @@ class AirNowDataUpdateCoordinator(DataUpdateCoordinator):
# Copy Report Details # Copy Report Details
data[ATTR_API_REPORT_DATE] = obv[ATTR_API_REPORT_DATE] data[ATTR_API_REPORT_DATE] = obv[ATTR_API_REPORT_DATE]
data[ATTR_API_REPORT_HOUR] = obv[ATTR_API_REPORT_HOUR] data[ATTR_API_REPORT_HOUR] = obv[ATTR_API_REPORT_HOUR]
data[ATTR_API_REPORT_TZ] = obv[ATTR_API_REPORT_TZ]
# Copy Station Details # Copy Station Details
data[ATTR_API_STATE] = obv[ATTR_API_STATE] data[ATTR_API_STATE] = obv[ATTR_API_STATE]

View File

@ -3,6 +3,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime
from typing import Any from typing import Any
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
@ -13,6 +14,7 @@ from homeassistant.components.sensor import (
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_TIME,
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
) )
@ -21,6 +23,7 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.dt import get_time_zone
from . import AirNowDataUpdateCoordinator from . import AirNowDataUpdateCoordinator
from .const import ( from .const import (
@ -29,6 +32,9 @@ from .const import (
ATTR_API_AQI_LEVEL, ATTR_API_AQI_LEVEL,
ATTR_API_O3, ATTR_API_O3,
ATTR_API_PM25, ATTR_API_PM25,
ATTR_API_REPORT_DATE,
ATTR_API_REPORT_HOUR,
ATTR_API_REPORT_TZ,
ATTR_API_STATION, ATTR_API_STATION,
ATTR_API_STATION_LATITUDE, ATTR_API_STATION_LATITUDE,
ATTR_API_STATION_LONGITUDE, ATTR_API_STATION_LONGITUDE,
@ -78,6 +84,12 @@ SENSOR_TYPES: tuple[AirNowEntityDescription, ...] = (
extra_state_attributes_fn=lambda data: { extra_state_attributes_fn=lambda data: {
ATTR_DESCR: data[ATTR_API_AQI_DESCRIPTION], ATTR_DESCR: data[ATTR_API_AQI_DESCRIPTION],
ATTR_LEVEL: data[ATTR_API_AQI_LEVEL], ATTR_LEVEL: data[ATTR_API_AQI_LEVEL],
ATTR_TIME: datetime.strptime(
f"{data[ATTR_API_REPORT_DATE]} {data[ATTR_API_REPORT_HOUR]}",
"%Y-%m-%d %H",
)
.replace(tzinfo=get_time_zone(data[ATTR_API_REPORT_TZ]))
.isoformat(),
}, },
), ),
AirNowEntityDescription( AirNowEntityDescription(

View File

@ -8,6 +8,7 @@
'DateObserved': '2020-12-20', 'DateObserved': '2020-12-20',
'HourObserved': 15, 'HourObserved': 15,
'Latitude': '**REDACTED**', 'Latitude': '**REDACTED**',
'LocalTimeZone': 'PST',
'Longitude': '**REDACTED**', 'Longitude': '**REDACTED**',
'O3': 0.048, 'O3': 0.048,
'PM10': 12, 'PM10': 12,