Skip to content

Commit

Permalink
chore: replace pytz with ZoneInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
delphiki committed Dec 12, 2024
1 parent d041cfe commit bd7992f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions custom_components/pronote/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
from homeassistant.util.dt import get_time_zone
import pytz
from zoneinfo import ZoneInfo

from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .coordinator import PronoteDataUpdateCoordinator
Expand All @@ -32,7 +32,7 @@ async def async_setup_entry(
@callback
def async_get_calendar_event_from_lessons(lesson, timezone) -> CalendarEvent:
"""Get a HASS CalendarEvent from a Pronote Lesson."""
tz = pytz.timezone(timezone)
tz = ZoneInfo(timezone)

lesson_name = format_displayed_lesson(lesson)
if lesson.canceled:
Expand All @@ -42,8 +42,8 @@ def async_get_calendar_event_from_lessons(lesson, timezone) -> CalendarEvent:
summary=lesson_name,
description=f"{lesson.teacher_name} - Salle {lesson.classroom}",
location=f"Salle {lesson.classroom}",
start=tz.localize(lesson.start),
end=tz.localize(lesson.end),
start=lesson.start.replace(tzinfo=tz),
end=lesson.end.replace(tzinfo=tz),
)


Expand Down
6 changes: 3 additions & 3 deletions custom_components/pronote/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .pronote_helper import *
from .pronote_formatter import *
import re
import pytz
from zoneinfo import ZoneInfo

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
Expand Down Expand Up @@ -210,7 +210,7 @@ async def _async_update_data(self) -> dict[Platform, dict[str, Any]]:
_LOGGER.info("Error getting lessons_next_day from pronote: %s", ex)

next_alarm = None
tz = pytz.timezone(self.hass.config.time_zone)
tz = ZoneInfo(self.hass.config.time_zone)
today_start_at = get_day_start_at(self.data["lessons_today"])
next_day_start_at = get_day_start_at(self.data["lessons_next_day"])
if today_start_at or next_day_start_at:
Expand All @@ -224,7 +224,7 @@ async def _async_update_data(self) -> dict[Platform, dict[str, Any]]:
if next_alarm is None and next_day_start_at is not None:
next_alarm = next_day_start_at - timedelta(minutes=alarm_offset)
if next_alarm is not None:
next_alarm = tz.localize(next_alarm)
next_alarm = next_alarm.replace(tzinfo=tz)

self.data["next_alarm"] = next_alarm

Expand Down

0 comments on commit bd7992f

Please sign in to comment.