Skip to content

Commit

Permalink
Merge pull request #234 from dbiczo/dbiczo-patch-1
Browse files Browse the repository at this point in the history
Fix UV Forcast timezone error in sensor.py
  • Loading branch information
Makin-Things authored Jul 24, 2024
2 parents 1f1e406 + b8bbaf6 commit 188c288
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions custom_components/bureau_of_meteorology/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Platform for sensor integration."""
import logging
from datetime import datetime, tzinfo
from datetime import datetime, tzinfo, timezone
from typing import Any

import iso8601
Expand Down Expand Up @@ -338,9 +338,9 @@ def state(self):
)
else:
utc = timezone.utc
local = timezone(self.collector.locations_data["data"]["timezone"])
start_time = utc.localize(datetime.strptime(self.collector.daily_forecasts_data["data"][self.day]["uv_start_time"], "%Y-%m-%dT%H:%M:%SZ")).astimezone(local)
end_time = utc.localize(datetime.strptime(self.collector.daily_forecasts_data["data"][self.day]["uv_end_time"], "%Y-%m-%dT%H:%M:%SZ")).astimezone(local)
local = zoneinfo.ZoneInfo(self.collector.locations_data["data"]["timezone"])
start_time = datetime.strptime(self.collector.daily_forecasts_data["data"][self.day]["uv_start_time"], "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=utc).astimezone(local)
end_time = datetime.strptime(self.collector.daily_forecasts_data["data"][self.day]["uv_end_time"], "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=utc).astimezone(local)
return (
f'Sun protection recommended from {start_time.strftime("%-I:%M%p").lower()} to '
f'{end_time.strftime("%-I:%M%p").lower()}, UV Index predicted to reach '
Expand Down

0 comments on commit 188c288

Please sign in to comment.