Skip to content

Fix SMARTCAM Time module and update tests#1659

Open
ZeliardM wants to merge 12 commits intopython-kasa:masterfrom
ZeliardM:feature/device-time
Open

Fix SMARTCAM Time module and update tests#1659
ZeliardM wants to merge 12 commits intopython-kasa:masterfrom
ZeliardM:feature/device-time

Conversation

@ZeliardM
Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings February 23, 2026 15:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown

codecov bot commented Feb 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.23%. Comparing base (be5ce08) to head (aef9930).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ZeliardM
Copy link
Copy Markdown
Contributor Author

Still working on the correct handling of the time zone information here.

@ZeliardM
Copy link
Copy Markdown
Contributor Author

ZeliardM commented Mar 1, 2026

@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.

@ZeliardM
Copy link
Copy Markdown
Contributor Author

ZeliardM commented Mar 2, 2026

@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.

@ZeliardM ZeliardM force-pushed the feature/device-time branch from a1ea53b to aef9930 Compare March 4, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants