FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Expose the light transition state change flag by nopoz · Pull Request #1745 · python-kasa/python-kasa · GitHub

Expose the light transition state change flag - #1745

Open
nopoz wants to merge 1 commit into
python-kasa:masterfrom
nopoz:feature/light-transition-change-state
Open

Expose the light transition state change flag#1745
nopoz wants to merge 1 commit into
python-kasa:masterfrom
nopoz:feature/light-transition-change-state

Conversation

nopoz commented Aug 24, 2026
edited
Loading

Copy link
Copy Markdown

Summary

Bulbs and light strips can fade smoothly when their brightness or colour changes, instead of snapping straight to the new value. The Tapo app exposes this as "Smooth Transition". python-kasa cannot read or change it today, so the setting is missing from Home Assistant even though the device supports it. This PR adds it as a switch.

Under the hood, on_off_gradually reports three flags. on_state and off_state cover fading when the light is turned on and off, and are already exposed as the smooth_transition_on / smooth_transition_off number features. The third, change_state, appears nowhere in lighttransition.py: it is never read and never written, and set_enabled() only touches the other two.

  • read change_state in _post_update_hook
  • add a change_transition property and set_change_transition()
  • register a smooth_transition_change switch feature when the device reports the flag

Verification

Confirmed on a physical L920 running firmware 1.4.4, on_off_gradually v4, by toggling the flag and watching the strip. With change_state cleared, a brightness jump from 10 to 100 snaps instantly. With it set, the same jump ramps. Turn-on and turn-off fades were unaffected in both cases, which is the expected split with on_state / off_state.

The flag persists across a full disconnect, so it is stored device state rather than a per-session toggle.

Notes

  • Only newer firmware reports change_state. Exactly one fixture in the repo has it, L530EA(EU)_1.0_1.4.2, and 26 other on_off_gradually fixtures do not, so the feature is registered conditionally and the test asserts both paths.
  • The conditional checks the parsed value rather than self.data. _initialize_features runs after _post_update_hook and must not raise for devices whose get_on_off_gradually_info query failed. Reading self.data there breaks fixture generation for several plugs, including P135 and KS225.
  • tests/fakeprotocol_smart.py needed a matching branch in _set_on_off_gradually_info, which previously applied on_state and off_state but silently dropped change_state.
  • The feature is a switch rather than a number because the device reports only enable for this flag, with no duration alongside it.

Test plan

  • uv run pytest tests/smart/modules/test_lighttransition.py - 66 tests, covering both the supported and unsupported paths
  • uv run pytest - full suite passes
  • uv run pre-commit run -a - clean

on_off_gradually reports three flags: on_state and off_state, which cover
fading when the light is turned on and off and are already exposed as
number features, and change_state, which was neither read nor written.

change_state controls fading between states while the light is already
on, and is what the Tapo app presents as "Smooth Transition". Verified on
an L920 running firmware 1.4.4: with the flag cleared a brightness jump
snaps instantly, and with it set the same jump ramps.

Only newer firmware reports it, so the feature is registered only when
the device returns the flag. The check uses the parsed value rather than
the raw data because _initialize_features must not raise for devices
whose get_on_off_gradually_info query failed.

codecov Bot commented Aug 24, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.30%. Comparing base (a29d061) to head (6298f32).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1745   +/-   ##
=======================================
  Coverage   93.29%   93.30%           
=======================================
  Files         157      157           
  Lines        9932     9945   +13     
  Branches     1022     1025    +3     
=======================================
+ Hits         9266     9279   +13     
  Misses        471      471           
  Partials      195      195           

☔ View full report in Codecov by Harness.
📢 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL