Add segment effect support for RGBIC light strips#1702
Open
shiner66 wants to merge 3 commits into
python-kasa:masterpython-kasa/python-kasa:masterfrom
shiner66:feat/l930-segment-effectsshiner66/python-kasa:feat/l930-segment-effectsCopy head branch name to clipboard
Open
Add segment effect support for RGBIC light strips#1702shiner66 wants to merge 3 commits intopython-kasa:masterpython-kasa/python-kasa:masterfrom shiner66:feat/l930-segment-effectsshiner66/python-kasa:feat/l930-segment-effectsCopy head branch name to clipboard
shiner66 wants to merge 3 commits into
python-kasa:masterpython-kasa/python-kasa:masterfrom
shiner66:feat/l930-segment-effectsshiner66/python-kasa:feat/l930-segment-effectsCopy head branch name to clipboard
Conversation
RGBIC strips such as the L930/L920/L430 expose a `segment_effect` component for the per-segment custom effects created in the Tapo app (breathe, circulating, chasing, flicker, bloom, stacking). These are separate from the `lighting_effect` system handled by LightStripEffect and are activated with the `apply_segment_effect_rule` method. Add a SegmentEffect module exposing the saved-effect list (from preset rules), the active effect, and set_effect/set_custom_effect, plus a fake-transport handler for apply_segment_effect_rule and an L930 1.4.3 fixture. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1702 +/- ##
==========================================
+ Coverage 93.22% 93.30% +0.08%
==========================================
Files 157 158 +1
Lines 9815 9935 +120
Branches 1003 1018 +15
==========================================
+ Hits 9150 9270 +120
Misses 472 472
Partials 193 193 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add tests for set_custom_effect (with and without speed/carousel), set_brightness (active and idle), the Off no-op path, the module properties, and non-dict preset entries — bringing the module to 100% coverage so the codecov patch check passes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Harden the segment effect rule builder using the decompiled Tapo app v3.18.506 `SegmentEffectData` bean (cross-checked on a live L930): * Validate `type` against the seven segment types (now incl. the static "none" paint) and raise on anything else. * Clamp brightness to 1-100 and speed to 1-10; speed 0 is permitted only for the static "none" paint (it freezes an animated type otherwise). * Normalise per-segment colours to the device's 4-int [h, s, v, w] form and reduce display_colors to the unique palette. start_segment_effect_test rejects 3-int [h, s, v] colours with PARAMS_ERROR(-1008); apply tolerates them, so normalising keeps both paths working. Add test()/stop_test() backed by start/stop_segment_effect_test for a churn-free live preview that does not rewrite the device preset table. Expand the module docstring with the type/range table and the dual `segments` encoding (group sizes for animated types, explicit LED indices for "none"). Cover the new behaviour with four tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
Update — pushed
+4 tests (clamping/normalisation, the The PR description above has been updated to match. |
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.
Summary
RGBIC light strips such as the L930 (also L920 / L430) expose a dedicated
segment_effectSMART component for the per-segment custom effects created inthe Tapo app (breathe, circulating, chasing, flicker, bloom, stacking, and the
static "none" paint). These
are a separate subsystem from the
lighting_effectsystem handled byLightStripEffect, and are activated with theapply_segment_effect_rulemethod rather than
set_lighting_effect. python-kasa currently has no supportfor them.
This PR adds a
SegmentEffectmodule:REQUIRED_COMPONENT = "segment_effect"get_segment_effect_ruleand the saved-effect listfrom
get_preset_rules(already fetched byLightPreset, so no extra query)effect/effect_list/is_active/brightness/has_custom_effectsset_effect(name | "Off"),set_custom_effect(rule),set_brightness()test(rule)/stop_test()for a churn-free live preview viastart_segment_effect_test/stop_segment_effect_test— plays a rule withoutrewriting the device preset table (saving an effect makes the firmware/app
rewrite the preset list and evict effects no longer present)
deviceType: "strip"(required for custom effects) andpreserves
speed(the firmware resets it to 0 / no animation if omitted)The rule builder is hardened against the documented
SegmentEffectDataranges(decompiled from the Tapo Android app v3.18.506, cross-checked on a live L930):
typeagainst the seven segment types (raises on anything else)brightnessto 1-100 andspeedto 1-10;speed: 0is permitted onlyfor the static "none" paint (it freezes an animated type otherwise)
[h, s, v, w]form andreduces
display_colorsto the unique palette —start_segment_effect_testrejects 3-int
[h, s, v]colours withPARAMS_ERROR(-1008)(apply toleratesthem), so normalising keeps both code paths working
segmentsfield is dual-encoded bytype: group sizes for the sixanimated types, explicit LED indices for the static "none" paint
Also adds a
FakeSmartTransporthandler forapply_segment_effect_rule, tests,and an L930 fixture (fw 1.4.3) that contains real saved segment effects.
Open question for maintainers
LightStripEffectnames itself"LightEffect"on the assumption that a devicesupports only one effect system, but RGBIC strips expose both
light_strip_lighting_effectandsegment_effect. This PR therefore registersthe new module under its own name (
Module.SegmentEffect) so the two coexist.I'm happy to change the approach — e.g. unify both into the
LightEffectinterface and route
set_effectto the correct subsystem — if you prefer.Notes on the fixture
The
L930-5(EU)_1.0_1.4.3fixture was captured from a real device. The regionsuffix is assumed; the device
brightnesswas normalised to a resting value andthe active segment rule set to
enable: 0(the two custom effects remain in thepreset slots). Happy to regenerate it with
dump_devinfoif you'd rather.Test plan
uv run pytest tests/smart/modules/test_segment_effect.pyuv run pytest -k "1.4.3"(full suite against the new fixture)pre-commit run -a(ruff / mypy / generate-supported)🤖 Generated with Claude Code