Replace pytz with stdlib zoneinfo#2077
Merged
Merged
Conversation
zoneinfo is available since Python 3.9 (now minimum), so pytz is no longer needed. Replace pytz.timezone() with ZoneInfo() and timezone.localize() with .replace(tzinfo=). Add tests for Timer timezone handling and configure_wifi gmt_offset calculation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2077 +/- ##
==========================================
+ Coverage 83.29% 83.49% +0.19%
==========================================
Files 199 199
Lines 19475 19519 +44
Branches 1058 1058
==========================================
+ Hits 16222 16297 +75
+ Misses 3071 3036 -35
- Partials 182 186 +4 ☔ View full report in Codecov by Harness. |
rytilahti
approved these changes
Jun 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1825
Summary
pytzdependency frompyproject.tomlpytz.timezone()withZoneInfo()from stdlibzoneinfomodule (Python 3.9+, now project minimum)timezone.localize(dt)(pytz-specific) withdt.replace(tzinfo=timezone)(standard)BaseTzInfotype annotation toZoneInfoTests
New tests in
TestVacuum:test_timer_with_timezone— Timer parses cron and returns a timezone-awarenext_scheduletest_timer_disabled— Timer respectsoffstatetest_timer_ts— Timer creation timestamp is parsed from unix IDtest_timer_ts_non_numeric_id— Non-numeric timer IDs (e.g. valetudo) returnNonefortstest_timer_list—vacuum.timer()builds Timer objects viaZoneInfotest_configure_wifi_with_timezone— UTC offset is 0.0 for UTCtest_configure_wifi_with_offset_timezone— UTC offset is 8.0 for Asia/ShanghaiAll 47 tests pass.