Fix airnow timezone look up (#120136)

This commit is contained in:
Indu Prakash 2024-06-22 10:31:39 -05:00 committed by GitHub
parent cdc157de74
commit 65a740f35e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 10 deletions

View File

@ -14,6 +14,7 @@ ATTR_API_POLLUTANT = "Pollutant"
ATTR_API_REPORT_DATE = "DateObserved"
ATTR_API_REPORT_HOUR = "HourObserved"
ATTR_API_REPORT_TZ = "LocalTimeZone"
ATTR_API_REPORT_TZINFO = "LocalTimeZoneInfo"
ATTR_API_STATE = "StateCode"
ATTR_API_STATION = "ReportingArea"
ATTR_API_STATION_LATITUDE = "Latitude"

View File

@ -12,6 +12,7 @@ from pyairnow.errors import AirNowError
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util import dt as dt_util
from .const import (
ATTR_API_AQI,
@ -26,6 +27,7 @@ from .const import (
ATTR_API_REPORT_DATE,
ATTR_API_REPORT_HOUR,
ATTR_API_REPORT_TZ,
ATTR_API_REPORT_TZINFO,
ATTR_API_STATE,
ATTR_API_STATION,
ATTR_API_STATION_LATITUDE,
@ -96,7 +98,9 @@ class AirNowDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
# Copy Report Details
data[ATTR_API_REPORT_DATE] = obv[ATTR_API_REPORT_DATE]
data[ATTR_API_REPORT_HOUR] = obv[ATTR_API_REPORT_HOUR]
data[ATTR_API_REPORT_TZ] = obv[ATTR_API_REPORT_TZ]
data[ATTR_API_REPORT_TZINFO] = await dt_util.async_get_time_zone(
obv[ATTR_API_REPORT_TZ]
)
# Copy Station Details
data[ATTR_API_STATE] = obv[ATTR_API_STATE]

View File

@ -23,7 +23,6 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.dt import get_time_zone
from . import AirNowConfigEntry, AirNowDataUpdateCoordinator
from .const import (
@ -35,7 +34,7 @@ from .const import (
ATTR_API_PM25,
ATTR_API_REPORT_DATE,
ATTR_API_REPORT_HOUR,
ATTR_API_REPORT_TZ,
ATTR_API_REPORT_TZINFO,
ATTR_API_STATION,
ATTR_API_STATION_LATITUDE,
ATTR_API_STATION_LONGITUDE,
@ -84,7 +83,7 @@ SENSOR_TYPES: tuple[AirNowEntityDescription, ...] = (
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]))
.replace(tzinfo=data[ATTR_API_REPORT_TZINFO])
.isoformat(),
},
),

View File

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

View File

@ -1,5 +1,7 @@
"""Test AirNow diagnostics."""
from unittest.mock import patch
import pytest
from syrupy import SnapshotAssertion
@ -18,8 +20,14 @@ async def test_entry_diagnostics(
snapshot: SnapshotAssertion,
) -> None:
"""Test config entry diagnostics."""
assert await hass.config_entries.async_setup(config_entry.entry_id)
assert (
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
== snapshot
)
# Fake LocalTimeZoneInfo
with patch(
"homeassistant.util.dt.async_get_time_zone",
return_value="PST",
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
assert (
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
== snapshot
)