Skip to content

Commit

Permalink
Added sprintqualifying to countdown and fix for Austin
Browse files Browse the repository at this point in the history
  • Loading branch information
marcokreeft87 committed Sep 25, 2024
1 parent 30546e8 commit 2f4eb5f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ or added by clicking the "Add to lovelace" button on the HACS dashboard after in
| translations | dictionary | _[translations](#Translations)_ | Dictionary to override the default translation |
| actions | object | _[Actions](#actions)_ | The tap, double tap or hold actions set on the image of the countdown, last_result, results, qualifying_results and next-race cards |
| row_limit | number | | Limit the schedule, results, last_result, driver_standings and constructor_standings to this amount of row |
| countdown_type | string or array | 'race' | Set the event to countdown to (race,qualifying,practice1,practice2,practice3,sprint) |
| countdown_type | string or array | 'race' | Set the event to countdown to (race,qualifying,practice1,practice2,practice3,sprint,sprintqualifying) |
| show_weather | boolean | `false` | Show the _[weather forecast](#Forecast)_ of the upcoming race |
| next_race_delay | number | | Delay (in hours) before the card switches to the next race |
| show_lastyears_result | boolean | `false` | Show the winner of last year (next_race, countdown) |
Expand Down Expand Up @@ -262,6 +262,7 @@ The following texts can be translated or altered.
| next_race, countdown | city | 'City' |
| next_race, countdown | sprint | 'Sprint' |
| next_race, countdown | qualifying | 'Qualifying' |
| next_race, countdown | sprintqualifying : 'Sprint Qualifying' |
| next_race, countdown, schedule | endofseason | 'Season is over. See you next year!' |
| constructor_standings | constructor | 'Constructor' |
| constructor_standings, driver_standings, last_result | points | 'Pts' |
Expand Down
2 changes: 1 addition & 1 deletion formulaone-card.js

Large diffs are not rendered by default.

Binary file modified formulaone-card.js.gz
Binary file not shown.
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": "1.9.5",
"version": "1.9.6",
"description": "Frontend card for Home Assistant to display Formula One data",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/api/f1-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface Root {
ThirdPractice?: ThirdPractice
Qualifying?: Qualifying
Sprint?: Sprint
SprintQualifying?: Qualifying
}

export interface Circuit {
Expand Down
9 changes: 6 additions & 3 deletions src/cards/countdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class Countdown extends BaseCard {
'racetime' : 'Race',
'sprint' : 'Sprint',
'qualifying' : 'Qualifying',
'sprintqualifying' : 'Sprint Qualifying',
'until' : 'Until'
};

Expand Down Expand Up @@ -139,16 +140,18 @@ export default class Countdown extends BaseCard {
const countdownTypes = this.config.countdown_type as CountdownType[];

const raceEvents = [
{ Date: new Date(nextRace.FirstPractice.date + 'T' + nextRace.FirstPractice.time), Type: CountdownType.Practice1 },
{ Date: new Date(nextRace.SecondPractice.date + 'T' + nextRace.SecondPractice.time), Type: CountdownType.Practice2 },
{ Date: nextRace.FirstPractice ? new Date(nextRace.FirstPractice.date + 'T' + nextRace.FirstPractice.time) : null, Type: CountdownType.Practice1 },
{ Date: nextRace.SecondPractice ? new Date(nextRace.SecondPractice.date + 'T' + nextRace.SecondPractice.time) : null, Type: CountdownType.Practice2 },
{ Date: nextRace.ThirdPractice ? new Date(nextRace.ThirdPractice.date + 'T' + nextRace.ThirdPractice.time) : null, Type: CountdownType.Practice3 },
{ Date: nextRace.Sprint ? new Date(nextRace.Sprint.date + 'T' + nextRace.Sprint.time) : null, Type: CountdownType.Sprint },
{ Date: new Date(nextRace.Qualifying.date + 'T' + nextRace.Qualifying.time), Type: CountdownType.Qualifying },
{ Date: nextRace.SprintQualifying ? new Date(nextRace.SprintQualifying.date + 'T' + nextRace.SprintQualifying.time) : null, Type: CountdownType.SprintQualifying },
{ Date: nextRace.Qualifying ? new Date(nextRace.Qualifying.date + 'T' + nextRace.Qualifying.time) : null, Type: CountdownType.Qualifying },
{ Date: new Date(nextRace.date + 'T' + nextRace.time), Type: CountdownType.Race }
].filter(x => x.Date).filter(x => x.Date > new Date()).sort((a, b) => a.Date.getTime() - b.Date.getTime());

// Get the first countdown type that occurs in race events and get the date and time for that event
const nextEvent = raceEvents.filter(x => countdownTypes?.includes(x.Type))[0];

raceDateTime = nextEvent?.Date;
countdownType = nextEvent?.Type ?? countdownType;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cards/next-race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default class NextRace extends BaseCard {
'city': 'City',
'racetime' : 'Race',
'sprint' : 'Sprint',
'qualifying' : 'Qualifying',
'qualifying' : 'Qualifying',
'sprintqualifying' : 'Sprint Qualifying',
'endofseason' : 'Season is over. See you next year!',
};

Expand Down
5 changes: 3 additions & 2 deletions src/types/formulaone-card-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface FormulaOneCardConfig extends LovelaceCardConfig {
only_show_date?: boolean;
tabs_order?: string[];
show_refresh?: boolean;
next_race_display?: NextRaceDisplay;
next_race_display?: NextRaceDisplay | undefined;
}

export interface ValueChangedEvent {
Expand Down Expand Up @@ -78,7 +78,8 @@ export enum CountdownType {
Practice1 = "practice1",
Practice2 = "practice2",
Practice3 = "practice3",
Sprint = "sprint"
Sprint = "sprint",
SprintQualifying = "sprintqualifying"
}

export interface ActionOptions {
Expand Down
76 changes: 74 additions & 2 deletions tests/cards/next-race.test.ts

Large diffs are not rendered by default.

0 comments on commit 2f4eb5f

Please sign in to comment.