Skip to content

Commit

Permalink
Check supported_features to identify legacy/modern weather
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Kissling authored and pkissling committed Nov 30, 2023
1 parent 6daeb5a commit a5ceef2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/clock-weather-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export class ClockWeatherCard extends LitElement {
}

private mergeForecasts (maxRowsCount: number, hourly: boolean): MergedWeatherForecast[] {
const forecasts = this.getWeather().attributes.forecast ?? this.forecasts ?? []
const forecasts = this.isLegacyWeather() ? this.getWeather().attributes.forecast ?? [] : this.forecasts ?? []
const agg = forecasts.reduce<Record<number, WeatherForecast[]>>((forecasts, forecast) => {
const d = new Date(forecast.datetime)
const unit = hourly ? `${d.getMonth()}-${d.getDate()}-${+d.getHours()}` : d.getDate()
Expand Down Expand Up @@ -616,7 +616,7 @@ export class ClockWeatherCard extends LitElement {
}

private isLegacyWeather (): boolean {
return (this.getWeather().attributes.forecast?.length ?? 0) > 0
return !this.supportsFeature(WeatherEntityFeature.FORECAST_DAILY) && !this.supportsFeature(WeatherEntityFeature.FORECAST_HOURLY)
}

private supportsFeature (feature: WeatherEntityFeature): boolean {
Expand Down

0 comments on commit a5ceef2

Please sign in to comment.