Fix button event entity creation in Bang & Olufsen#157982
Conversation
Update entity checking methods
abmantis
left a comment
There was a problem hiding this comment.
LGTM overall, just some small suggestions
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Create Beoconnect Core entity helper function Update helper function docstring
There was a problem hiding this comment.
Pull request overview
This PR fixes button event entity creation in the Bang & Olufsen integration to only create entities for physical buttons that actually exist on each device model. Previously, some devices were creating event entities for non-existent buttons (e.g., Beosound Premiere created a Bluetooth button entity despite lacking the physical button). The PR also improves test quality by comparing actual entity IDs instead of just counting them, and introduces reusable helper functions to reduce code duplication.
Key Changes
- Updated
get_device_buttons()to filter buttons based on device model capabilities (A5/A9 lack microphone, A9/Premiere lack Bluetooth) - Refactored tests to use exact entity ID comparison with
pytest_unorderedinstead of count-based assertions - Added test coverage for Beosound A5 device
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/bang_olufsen/util.py |
Refactored button filtering logic to handle multiple models without microphone/Bluetooth buttons |
tests/components/bang_olufsen/util.py |
Added device-specific helper functions and made _get_button_entity_ids private |
tests/components/bang_olufsen/test_event.py |
Extracted common test logic into _check_button_event_creation helper and added A5 test case |
tests/components/bang_olufsen/test_websocket.py |
Updated assertions to compare exact entity IDs using pytest_unordered |
tests/components/bang_olufsen/const.py |
Added Beosound A5 test constants |
tests/components/bang_olufsen/conftest.py |
Added Beosound A5 config entry fixture |
tests/components/bang_olufsen/snapshots/*.ambr |
Updated snapshots to reflect corrected entity lists and device name changes |
Proposed change
Currently some of the created Event entities do not have a physical button to trigger that event. I've gone through the compatible devices and this PR should make the integration accurate.
Improve testing by comparing the entity IDs of the expected entities and the created instead of just the number of IDs. Additionally use a helper function to reduce duplicate code.
Will leave stale Event entities for Beosound A9 and Beosound A5 devices. These entities could never be triggered as the devices lack the physical buttons. Not sure if this is considered a breaking change.
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: