Skip to content

Commit

Permalink
Merge pull request #1338 from dasadi/bugfix/weather-entity
Browse files Browse the repository at this point in the history
Replace deprecated weather forecast with new service call
  • Loading branch information
KartoffelToby committed Apr 24, 2024
2 parents 1d25c94 + 29e152e commit 219838f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion custom_components/better_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ async def _trigger_check_weather(self, event=None):
_check = await check_all_entities(self)
if _check is False:
return
check_weather(self)
await check_weather(self)
if self._last_call_for_heat != self.call_for_heat:
self._last_call_for_heat = self.call_for_heat
await self.async_update_ha_state(force_refresh=True)
Expand Down
15 changes: 11 additions & 4 deletions custom_components/better_thermostat/utils/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
_LOGGER = logging.getLogger(__name__)


def check_weather(self) -> bool:
async def check_weather(self) -> bool:
"""check weather predictions or ambient air temperature if available
Parameters
Expand All @@ -37,7 +37,7 @@ def check_weather(self) -> bool:
self.call_for_heat = True

if self.weather_entity is not None:
_call_for_heat_weather = check_weather_prediction(self)
_call_for_heat_weather = await check_weather_prediction(self)
self.call_for_heat = _call_for_heat_weather

if self.outdoor_sensor is not None:
Expand All @@ -63,7 +63,7 @@ def check_weather(self) -> bool:
return False


def check_weather_prediction(self) -> bool:
async def check_weather_prediction(self) -> bool:
"""Checks configured weather entity for next two days of temperature predictions.
Returns
Expand All @@ -84,7 +84,14 @@ def check_weather_prediction(self) -> bool:
return None

try:
forecast = self.hass.states.get(self.weather_entity).attributes.get("forecast")
forecasts = await self.hass.services.async_call(
"weather",
"get_forecasts",
{"type": "daily", "entity_id": self.weather_entity},
blocking=True,
return_response=True,
)
forecast = forecasts.get(self.weather_entity).get("forecast")
if len(forecast) > 0:
cur_outside_temp = convert_to_float(
str(
Expand Down

0 comments on commit 219838f

Please sign in to comment.