Skip to content

Commit

Permalink
Added cardsize method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcokreeft87 committed Dec 20, 2022
1 parent 5d4585f commit 7bd567a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/cards/base-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ export abstract class BaseCard {
}

abstract render() : HTMLTemplateResult;

abstract cardSize() : number;
}
4 changes: 4 additions & 0 deletions src/cards/constructor-standings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export default class ConstructorStandings extends BaseCard {
constructor(sensor: string, hass: HomeAssistant, config: FormulaOneCardConfig) {
super(sensor, hass, config);
}

cardSize(): number {
throw new Error("Method not implemented.");
}

renderStandingRow(standing: ConstructorStanding): HTMLTemplateResult {
return html`
Expand Down
4 changes: 4 additions & 0 deletions src/cards/driver-standings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default class DriverStandings extends BaseCard {
constructor(sensor: string, hass: HomeAssistant, config: FormulaOneCardConfig) {
super(sensor, hass, config);
}

cardSize(): number {
throw new Error("Method not implemented.");
}

getCountryFlag = (nationality: string) => {
const country = countries.filter(x => x.Nationality === nationality)[0].Country;
Expand Down
6 changes: 5 additions & 1 deletion src/cards/last-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export default class LastResult extends BaseCard {

constructor(sensor: string, hass: HomeAssistant, config: FormulaOneCardConfig) {
super(sensor, hass, config);
}
}

cardSize(): number {
throw new Error("Method not implemented.");
}

renderResultRow(result: Result): HTMLTemplateResult {

Expand Down
6 changes: 5 additions & 1 deletion src/cards/next-race.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export default class NextRace extends BaseCard {
const sensorEntity = this.hass.states[this.sensor_entity_id];

this.next_race = sensorEntity.attributes['next_race'] as Race;
}
}

cardSize(): number {
throw new Error("Method not implemented.");
}

renderHeader(): HTMLTemplateResult {

Expand Down
6 changes: 5 additions & 1 deletion src/cards/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ export default class Schedule extends BaseCard {
const sensorEntity = this.hass.states[this.sensor_entity_id];

this.next_race = sensorEntity.attributes['next_race'] as Race;
}
}

cardSize(): number {
throw new Error("Method not implemented.");
}

renderSeasonEnded(): HTMLTemplateResult {
return html`<table><tr><td class="text-center"><strong>Season is over. See you next year!</strong></td></tr></table>`;
Expand Down
24 changes: 19 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DriverStandings from './cards/driver-standings';
import Schedule from './cards/schedule';
import NextRace from './cards/next-race';
import LastResult from './cards/last-result';
import { BaseCard } from './cards/base-card';

console.info(
`%c FORMULAONE-CARD %c ${packageJson.version}`,
Expand All @@ -31,6 +32,7 @@ console.info(
export default class FormulaOneCard extends LitElement {
@property() _hass?: HomeAssistant;
@property() config?: FormulaOneCardConfig;
@property() card: BaseCard;

setConfig(config: FormulaOneCardConfig) {

Expand All @@ -54,18 +56,26 @@ export default class FormulaOneCard extends LitElement {
}

renderCardType(): HTMLTemplateResult {
let card: BaseCard;
switch(this.config.card_type) {
case FormulaOneCardType.ConstructorStandings:
return new ConstructorStandings(this.config.sensor, this._hass, this.config).render();
card = new ConstructorStandings(this.config.sensor, this._hass, this.config);
break;
case FormulaOneCardType.DriverStandings:
return new DriverStandings(this.config.sensor, this._hass, this.config).render();
card = new DriverStandings(this.config.sensor, this._hass, this.config);
break;
case FormulaOneCardType.Schedule:
return new Schedule(this.config.sensor, this._hass, this.config).render();
card = new Schedule(this.config.sensor, this._hass, this.config);
break;
case FormulaOneCardType.NextRace:
return new NextRace(this.config.sensor, this._hass, this.config).render();
card = new NextRace(this.config.sensor, this._hass, this.config);
break;
case FormulaOneCardType.LastResult:
return new LastResult(this.config.sensor, this._hass, this.config).render();
card = new LastResult(this.config.sensor, this._hass, this.config);
break;
}

return card.render();
}

render() : HTMLTemplateResult {
Expand All @@ -82,4 +92,8 @@ export default class FormulaOneCard extends LitElement {
return html`<hui-warning>${error.toString()}</hui-warning>`;
}
}

getCardSize() {
return this.card.cardSize();
}
}

0 comments on commit 7bd567a

Please sign in to comment.