Skip to content

Experiment cleaning up light class#734

Draft
TheJulianJES wants to merge 6 commits intozigpy:devfrom
TheJulianJES:tjj/light_class_cleanup_experiments_1
Draft

Experiment cleaning up light class#734
TheJulianJES wants to merge 6 commits intozigpy:devfrom
TheJulianJES:tjj/light_class_cleanup_experiments_1

Conversation

@TheJulianJES
Copy link
Copy Markdown
Contributor

@TheJulianJES TheJulianJES commented Apr 1, 2026

DRAFT. We need full test coverage first. This is also still experimental.

Proposed change

This adds a _check_result method to the light class that raises if the status is not SUCCESS.
Depending on the _ZCLFailureAction, the exception handling differs for the transition timing.

#733 is also pulled in temporarily. Other clean-ups are applied as well.

Background

The light class basically works perfectly, except for turning off an effect when also switching color modes (affecting some lights). This would be fixed with PR #733. However, the light class also has potential to be cleaned up a bit.

In order to handle transitions and intermediate command failures correctly, you need a lot of conditionals to correctly handle all possible failure states. Other Zigbee implementations often do not do this correctly, causing incorrect state in Home Assistant when one command fails to deliver.

However, we can still clean up our light class a lot. One idea for this failed command handling is the one implemented in this PR. We likely want more test coverage for all edge-cases (group lights, assumed state, turn on after being turned off with a transition (internal brightness differs), ...) before trying any clean-up PRs though.

Additional information

Somewhat related:

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 78.57143% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.79%. Comparing base (696ab1c) to head (764fa47).

Files with missing lines Patch % Lines
zha/application/platforms/light/__init__.py 78.57% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #734      +/-   ##
==========================================
+ Coverage   97.63%   97.79%   +0.16%     
==========================================
  Files          62       62              
  Lines       10814    10817       +3     
==========================================
+ Hits        10558    10579      +21     
+ Misses        256      238      -18     

☔ 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