Skip to content

Add Dimmer Configuration Support #1484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 2, 2025
Merged

Conversation

ryenitcher
Copy link
Contributor

  • Add: Support for configuring minimum dimming level.
  • Add: Support for configuring dimmer ramp rate.
  • Add: Support for configuring dimmer gentle fade time.
  • Add: Support for configuring dimmper fade time.

@ryenitcher
Copy link
Contributor Author

Hopefully breaking out the dimmer configuration into a feature from the module is acceptable.

I've tested this against an KS220, and it appears to work well, but I can look into adding proper tests for this if the change seems reasonable to you.

@ryenitcher
Copy link
Contributor Author

This should cover #1464

Copy link

codecov bot commented Jan 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.71%. Comparing base (09e73fa) to head (f010a3b).
Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1484      +/-   ##
==========================================
+ Coverage   92.64%   92.71%   +0.06%     
==========================================
  Files         149      150       +1     
  Lines        9428     9524      +96     
  Branches      957      968      +11     
==========================================
+ Hits         8735     8830      +95     
+ Misses        497      496       -1     
- Partials      196      198       +2     

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

@rytilahti rytilahti linked an issue Jan 25, 2025 that may be closed by this pull request
@rytilahti rytilahti added the enhancement New feature or request label Jan 26, 2025
Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Looks really great and it's nice to see also older devices getting some love, thanks @ryenitcher! 💯

I added some comments (which likely apply for all these settings) inline, let me know if you think those changes make sense or not. On tests, it would be great to have some, either test_motion.py or test_ambientlight.py could be a good starting point.


:param min: The minimum dimming level, in the range 0-51.
"""
if (min < 0) or (min > 51):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (min < 0) or (min > 51):
if min < 0 or min > 51:

Is it really up to 51 and not 50? In any case, no need for parentheses here.

Copy link
Contributor Author

@ryenitcher ryenitcher Jan 26, 2025

Choose a reason for hiding this comment

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

Yeah if you use the app to set the dimmer trim to max, it sets the value to 51, which surprised me as well. The API rejects 52 as a value though, so it has to end on 51. Perhaps there is a special bypass mode on the triac or something for no dimming, and that's a special value used to denote that?

Copy link
Member

Choose a reason for hiding this comment

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

Could be something special indeed, but we can keep it as it is and adjust when someone chimes in with an issue report :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be worth adding a small comment here about the tested app behaviour.

- Add: Support for configuring minimum dimming level.
- Add: Support for configuring dimmer ramp rate.
- Add: Support for configuring dimmer gentle fade time.
- Add: Support for configuring dimmper fade time.
- Fix: Return time values as `timedelta` instead of `int`.
- Fix: Move constants to top of file.
- Fix: Correct feature types.
- Fix: Expose range of bounded features.
- Add: Tests for IOT Dimmer feature.
@ryenitcher
Copy link
Contributor Author

I'm not sure if it's worth writing a test for this line?

I doubt it will ever be triggered, and even then all it does its immediately return?

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Just some minor style-related nitpicks but this looks otherwise good to go, thanks @ryenitcher!

@ryenitcher
Copy link
Contributor Author

Looks really great and it's nice to see also older devices getting some love, thanks @ryenitcher! 💯

It looks like the KS240 might be the only “new” dimmer so far (from searching the fixture files), but it looks like the config layout for the IOT version is roughly the same. I can copy over support to IOT in a follow up PR if that works. The new matter dimmer (KS225) might also be an IOT dimmer, but I don’t currently have one to test against.

- Fix: Correct inline comment formatting.
- Fix: Remove un-needed check for `get_dimmer_parameters` on dimmers.
- Fix: Remove extra newline from docstring summaries.
@ryenitcher
Copy link
Contributor Author

I think this PR should now be ready to go.

I've opened #1495 in draft status for calibration support on the SMART devices.

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @ryenitcher! 🎉

@sdb9696 sdb9696 added this to the 0.10.1 milestone Feb 2, 2025
@sdb9696 sdb9696 merged commit bff5409 into python-kasa:master Feb 2, 2025
18 checks passed
@sdb9696 sdb9696 mentioned this pull request Feb 2, 2025
sdb9696 added a commit that referenced this pull request Feb 2, 2025
## [0.10.1](https://github.com/python-kasa/python-kasa/tree/0.10.1) (2025-02-02)

[Full Changelog](0.10.0...0.10.1)

**Release summary:**

Small patch release for bugfixes

**Implemented enhancements:**

- dustbin\_mode: add 'off' mode for cleaner downstream impl [\#1488](#1488) (@rytilahti)
- Add Dimmer Configuration Support [\#1484](#1484) (@ryenitcher)

**Fixed bugs:**

- Do not return empty string for custom light effect name [\#1491](#1491) (@sdb9696)
- Add FeatureAttributes to smartcam Alarm [\#1489](#1489) (@sdb9696)

**Project maintenance:**

- Add module.device to the public api [\#1478](#1478) (@sdb9696)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dimmer Calibration? NOT Presets
3 participants