From 99065a689fda336a984bf1da21b22a3e6c7ecb39 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Tue, 11 Feb 2025 22:39:46 -0800 Subject: [PATCH] Retry subscribing to weather forecast if it fails (#24188) --- .../lovelace/cards/hui-weather-forecast-card.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/panels/lovelace/cards/hui-weather-forecast-card.ts b/src/panels/lovelace/cards/hui-weather-forecast-card.ts index 080900d407..6050ef428d 100644 --- a/src/panels/lovelace/cards/hui-weather-forecast-card.ts +++ b/src/panels/lovelace/cards/hui-weather-forecast-card.ts @@ -37,6 +37,7 @@ import type { LovelaceGridOptions, } from "../types"; import type { WeatherForecastCardConfig } from "./types"; +import { isComponentLoaded } from "../../../common/config/is_component_loaded"; @customElement("hui-weather-forecast-card") class HuiWeatherForecastCard extends LitElement implements LovelaceCard { @@ -106,7 +107,9 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard { !this.isConnected || !this.hass || !this._config || - !this._needForecastSubscription() + !this._needForecastSubscription() || + !isComponentLoaded(this.hass, "weather") || + !this.hass.states[this._config!.entity] ) { return; } @@ -118,7 +121,14 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard { (event) => { this._forecastEvent = event; } - ); + ).catch((e) => { + if (e.code === "invalid_entity_id") { + setTimeout(() => { + this._subscribed = undefined; + }, 2000); + } + throw e; + }); } public connectedCallback(): void {