Skip to content

Commit

Permalink
Fixes London Air parsing error (home-assistant#97557)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrolamas authored Aug 1, 2023
1 parent 7e134a3 commit 3f5c0a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions homeassistant/components/london_air/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/london_air.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 3f5c0a1

Please sign in to comment.