Conversation
An unprovisioned device can report a clock far in the past (e.g. year 2000). When its timezone has to be guessed from the offset to the host time, the resulting delta is years long and timezone(offset) raises "offset must be a timedelta strictly between -timedelta(hours=24) and timedelta(hours=24)", which breaks update() and so every cli command. Real UTC offsets range from -12h to +14h, so treat anything beyond that as an unset clock and use UTC instead of guessing. Fixes python-kasa#1767 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1768 +/- ##
=======================================
Coverage 93.31% 93.31%
=======================================
Files 158 158
Lines 9977 9980 +3
Branches 1025 1026 +1
=======================================
+ Hits 9310 9313 +3
Misses 472 472
Partials 195 195 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rytilahti
approved these changes
Sep 29, 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.
Fixes #1767
What was wrong
A new or factory-reset iot device can report a clock far in the past, e.g. year 2000. When the iot
Timemodule can't use the configured zone index,_post_update_hookguesses a timezone from the difference between the device clock and host time. With an unset clock that difference is about 26 years. The last-resorttimezone(offset)in_guess_timezone_by_offsetthen raises:That exception breaks
update(), so every cli command fails, includingwifi scanandwifi join, which are the commands needed to provision the device.Fix
In
kasa/iot/modules/time.py, if the rounded delta is outside the range of real UTC offsets (-12h to +14h), treat the clock as unset and use UTC instead of guessing. The regular path, where the zone index resolves, is unchanged.Testing
test_time_post_update_unsynced_clock_uses_utcintests/test_common_modules.py. It runs over all iot device fixtures (@device_iot), sets the fake device'sget_timeto 2000-01-01 and forces the offset-based path. Without the fix, all 85 cases fail with theValueErrorfrom the issue. With the fix, they pass.uv run pytest -n auto: 23338 passed, 898 skippedpre-commit run --files kasa/iot/modules/time.py tests/test_common_modules.py: all hooks pass (ruff, ruff-format, mypy, etc.)I don't have an HS103 to test on, so I haven't confirmed provisioning end to end on real hardware.
Drafted with Claude Code; I reviewed the change and ran the tests myself.
🤖 Generated with Claude Code