Skip to content

Commit

Permalink
Added sprint results and moved qualifying to tab in results card (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcokreeft87 authored Feb 5, 2023
1 parent ef84921 commit ad3cfb0
Show file tree
Hide file tree
Showing 20 changed files with 625 additions and 634 deletions.
46 changes: 16 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,13 @@ f1_font: true
```
![image](https://user-images.githubusercontent.com/10223677/215340692-898a03ef-2f66-46fd-92da-6e842d413500.png)
```
type: custom:formulaone-card
card_type: qualifying_results
title: Qualifying
f1_font: true

```
![image](https://user-images.githubusercontent.com/10223677/216780167-df1cd864-9c54-47fe-afed-cb0c6b4cd4bb.png)
This card can also show the flags and team names of the driver, alongside the logo of the teams:
```
type: custom:formulaone-card
card_type: qualifying_results
standings:
show_flag: true
show_team: true
show_teamlogo: true

```
## Icons
The following icons can be altered.
| Card type(s) | Key | Default value |
| ----------------------------------- | ------------- | ----------------------------------- |
| results | results | mdi:trophy |
| results | qualifying | mdi:timer-outline |
| results | sprint | mdi:flag-checkered |
## Translations
Expand All @@ -249,16 +234,17 @@ The following texts can be translated or altered.
| constructor_standings | constructor | 'Constructor' |
| constructor_standings, driver_standings, last_result | points | 'Pts' |
| constructor_standings, driver_standings | wins | 'Wins' |
| driver_standings, results, qualifying_results | team | 'Team' |
| driver_standings, last_result, results, qualifying_results | driver | 'Driver' |
| driver_standings, results | team | 'Team' |
| driver_standings, last_result, results | driver | 'Driver' |
| last_result | grid | 'Grid' |
| last_result | status | 'Status' |
| schedule | time | 'Time' |
| results,qualifying_results | raceheader | 'Race' |
| results.qualifying_results | seasonheader | 'Season' |
| results,qualifying_results | selectseason | 'Select season' |
| results,qualifying_results | selectrace | 'Select race' |
| results,qualifying_results | noresults | 'Please select a race thats already been run' |
| results | raceheader | 'Race' |
| results | seasonheader | 'Season' |
| results | selectseason | 'Select season' |
| results | selectrace | 'Select race' |
| results | noresults | 'Please select a race thats already been run' |
| results | nosprint | 'No sprint race results available.' |
| countdown | days | 'd' |
| countdown | hours' : 'h' |
| countdown | minutes' : 'm' |
Expand Down Expand Up @@ -291,7 +277,7 @@ translations:
## TODO
- [x] Convert Ergast client to use fetch to reduce library size
- [x] Qualifying result card (https://ergast.com/mrd/methods/qualifying/)
- [ ] Sprint result card (https://ergast.com/mrd/methods/sprint/)
- [x] Sprint result card (https://ergast.com/mrd/methods/sprint/)
- [ ] Live timing poc (https://livetiming.formula1.com/static/2022/2022-11-20_Abu_Dhabi_Grand_Prix/2022-11-20_Race/RaceControlMessages.json)
- [x] Use F1 font
- [ ] Editor
212 changes: 118 additions & 94 deletions formulaone-card.js

Large diffs are not rendered by default.

Binary file modified formulaone-card.js.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formulaone-card",
"version": "0.9.1",
"version": "1.0.0",
"description": "Frontend card for Home Assistant to display Formula One data",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/api/ergast-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export default class ErgastClient {
return data?.MRData.StandingsTable.StandingsLists[0].ConstructorStandings;
}

async GetSprintResults(season: number, round: number) : Promise<RaceTable> {
const data = await this.GetData<Root>(`${season}/${round}/sprint.json`, false, 0);

return data?.MRData.RaceTable;
}

async GetQualifyingResults(season: number, round: number) : Promise<RaceTable> {
const data = await this.GetData<Root>(`${season}/${round}/qualifying.json`, false, 0);

Expand Down
11 changes: 6 additions & 5 deletions src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface Root {
time: string
Results?: Result[]
QualifyingResults?: QualifyingResult[]
SprintResults?: Result[]
FirstPractice: FirstPractice
SecondPractice: SecondPractice
ThirdPractice?: ThirdPractice
Expand Down Expand Up @@ -92,11 +93,11 @@ export interface Root {
status: string
Time?: Time
FastestLap: FastestLap
FirstPractice: FirstPractice
SecondPractice: SecondPractice
ThirdPractice?: ThirdPractice
Qualifying: Qualifying
Sprint?: Sprint
// FirstPractice: FirstPractice
// SecondPractice: SecondPractice
// ThirdPractice?: ThirdPractice
// Qualifying: Qualifying
// Sprint?: Sprint
}

export interface QualifyingResult {
Expand Down
3 changes: 2 additions & 1 deletion src/cards/base-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export abstract class BaseCard {
const races = cardProperties?.races as Race[];
const selectedRace = cardProperties?.selectedRace as Race;
const selectedSeason = cardProperties?.selectedSeason as string;
return { races, selectedRace, selectedSeason };
const selectedTabIndex = cardProperties?.selectedTabIndex as number ?? 0;
return { races, selectedRace, selectedSeason, selectedTabIndex };
}

protected getParentCardValues() {
Expand Down
159 changes: 0 additions & 159 deletions src/cards/qualifying-results.ts

This file was deleted.

Loading

0 comments on commit ad3cfb0

Please sign in to comment.