You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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)
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.
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.
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.
Preserve active settling deadlines during group verification
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.
Remove untranslated exception text from grouping errors
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.
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
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.
Proposed change
Add media player grouping to the Songpal integration using the UPnP grouping feature provided by python-songpal's
GroupControl.X_Leave): leaving from the member side (X_Exit) keeps it listed on the leader.X_Exitis only used when the leader is not set up in HA.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 callsX_StartandX_Exitdirectly. rytilahti/python-songpal#164 fixes that. Once it is released, I'll update the library in a separate PR and switch this one tocreate()andexit().Type of change
Additional information
I used an LLM for help in testing and writing the code.
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: