From 3f5c0a1285d865d4a472ba569f9d44f8dab501b5 Mon Sep 17 00:00:00 2001 From: Pedro Lamas Date: Tue, 1 Aug 2023 10:04:30 +0100 Subject: [PATCH] Fixes London Air parsing error (#97557) --- homeassistant/components/london_air/sensor.py | 10 ++++++---- tests/fixtures/london_air.json | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/london_air/sensor.py b/homeassistant/components/london_air/sensor.py index e970f040b5f137..98cc4c4b4e80a4 100644 --- a/homeassistant/components/london_air/sensor.py +++ b/homeassistant/components/london_air/sensor.py @@ -218,10 +218,12 @@ def parse_api_response(response): for authority in AUTHORITIES: for entry in response["HourlyAirQualityIndex"]["LocalAuthority"]: if entry["@LocalAuthorityName"] == authority: - if isinstance(entry["Site"], dict): - entry_sites_data = [entry["Site"]] - else: - entry_sites_data = entry["Site"] + entry_sites_data = [] + if "Site" in entry: + if isinstance(entry["Site"], dict): + entry_sites_data = [entry["Site"]] + else: + entry_sites_data = entry["Site"] data[authority] = parse_site(entry_sites_data) diff --git a/tests/fixtures/london_air.json b/tests/fixtures/london_air.json index 3a3d9afb643099..7045a90e6e9f6b 100644 --- a/tests/fixtures/london_air.json +++ b/tests/fixtures/london_air.json @@ -3,6 +3,14 @@ "@GroupName": "London", "@TimeToLive": "38", "LocalAuthority": [ + { + "@LocalAuthorityCode": "7", + "@LocalAuthorityName": "City of London", + "@LaCentreLatitude": "51.51333", + "@LaCentreLongitude": "-0.088947", + "@LaCentreLatitudeWGS84": "6712603.132989", + "@LaCentreLongitudeWGS84": "-9901.534748" + }, { "@LocalAuthorityCode": "24", "@LocalAuthorityName": "Merton",