Skip to content

Fix ValueError when turning on blebox light with brightness set to 0#170769

Merged
joostlek merged 3 commits into
home-assistant:devfrom
bkobus-bbx:blebox/fix-turn-off-light-0-brightness
May 18, 2026
Merged

Fix ValueError when turning on blebox light with brightness set to 0#170769
joostlek merged 3 commits into
home-assistant:devfrom
bkobus-bbx:blebox/fix-turn-off-light-0-brightness

Conversation

@bkobus-bbx
Copy link
Copy Markdown
Contributor

@bkobus-bbx bkobus-bbx commented May 15, 2026

Breaking change

Proposed change

Fixed a ValueError raised when calling async_on with a list of all-zero channel values. This can happen when the device's last known state (sensible_on_value) has all channels set to zero. Added an early check so that when the resolved value is a list of all zeros, async_off is called instead.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @bbx-a, @swistakm, mind taking a look at this pull request as it has been labeled with an integration (blebox) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of blebox can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign blebox Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adjusts the BleBox light turn-on behavior to treat “brightness = 0” as a request to turn the device off (instead of raising a ValueError), and adds a regression test for the wLightBox.

Changes:

  • Add an early-return path in async_turn_on that turns the device off when the computed channel values are all zero.
  • Add a unit test ensuring SERVICE_TURN_ON with ATTR_BRIGHTNESS: 0 results in an off state (and uses async_off, not async_on).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/components/blebox/test_light.py Adds regression test for “turn_on brightness=0 should turn off” behavior.
homeassistant/components/blebox/light.py Implements early-off behavior when the computed output values are all zeros.

Comment on lines +204 to +206
if isinstance(value, list) and not any(value):
await self._feature.async_off()
return
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The root cause is that sensible_on_value can already return all-zero channel values, and in that case async_on([0, 0, 0, 0]) always raises a ValueError regardless of what the user requested. So checking the computed value is the right place to catch this.

Comment on lines +204 to +206
if isinstance(value, list) and not any(value):
await self._feature.async_off()
return
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll fix it and add checking against a tuple.

else:
value = feature.apply_brightness(value, brightness)

if isinstance(value, list) and not any(value):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If apply_brightness ever returns all zeros for a non-zero brightness, that's a bug in the library that should be caught and fixed there. Adding a test that mocks that behavior would only be testing the mock, not protecting against a real regression.

@bkobus-bbx
Copy link
Copy Markdown
Contributor Author

Fixed the PR title and description to clarify that the issue is not limited to brightness values. The problem occurs when all channel values are set to 0 (for example, when a light is on and the user manually sets all RGBW/RGBCCT channels to 0), which effectively means the light should be turned off. In this case, async_on could raise a ValueError, so an early check was added to call async_off instead.

@elupus
Copy link
Copy Markdown
Contributor

elupus commented May 17, 2026

Please address or comment on the copilot comments.

@elupus elupus marked this pull request as draft May 17, 2026 11:30
@bkobus-bbx
Copy link
Copy Markdown
Contributor Author

Please address or comment on the copilot comments.

Done, replied and fixed one issue

@bkobus-bbx bkobus-bbx marked this pull request as ready for review May 18, 2026 08:04
Copilot AI review requested due to automatic review settings May 18, 2026 08:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +204 to +206
if isinstance(value, (list, tuple)) and not any(value):
await self._feature.async_off()
return
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The guard is intentionally on the post-processed value. Apply_brightness with brightness=0 always produces all-zero list/tuple for every color mode we handle, and no code path here produces a scalar. Checking brightness == 0 early would also miss cases where brightness comes implicitly from rgb/rgbww.

value = feature.apply_brightness(value, brightness)

if isinstance(value, (list, tuple)) and not any(value):
await self._feature.async_off()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

async_turn_off calls async_off() without any try/except either, so the error handling is already consistent. Neither path wraps it.

