Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Handle if JSON is not filled yet #67

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion custom_components/formulaone_api/constructorsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ def get_race_data(self):

now = dt.now()
constructors = f1.constructor_standings(season=now.year).json
if constructors['MRData']['total'] == "0":
data = []
else:
data = constructors['MRData']['StandingsTable']['StandingsLists'][0]['ConstructorStandings']

# # Merge all attributes to a single dict.
all_attr = {
'last_update': now,
'data': constructors['MRData']['StandingsTable']['StandingsLists'][0]['ConstructorStandings']
'data': data
}

return all_attr
Expand Down
7 changes: 6 additions & 1 deletion custom_components/formulaone_api/driverssensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ def get_race_data(self):

now = dt.now()
drivers = f1.driver_standings(season=now.year).json
if drivers['MRData']['total'] == "0":
data = []
else:
data = drivers['MRData']['StandingsTable']['StandingsLists'][0]['DriverStandings']


# # Merge all attributes to a single dict.
all_attr = {
'last_update': now,
'data': drivers['MRData']['StandingsTable']['StandingsLists'][0]['DriverStandings']
'data': data
}

return all_attr
Expand Down