Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated weather forecast with new service call #1338

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading