Skip to content

Commit

Permalink
Align changes from version 0.34.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh committed Oct 10, 2024
1 parent 1e5d779 commit 25b0b1e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions custom_components/ims/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"documentation": "https://github.com/GuyKh/ims-custom-component",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/GuyKh/ims-custom-component/issues",
"requirements": ["weatheril>=0.33.0"],
"version": "0.1.28"
"requirements": ["weatheril>=0.34.0"],
"version": "0.1.29"
}
1 change: 0 additions & 1 deletion custom_components/ims/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
SENSOR_DESCRIPTIONS_KEYS = [desc.key for desc in SENSOR_DESCRIPTIONS]

weather = None
timezone = dt_util.get_time_zone('Asia/Jerusalem')

async def async_setup_platform(hass, config_entry, async_add_entities, discovery_info=None):
_LOGGER.warning(
Expand Down
6 changes: 2 additions & 4 deletions custom_components/ims/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ def round_if_needed(value: int | float, output_round: bool):
else:
return round(value, 2)

timezone = dt_util.get_time_zone('Asia/Jerusalem')

class IMSWeather(WeatherEntity):
"""Implementation of an IMSWeather sensor."""

Expand Down Expand Up @@ -243,7 +241,7 @@ def _forecast(self, hourly: bool) -> list[Forecast]:
data = [
Forecast(
condition=WEATHER_CODE_TO_CONDITION[daily_forecast.weather_code],
datetime=daily_forecast.date.astimezone(pytz.UTC).isoformat(),
datetime=daily_forecast.date.isoformat(),
native_temperature=daily_forecast.maximum_temperature,
native_templow=daily_forecast.minimum_temperature
) for daily_forecast in self._weather_coordinator.data.forecast.days
Expand All @@ -262,7 +260,7 @@ def _forecast(self, hourly: bool) -> list[Forecast]:
data.append(
Forecast(
condition=WEATHER_CODE_TO_CONDITION[hourly_weather_code],
datetime=hourly_forecast.forecast_time.astimezone(timezone).isoformat(),
datetime=hourly_forecast.forecast_time.isoformat(),
native_temperature=hourly_forecast.precise_temperature,
native_templow=daily_forecast.minimum_temperature,
native_precipitation=hourly_forecast.rain,
Expand Down
9 changes: 6 additions & 3 deletions custom_components/ims/weather_update_coordinator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Weather data coordinator for the OpenWeatherMap (OWM) service."""
import asyncio
import logging
from datetime import timedelta, date, datetime
import homeassistant.util.dt as dt_util

from datetime import timedelta

from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from weatheril import WeatherIL
Expand All @@ -14,6 +16,7 @@

ATTRIBUTION = "Powered by IMS Weather"

timezone = dt_util.get_time_zone("Asia/Jerusalem")

class WeatherUpdateCoordinator(DataUpdateCoordinator):
"""Weather data update coordinator."""
Expand Down Expand Up @@ -64,14 +67,14 @@ async def _get_ims_weather(self):
@staticmethod
def _filter_future_forecast(weather_forecast):
""" Filter Forecast to include only future dates """
today_datetime = datetime.fromordinal(date.today().toordinal())
today_datetime = dt_util.start_of_local_day(timezone)
filtered_day_list = list(filter(lambda daily: daily.date >= today_datetime, weather_forecast.days))

for daily_forecast in filtered_day_list:
filtered_hours = []
for hourly_forecast in daily_forecast.hours:
forecast_datetime = daily_forecast.date + timedelta(hours=int(hourly_forecast.hour.split(":")[0]))
if datetime.now() <= forecast_datetime:
if dt_util.now(timezone) <= forecast_datetime:
filtered_hours.append(hourly_forecast)
daily_forecast.hours = filtered_hours

Expand Down

0 comments on commit 25b0b1e

Please sign in to comment.