diff --git a/custom_components/ims/manifest.json b/custom_components/ims/manifest.json index e330f02..e3b946a 100644 --- a/custom_components/ims/manifest.json +++ b/custom_components/ims/manifest.json @@ -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" } diff --git a/custom_components/ims/sensor.py b/custom_components/ims/sensor.py index 5301b13..220848b 100644 --- a/custom_components/ims/sensor.py +++ b/custom_components/ims/sensor.py @@ -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( diff --git a/custom_components/ims/weather.py b/custom_components/ims/weather.py index 4012026..20c55e1 100644 --- a/custom_components/ims/weather.py +++ b/custom_components/ims/weather.py @@ -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.""" @@ -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 @@ -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, diff --git a/custom_components/ims/weather_update_coordinator.py b/custom_components/ims/weather_update_coordinator.py index 71aeca9..873bb7b 100644 --- a/custom_components/ims/weather_update_coordinator.py +++ b/custom_components/ims/weather_update_coordinator.py @@ -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 @@ -14,6 +16,7 @@ ATTRIBUTION = "Powered by IMS Weather" +timezone = dt_util.get_time_zone("Asia/Jerusalem") class WeatherUpdateCoordinator(DataUpdateCoordinator): """Weather data update coordinator.""" @@ -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