Fix weather entities with update_before_add (#97950)

Fix weather entities update_before_add
This commit is contained in:
G Johansson
2023-08-07 09:42:20 +02:00
committed by GitHub
parent 56257b7a38
commit 001dda6345

View File

@@ -1048,6 +1048,12 @@ class WeatherEntity(Entity):
self, forecast_types: Iterable[Literal["daily", "hourly", "twice_daily"]] | None
) -> None:
"""Push updated forecast to all listeners."""
if not hasattr(self, "_forecast_listeners"):
# Required for entities initiated with `update_before_add`
# as `self._forecast_listeners` has not yet been set.
# `async_internal_added_to_hass()` will execute once entity has been added.
return
if forecast_types is None:
forecast_types = {"daily", "hourly", "twice_daily"}
for forecast_type in forecast_types: