Skip to content

Commit

Permalink
fix[weather::forecasts]: add timezone to forecasts datetime
Browse files Browse the repository at this point in the history
Fix i98
  • Loading branch information
IATkachenko committed Apr 7, 2024
1 parent 9d63cbc commit 6c02747
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions custom_components/yandex_weather/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.util.dt import get_time_zone

from .const import (
ATTR_API_CONDITION,
Expand Down Expand Up @@ -229,7 +230,7 @@ def get_timezone(nows: str, nowi: int) -> timezone:
microsecond=0
)
server_unix_time = datetime.fromtimestamp(nowi)
return timezone(server_utc_time - server_unix_time)
return timezone(server_unix_time - server_utc_time)

async def update(self):
"""Update weather information.
Expand All @@ -238,23 +239,23 @@ async def update(self):
"""
result = {}
timeout = aiohttp.ClientTimeout(total=20)
local_tz = get_time_zone(self.hass.config.time_zone)
async with aiohttp.ClientSession(timeout=timeout) as session:
response = await self.request(
session, self.__api_key, self._lat, self._lon, "en_US"
)
r = json.loads(response)

result = {
ATTR_API_WEATHER_TIME: datetime.fromtimestamp(
r["fact"][ATTR_API_WEATHER_TIME],
tz=self.get_timezone(r["now_dt"], r["now"]),
),
).astimezone(tz=local_tz),
ATTR_API_FORECAST_ICONS: [],
ATTR_FORECAST_DATA: [],
}
self.process_data(result, r["fact"], CURRENT_WEATHER_ATTRIBUTE_TRANSLATION)

f_datetime = datetime.utcnow()
f_datetime = datetime.now(tz=local_tz)
for f in r["forecast"]["parts"]:
f_datetime += timedelta(hours=24 / 4)
forecast = Forecast(datetime=f_datetime.isoformat())
Expand Down

0 comments on commit 6c02747

Please sign in to comment.