Skip to content

Fix button event entity creation in Bang & Olufsen#157982

Merged
abmantis merged 5 commits into
home-assistant:devfrom
mj23000:bang_olufsen_device_button_filtering
Dec 5, 2025
Merged

Fix button event entity creation in Bang & Olufsen#157982
abmantis merged 5 commits into
home-assistant:devfrom
mj23000:bang_olufsen_device_button_filtering

Conversation

@mj23000
Copy link
Copy Markdown
Contributor

@mj23000 mj23000 commented Dec 4, 2025

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

  • 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

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

Copy link
Copy Markdown
Member

@abmantis abmantis left a comment

Choose a reason for hiding this comment

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

LGTM overall, just some small suggestions

Comment thread tests/components/bang_olufsen/test_event.py Outdated
Comment thread tests/components/bang_olufsen/test_event.py Outdated
Comment thread tests/components/bang_olufsen/test_event.py Outdated
Comment thread tests/components/bang_olufsen/test_event.py Outdated
Comment thread tests/components/bang_olufsen/test_event.py Outdated
Comment thread tests/components/bang_olufsen/util.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft December 4, 2025 19:52
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Dec 4, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

mj23000 and others added 2 commits December 5, 2025 09:54
Create Beoconnect Core entity helper function
Update helper function docstring
@abmantis abmantis marked this pull request as ready for review December 5, 2025 17:58
Copilot AI review requested due to automatic review settings December 5, 2025 17:59
@home-assistant home-assistant Bot requested a review from abmantis December 5, 2025 17:59
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

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_unordered instead 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

@abmantis abmantis merged commit ce48c89 into home-assistant:dev Dec 5, 2025
41 of 42 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 6, 2025
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.

3 participants