Fix SMARTCAM Time module and update tests#1659
Fix SMARTCAM Time module and update tests#1659ZeliardM wants to merge 12 commits intopython-kasa:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the SmartCam Time module's set_time method to properly set the device time manually. The fix addresses three key issues: formatting local_time in UTC (not machine local time), removing microseconds from the timestamp format, and switching timing_mode from "ntp" to "manual" so devices accept manual time updates.
Changes:
- Fixed time formatting to use UTC without microseconds (format: 'YYYY-MM-DD HH:MM:SS')
- Added logic to set timing_mode to "manual" before updating clock_status (for devices that support it)
- Combined zone_id and timing_mode updates into a single API call for efficiency
- Added comprehensive unit tests covering all device types (cameras with timing_mode, hubs without timing_mode)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| kasa/smartcam/modules/time.py | Rewrote set_time method to format time in UTC, set timing_mode to manual, and handle devices without timing_mode field |
| tests/test_common_modules.py | Added three comprehensive unit tests verifying UTC formatting, ZoneInfo handling, and H200 hub compatibility |
| tests/fakeprotocol_smartcam.py | Fixed variable shadowing issue by renaming nested 'section' variable to 'section_data' |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1659 +/- ##
=======================================
Coverage 93.22% 93.23%
=======================================
Files 157 157
Lines 9815 9825 +10
Branches 1003 1004 +1
=======================================
+ Hits 9150 9160 +10
Misses 472 472
Partials 193 193 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Still working on the correct handling of the time zone information here. |
|
@rytilahti After further investigation, there appears no way for set_time to directly set the clock time on SMARTCAM devices. The set_time commands have been updated to correctly handle the timezone now and removed the sending of the seconds_from_1970 through the setTimezone function since it does nothing. Confirmed that this is all handled correctly now and that if the device is connected to the internet, it will pull the correct clock time via NTP. This should be good to go. |
|
@rytilahti Yea, I forgot to push the commit, lol I re-worked it yet again. Give it another once over and let me know if this looks cleaner. I made the changes to the fake_smartcamprotocol.py for the multiple calls issue in the tests. Then, modified the tests correctly in the test_smartcamdevice.py, added instance checks in the test_cli.py and test_common_modules.py to handle the specifics that the smartcam/modules/time.py only sets the timezone and not the time and modified those tests accordingly and to catch the warning in the test_common_module.py. This looks cleaner to me now as well but let me know if I'm still missing it. |
a1ea53b to
aef9930
Compare
This will update the SMARTCAM Time module so that manually setting the time will function correctly. An important note is that this turns off NTP time updating.