@joostlek joostlek added this to the 2026.5.3 milestone May 18, 2026
@joostlek joostlek merged commit b633fbc into home-assistant:dev May 18, 2026
32 of 33 checks passed
@bkobus-bbx bkobus-bbx deleted the blebox/fix-turn-off-light-0-brightness branch May 18, 2026 10:54
jnimmo pushed a commit to jnimmo/core that referenced this pull request May 18, 2026
frenck pushed a commit that referenced this pull request May 19, 2026
…170769)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
@frenck frenck mentioned this pull request May 19, 2026
eleboucher pushed a commit to eleboucher/homelab that referenced this pull request May 19, 2026
…2026.5.2 ➔ 2026.5.3) (#568)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/home-operations/home-assistant](https://ghcr.io/home-operations/home-assistant) ([source](https://github.com/home-assistant/core)) | patch | `2026.5.2` → `2026.5.3` |

---

### Release Notes

<details>
<summary>home-assistant/core (ghcr.io/home-operations/home-assistant)</summary>

### [`v2026.5.3`](https://github.com/home-assistant/core/releases/tag/2026.5.3)

[Compare Source](home-assistant/core@2026.5.2...2026.5.3)

- Bump qbittorrent-api to 2026.5.1 ([@&#8203;lumatijev] - [#&#8203;170181]) ([qbittorrent docs]) (dependency)
- Improve iaqualink 429 handling ([@&#8203;flz] - [#&#8203;170231]) ([iaqualink docs])
- Fix Apple TV keyboard focus binary\_sensor missing on cold start ([@&#8203;kroehre] - [#&#8203;170360]) ([apple\_tv docs][apple_tv docs])
- Add tilt controls for UpDownSheerScreen in Overkiz ([@&#8203;dankarization] - [#&#8203;170563]) ([overkiz docs])
- Fix ValueError when turning on blebox light with brightness set to 0 ([@&#8203;bkobus-bbx] - [#&#8203;170769]) ([blebox docs])
- Bump aiodns to 4.0.3 ([@&#8203;bdraco] - [#&#8203;170865]) ([dnsip docs]) (dependency)
- Populate uid and recurrence\_id in CalDAV calendar events ([@&#8203;frenck] - [#&#8203;170910]) ([caldav docs])
- Fix is\_closed state for SlidingDiscreteGateWithPedestrianPosition covers in Overkiz ([@&#8203;iMicknl] - [#&#8203;170913]) ([overkiz docs])
- Disable USB discovery for teleinfo ([@&#8203;puddly] - [#&#8203;170933]) ([teleinfo docs])
- Fix utility meter next\_reset shifting forward on entity rename ([@&#8203;frenck] - [#&#8203;170957]) ([utility\_meter docs][utility_meter docs])
- Use correct state\_class for utility meters with device classes that don't support total\_increasing ([@&#8203;frenck] - [#&#8203;170962]) ([utility\_meter docs][utility_meter docs])
- Reduce GoodWe connect retries to avoid blocking startup ([@&#8203;frenck] - [#&#8203;170964]) ([goodwe docs])
- Fix is\_closed state for DiscretePositionableGarageDoor in Overkiz ([@&#8203;iMicknl] - [#&#8203;170981]) ([overkiz docs])
- Fix controls for OpenCloseGate4T (rts:GateOpenerRTS4TComponent) in Overkiz ([@&#8203;iMicknl] - [#&#8203;170987]) ([overkiz docs])
- Prevent Google Assistant entity sync from blocking startup ([@&#8203;frenck] - [#&#8203;170991]) ([google\_assistant docs][google_assistant docs])
- Load template extensions by class to prevent import deadlock ([@&#8203;frenck] - [#&#8203;170995])
- Use asyncio.get\_running\_loop() in emulated\_hue UPnP responder ([@&#8203;frenck] - [#&#8203;171000]) ([emulated\_hue docs][emulated_hue docs])
- Fix Netatmo valve KeyError when hvac\_action state is unavailable in Overkiz ([@&#8203;frenck] - [#&#8203;171004]) ([overkiz docs])
- Fix time trigger crash when using entity\_id dict format without offset ([@&#8203;frenck] - [#&#8203;171006]) ([homeassistant docs])
- Fix threshold preview crash when hysteresis is not provided ([@&#8203;frenck] - [#&#8203;171009]) ([threshold docs])
- Fix Growatt mix device IndexError when chart data is empty ([@&#8203;frenck] - [#&#8203;171012]) ([growatt\_server docs][growatt_server docs])
- Fix SleepIQ timer units: seconds should be minutes for core climate and foot warmer ([@&#8203;frenck] - [#&#8203;171013]) ([sleepiq docs])
- Fix Control4 climate crash when humidity is 'Undefined' ([@&#8203;frenck] - [#&#8203;171015]) ([control4 docs])
- Fix manual alarm panel crash on restore with invalid state ([@&#8203;frenck] - [#&#8203;171016]) ([manual docs])
- Handle Daikin connection errors gracefully in coordinator ([@&#8203;frenck] - [#&#8203;171017]) ([daikin docs])
- Fix shorthand template conditions in choose blocks crashing all automations ([@&#8203;frenck] - [#&#8203;171018])
- Add additional overrides to cover entity in Overkiz ([@&#8203;iMicknl] - [#&#8203;171019]) ([overkiz docs])
- Fix Verisure alarm crash when cloud rejects arm/disarm command ([@&#8203;frenck] - [#&#8203;171024]) ([verisure docs])
- Add stop command to Overkiz pergola horizontal awning covers ([@&#8203;frenck] - [#&#8203;171034]) ([overkiz docs])
- Fix WeatherFlow websocket crash when data payload is None ([@&#8203;frenck] - [#&#8203;171037]) ([weatherflow\_cloud docs][weatherflow_cloud docs])
- Bump pyIntesishome to 1.8.8 ([@&#8203;jnimmo] - [#&#8203;171041]) ([intesishome docs]) (dependency)
- Return media\_content\_id as string in forked\_daapd ([@&#8203;frenck] - [#&#8203;171059]) ([forked\_daapd docs][forked_daapd docs])
- Bump aioimmich to 0.14.1 ([@&#8203;mib1185] - [#&#8203;171138]) ([immich docs]) (dependency)
- Fix controls for UpDownGarageDoor4T and additional 4T covers in Overkiz ([@&#8203;iMicknl] - [#&#8203;171144]) ([overkiz docs])
- Fix ZHA config entries using a URI without a port ([@&#8203;puddly] - [#&#8203;171164]) ([zha docs])
- Fix is\_closed state and position for DynamicPergola covers in Overkiz ([@&#8203;iMicknl] - [#&#8203;170983]) ([overkiz docs])
- Fix tilt and position support for VenetianBlind covers in Overkiz ([@&#8203;iMicknl] - [#&#8203;170974]) ([overkiz docs])
- Fix blebox light temperature scaling ([@&#8203;bkobus-bbx] - [#&#8203;170573]) ([blebox docs])

[#&#8203;169484]: home-assistant/core#169484

[#&#8203;170146]: home-assistant/core#170146

[#&#8203;170181]: home-assistant/core#170181

[#&#8203;170231]: home-assistant/core#170231

[#&#8203;170360]: home-assistant/core#170360

[#&#8203;170563]: home-assistant/core#170563

[#&#8203;170573]: home-assistant/core#170573

[#&#8203;170769]: home-assistant/core#170769

[#&#8203;170840]: home-assistant/core#170840

[#&#8203;170865]: home-assistant/core#170865

[#&#8203;170910]: home-assistant/core#170910

[#&#8203;170913]: home-assistant/core#170913

[#&#8203;170933]: home-assistant/core#170933

[#&#8203;170957]: home-assistant/core#170957

[#&#8203;170962]: home-assistant/core#170962

[#&#8203;170964]: home-assistant/core#170964

[#&#8203;170974]: home-assistant/core#170974

[#&#8203;170981]: home-assistant/core#170981

[#&#8203;170983]: home-assistant/core#170983

[#&#8203;170987]: home-assistant/core#170987

[#&#8203;170991]: home-assistant/core#170991

[#&#8203;170995]: home-assistant/core#170995

[#&#8203;171000]: home-assistant/core#171000

[#&#8203;171004]: home-assistant/core#171004

[#&#8203;171006]: home-assistant/core#171006

[#&#8203;171009]: home-assistant/core#171009

[#&#8203;171012]: home-assistant/core#171012

[#&#8203;171013]: home-assistant/core#171013

[#&#8203;171015]: home-assistant/core#171015

[#&#8203;171016]: home-assistant/core#171016

[#&#8203;171017]: home-assistant/core#171017

[#&#8203;171018]: home-assistant/core#171018

[#&#8203;171019]: home-assistant/core#171019

[#&#8203;171024]: home-assistant/core#171024

[#&#8203;171034]: home-assistant/core#171034

[#&#8203;171037]: home-assistant/core#171037

[#&#8203;171041]: home-assistant/core#171041

[#&#8203;171059]: home-assistant/core#171059

[#&#8203;171138]: home-assistant/core#171138

[#&#8203;171144]: home-assistant/core#171144

[#&#8203;171164]: home-assistant/core#171164

[@&#8203;bdraco]: https://github.com/bdraco

[@&#8203;bkobus-bbx]: https://github.com/bkobus-bbx

[@&#8203;dankarization]: https://github.com/dankarization

[@&#8203;flz]: https://github.com/flz

[@&#8203;frenck]: https://github.com/frenck

[@&#8203;iMicknl]: https://github.com/iMicknl

[@&#8203;jnimmo]: https://github.com/jnimmo

[@&#8203;kroehre]: https://github.com/kroehre

[@&#8203;lumatijev]: https://github.com/lumatijev

[@&#8203;mib1185]: https://github.com/mib1185

[@&#8203;puddly]: https://github.com/puddly

[apple_tv docs]: https://www.home-assistant.io/integrations/apple_tv/

[blebox docs]: https://www.home-assistant.io/integrations/blebox/

[caldav docs]: https://www.home-assistant.io/integrations/caldav/

[control4 docs]: https://www.home-assistant.io/integrations/control4/

[daikin docs]: https://www.home-assistant.io/integrations/daikin/

[dnsip docs]: https://www.home-assistant.io/integrations/dnsip/

[emulated_hue docs]: https://www.home-assistant.io/integrations/emulated_hue/

[forked_daapd docs]: https://www.home-assistant.io/integrations/forked_daapd/

[goodwe docs]: https://www.home-assistant.io/integrations/goodwe/

[google_assistant docs]: https://www.home-assistant.io/integrations/google_assistant/

[growatt_server docs]: https://www.home-assistant.io/integrations/growatt_server/

[homeassistant docs]: https://www.home-assistant.io/integrations/homeassistant/

[iaqualink docs]: https://www.home-assistant.io/integrations/iaqualink/

[immich docs]: https://www.home-assistant.io/integrations/immich/

[intesishome docs]: https://www.home-assistant.io/integrations/intesishome/

[manual docs]: https://www.home-assistant.io/integrations/manual/

[overkiz docs]: https://www.home-assistant.io/integrations/overkiz/

[qbittorrent docs]: https://www.home-assistant.io/integrations/qbittorrent/

[sleepiq docs]: https://www.home-assistant.io/integrations/sleepiq/

[teleinfo docs]: https://www.home-assistant.io/integrations/teleinfo/

[threshold docs]: https://www.home-assistant.io/integrations/threshold/

[utility_meter docs]: https://www.home-assistant.io/integrations/utility_meter/

[verisure docs]: https://www.home-assistant.io/integrations/verisure/

[weatherflow_cloud docs]: https://www.home-assistant.io/integrations/weatherflow_cloud/

[zha docs]: https://www.home-assistant.io/integrations/zha/

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/568
@github-actions github-actions Bot locked and limited conversation to collaborators May 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants