Skip to content

Include device_on in set_brightness, set_color_temp, and set_hsv#1680

Open
fluffyspace wants to merge 3 commits intopython-kasa:masterfrom
fluffyspace:fix-device-on-light-commands
Open

Include device_on in set_brightness, set_color_temp, and set_hsv#1680
fluffyspace wants to merge 3 commits intopython-kasa:masterfrom
fluffyspace:fix-device-on-light-commands

Conversation

@fluffyspace
Copy link
Copy Markdown

Summary

  • Add device_on: True to the set_device_info payload in set_brightness(), set_color_temp(), and set_hsv()
  • Fixes silent command failure on devices that treat power state and brightness/color as independent parameters (confirmed on Tapo L900-5 LED strip)

Problem

Some Tapo devices (confirmed on the L900-5 LED light strip) do not implicitly turn on when receiving brightness or color commands via set_device_info. The device:

  1. Accepts the KLAP command and returns success (error_code: 0)
  2. Updates its internal state (reports device_on: true, brightness: 100 when queried)
  3. But does not physically turn on the LEDs

This creates a "zombie state" where the device reports it's on but the LEDs are off. The state persists until the device is power-cycled. Since every protocol response indicates success, python-kasa (and Home Assistant) have no way to detect the failure.

Root cause

  • Brightness.set_brightness() sends {"brightness": N} — no device_on
  • ColorTemperature.set_color_temp() sends {"color_temp": N} — no device_on
  • Color.set_hsv() sends {"hue": N, "saturation": N} — no device_on

Meanwhile, Light.set_state() always includes device_on in the payload, and works correctly.

Fix

Include "device_on": True in all three methods' set_device_info payloads. This matches the behavior of set_state() and is consistent with how the official Tapo app sends commands.

Testing

Tested on a Tapo L900-5 (firmware current, KLAP v2 transport) controlled via Home Assistant's tplink integration:

  • Before fix: light.turn_on with brightness_pct=100 → device reports on, LEDs stay off
  • After fix: light.turn_on with brightness_pct=100 → device reports on, LEDs turn on
  • Stress test: 28 rapid-fire on/off commands (delays from 10s down to 0.1s) — all 28 physically executed correctly with the fix

🤖 Generated with Claude Code

fluffyspace and others added 3 commits April 6, 2026 12:03
Some Tapo devices (confirmed on L900-5 LED strip) treat power state
and brightness/color as independent parameters. When set_device_info
is called with only brightness or color parameters (without device_on),
the device accepts the command, updates its internal state, and reports
success — but the LEDs do not physically turn on.

This causes a particularly bad failure mode: the device enters a
"zombie state" where it reports on/brightness=100 to all queries
while the LEDs remain off. The device stays in this state until
power cycled, and python-kasa has no way to detect the discrepancy
since every protocol response indicates success.

Adding device_on: True to set_brightness(), set_color_temp(), and
set_hsv() ensures the device always receives an explicit power state
with light property changes. This matches the behavior of set_state()
which already includes device_on, and is consistent with how the
official Tapo app sends commands.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Update test_light_effect_brightness assertions in both
test_light_effect.py and test_light_strip_effect.py to match the
new set_brightness payload that includes device_on: True.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (76d9f68) to head (a87c78d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1680   +/-   ##
=======================================
  Coverage   93.22%   93.22%           
=======================================
  Files         157      157           
  Lines        9815     9815           
  Branches     1003     1003           
=======================================
  Hits         9150     9150           
  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.

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