Fix error is measurement is not sent by AirNow (#100477)

This commit is contained in:
J.P. Krauss 2023-09-16 09:16:15 -07:00 committed by GitHub
parent c8265a86b2
commit 01ecef7f05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -58,6 +58,16 @@ class AirNowEntityDescription(SensorEntityDescription, AirNowEntityDescriptionMi
"""Describes Airnow sensor entity.""" """Describes Airnow sensor entity."""
def station_extra_attrs(data: dict[str, Any]) -> dict[str, Any]:
"""Process extra attributes for station location (if available)."""
if ATTR_API_STATION in data:
return {
"lat": data.get(ATTR_API_STATION_LATITUDE),
"long": data.get(ATTR_API_STATION_LONGITUDE),
}
return {}
SENSOR_TYPES: tuple[AirNowEntityDescription, ...] = ( SENSOR_TYPES: tuple[AirNowEntityDescription, ...] = (
AirNowEntityDescription( AirNowEntityDescription(
key=ATTR_API_AQI, key=ATTR_API_AQI,
@ -93,10 +103,7 @@ SENSOR_TYPES: tuple[AirNowEntityDescription, ...] = (
translation_key="station", translation_key="station",
icon="mdi:blur", icon="mdi:blur",
value_fn=lambda data: data.get(ATTR_API_STATION), value_fn=lambda data: data.get(ATTR_API_STATION),
extra_state_attributes_fn=lambda data: { extra_state_attributes_fn=station_extra_attrs,
"lat": data[ATTR_API_STATION_LATITUDE],
"long": data[ATTR_API_STATION_LONGITUDE],
},
), ),
) )