Improve exceptions handling in WLED#171646
Draft
mik-laj wants to merge 3 commits into
Draft
Conversation
… in WLED integration Add proper exception handling for the new exception types introduced in wled library, with differentiated translation keys for invalid response errors and connection errors. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Contributor
|
Hey there @frenck, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds more granular WLED error handling (invalid/empty responses and upgrade failures) and aligns tests/translations with the new behavior.
Changes:
- Add translation keys/messages for invalid responses (including presets-specific) and firmware install failures.
- Update coordinator/helpers/config flow/update flows to raise translated
HomeAssistantError/UpdateFailedfor new WLED exception types. - Extend WLED component tests to cover the new error scenarios and state behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/components/wled/test_update.py | Updates update-install error test to assert translated HomeAssistantError for upgrade failures. |
| tests/components/wled/test_switch.py | Adds invalid-response handling tests ensuring entity does not become unavailable; adjusts call counts. |
| tests/components/wled/test_select.py | Adds invalid-response handling tests ensuring entity does not become unavailable; adjusts call counts. |
| tests/components/wled/test_number.py | Adds invalid-response test for number service calls and availability behavior. |
| tests/components/wled/test_light.py | Expands parametrized coverage to include invalid/empty response errors (presets vs full). |
| tests/components/wled/test_coordinator.py | Consolidates setup-failure tests into a parametrized suite covering more exceptions + log messages. |
| tests/components/wled/test_config_flow.py | Adds config-flow coverage for invalid/empty response errors and consolidates zeroconf abort tests. |
| tests/components/wled/test_button.py | Expands restart button error coverage and adds assertion for reset call. |
| homeassistant/components/wled/update.py | Converts WLEDUpgradeError into translated HomeAssistantError and refreshes coordinator after install attempt. |
| homeassistant/components/wled/strings.json | Adds new config-flow errors and entity error translation messages for presets/upgrade cases. |
| homeassistant/components/wled/helpers.py | Adds handling for invalid/empty responses and maps them to presets vs generic translation keys. |
| homeassistant/components/wled/coordinator.py | Adds invalid/empty response handling during coordinator updates and adjusts translation mapping for failures. |
| homeassistant/components/wled/config_flow.py | Adds invalid/empty response mapping to config-flow error/abort reasons. |
…eptions in WLED integration
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.
Breaking change
Proposed change
WLED devices store presets in their internal flash memory (
presets.json). This file is prone to corruption — many users have reported devices where it is damaged or missing. Previously, when the python-wled library tried to fetch presets from such a device, it would propagate low-level exceptions (e.g.UnicodeError) that surfaced as cryptic, unhelpful error messages with no guidance for the user. Related issues: #162199 #163772.The python-wled library (as of frenck/python-wled#2052) now raises typed exceptions -
WLEDInvalidResponseErrorandWLEDEmptyResponseError- for these cases instead of letting raw errors bubble up.This PR catches those exceptions explicitly in:
config_flow.py- during manual setup and Zeroconf discoverycoordinator.py- during periodic data updateshelpers.py- in thewled_exception_handlerdecorator used by entity actions (light, switch, select, number)When the error message indicates the failure is related to
presets, a dedicated, actionable error message is shown:This guides users to the WLED web UI where they can repair or reset their preset configuration. For other invalid response errors, a generic message is shown.
Additionally,
WLEDUpgradeErroris now caught during firmware installation inupdate.py, replacing a previously unhandled exception with a proper translated error message.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: