Skip to content

Add grouping support to Songpal - #192579

Draft
SirScythe wants to merge 2 commits into
home-assistant:devfrom
SirScythe:songpal-grouping
Draft

SirScythe wants to merge 2 commits into
home-assistant:devfrom
SirScythe:songpal-grouping

Conversation

@SirScythe

@SirScythe SirScythe commented Nov 13, 2026 •

Copy link
Copy Markdown

Proposed change

Add media player grouping to the Songpal integration using the UPnP grouping feature provided by python-songpal's GroupControl.

  • The UPnP description URL and UDN of a device are taken from the SSDP discovery cache.
  • Grouping is only enabled for a device when its UPnP group service is found. This is done in the background to prevent blocking the platform setup
  • Since the group service does not push changes, its state is polled every 30 seconds (if no join/unjoin is triggered through HA, then it's shown right away and verified after 2 seconds)
  • Members are identified by their UDN. A member leaves through the leader (X_Leave): leaving from the member side (X_Exit) keeps it listed on the leader. X_Exit is only used when the leader is not set up in HA.
  • Groups are named after the friendly names of the leader and members ("Living room + Bathroom") until a length of 64 bytes (which is the max. that is accepted by devices) or three device names, then it switches to the leader + number of members ("Living room + 3")
  • From my testing some devices sometimes stop responding for about a minute so a failed poll keeps the last known group instead of showing the device ungrouped.

I've been running the change as a custom integration for about a month on my HT-ZF9 and SRS-X77 with the latest release versions of HA.

Waiting for upstream: python-songpal 0.16.2 creates groups with a codec that causes dropouts after pausing and has no method for X_Exit, so this PR currently calls X_Start and X_Exit directly. rytilahti/python-songpal#164 fixes that. Once it is released, I'll update the library in a separate PR and switch this one to create() and exit().

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 (refactoring, typing, performance, etc.)
  • Developer tooling (CI, GitHub workflows, linters and checkers, scripts, AI instructions, code owners)

Additional information

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

I used an LLM for help in testing and writing the code.

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:

@SirScythe
SirScythe requested a review from rytilahti as a code owner November 13, 2026 16:46
Copilot AI balanced review requested due to automatic review settings November 13, 2026 16:46
@home-assistant

home-assistant Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

👋 Hi! Thanks for contributing to Home Assistant.

This is your PR dashboard which flags anything you need to address before your PR can be reviewed. Once everything is green, you can press the 'Ready for review' button at the bottom of the page to notify reviewers to take a look.

More information about this dashboard

This dashboard automatically updates on every change to this PR and reevaluates the rules as you go. Until everything has been addressed, the bot will keep the PR in draft.

Skip a check that doesn't apply

If you think a check doesn't apply to your PR (or the rule is bugged), comment @home-assistant ignore "<check name>" "<reason>". The check name as shown in the table above. This will mark the check as ignored and let you put your PR in 'Ready for review'; @home-assistant unignore "<check name>" restores the rule.

Bot commands

Reply with @home-assistant <command>. Several commands can be stacked, one per line:

  • update — Re-runs the bot's checks on the issue or pull request.
  • ignore — Waives a dashboard check: ignore "<check name>" "<reason>". (author) — e.g. @home-assistant ignore "Merge conflicts" "Broken rule, no merge conflicts present"
  • unignore — Restores a waived dashboard check: unignore "<check name>". (author) — e.g. @home-assistant unignore "Merge conflicts"
  • unassign — Removes the given integration domain's label and its code owners from the assignees. (author or code owners) — e.g. @home-assistant unassign "opensky"
  • close — Closes the issue or pull request. (code owners)
  • reopen — Reopens the issue or pull request. (code owners)
  • rename — Renames the issue or pull request: rename "<new title>". (code owners) — e.g. @home-assistant rename "A more descriptive title"
  • add-label — Adds a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the issue or pull request. (code owners) — e.g. @home-assistant add-label "needs-more-information"
  • remove-label — Removes a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) from the issue or pull request. (code owners) — e.g. @home-assistant remove-label "needs-more-information"
  • mark-draft — Marks the pull request as draft. (code owners)
  • update-branch — Updates the pull request branch with the base branch. (code owners)

Checks

✨ Everything's in order!

5 checks passed (6 skipped)
Status Check Details
✅ Forbidden files No forbidden files.
✅ Merge conflicts Merge status is being recalculated by GitHub.
✅ Merge target This PR targets dev.
✅ Type of change Type of change: new-feature
✅ CLA Everyone involved has signed the CLA.
➖ New integration validation Not a new-integration PR.
➖ Single new platform No new platforms added.
➖ Documentation Not a new integration or platform — no documentation PR required.
➖ Belongs together No pull requests listed.
➖ Code owner approval Touches no platinum integration — no code-owner approval required.
➖ Blocking: awaiting-frontend awaiting-frontend label not set — nothing to block.

@home-assistant

Copy link
Copy Markdown
Contributor

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

Code owner commands

Reply with @home-assistant <command>:

  • update — Re-runs the bot's checks on the issue or pull request.
  • ignore — Waives a dashboard check: ignore "<check name>" "<reason>". (author) — e.g. @home-assistant ignore "Merge conflicts" "Broken rule, no merge conflicts present"
  • unignore — Restores a waived dashboard check: unignore "<check name>". (author) — e.g. @home-assistant unignore "Merge conflicts"
  • unassign — Removes the given integration domain's label and its code owners from the assignees. (author or code owners) — e.g. @home-assistant unassign "opensky"
  • close — Closes the issue or pull request. (code owners)
  • reopen — Reopens the issue or pull request. (code owners)
  • rename — Renames the issue or pull request: rename "<new title>". (code owners) — e.g. @home-assistant rename "A more descriptive title"
  • add-label — Adds a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the issue or pull request. (code owners) — e.g. @home-assistant add-label "needs-more-information"
  • remove-label — Removes a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) from the issue or pull request. (code owners) — e.g. @home-assistant remove-label "needs-more-information"
  • mark-draft — Marks the pull request as draft. (code owners)
  • update-branch — Updates the pull request branch with the base branch. (code owners)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved grouping bugs can prevent rediscovery, leave stale memberships, and indefinitely suppress polling after entity removal, while grouping errors expose untranslated exception text.

5 open issues
What changed in this PR

Adds media-player grouping to the Songpal integration using UPnP group control, with SSDP discovery to identify compatible devices.

Changes:

  • Adds join/unjoin actions, automatic group naming, and group membership reporting.
  • Polls group state and displays expected changes while devices settle.
  • Adds translated errors and tests covering discovery, grouping, failures, and lifecycle cleanup.
File Description
tests/​components/​songpal/​test_media_player.py Tests grouping actions, discovery, polling, and cleanup.
tests/​components/​songpal/​conftest.py Adds shared device, group-control, and discovery fixtures.
tests/​components/​songpal/​__init__.py Adds grouping mock data and setup helpers.
homeassistant/​components/​songpal/​strings.json Adds user-facing grouping error messages.
homeassistant/​components/​songpal/​media_player.py Implements discovery, group control, polling, and membership reporting.
homeassistant/​components/​songpal/​manifest.json Orders setup after SSDP when available.
homeassistant/​components/​songpal/​const.py Defines the Sony SSDP service type.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 13, 2026 17:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unresolved grouping-state races allow stale in-flight polls and premature timer refreshes to overwrite expected group state while join or unjoin operations are still settling.

1 open issue
3 previously missed issues

In code that hasn't changed since last review

Medium severity Discard poll responses started before a group change

homeassistant/​components/​songpal/​media_player.py:640

Discard poll responses that predate a join or unjoin. A poll already awaiting state() can return the old group after _async_set_expected_group_states() publishes the new one and overwrite it despite the settling deadline. Invalidate those requests with a generation counter or serialize polling with group changes, and add a regression test for this ordering.

Medium severity Preserve active settling deadlines during group verification

homeassistant/​components/​songpal/​media_player.py:654

Preserve each entity's settling deadline when verifying a group change. If another device starts a grouping operation just before this timer fires, this loop clears its newer deadline and polls it immediately, overwriting the expected group with the device's pre-change state. Only refresh entities whose settling deadlines have elapsed.

Low severity Remove untranslated exception text from grouping errors

homeassistant/​components/​songpal/​media_player.py:812

Remove the stringified exception from both translated grouping errors. Passing str(ex) as {error} inserts untranslated library text into localized messages here and in the unjoin handler at line 849. Keep exception chaining for diagnostics, remove the placeholder from both handlers, and remove {error} from grouping_failed in strings.json.

4 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants