Skip to content

HEOS: Mark players unavailable on controller disconnection#4068

Draft
MarvinSchenkel wants to merge 1 commit into
devfrom
claude/charming-heisenberg-V5Rgg
Draft

HEOS: Mark players unavailable on controller disconnection#4068
MarvinSchenkel wants to merge 1 commit into
devfrom
claude/charming-heisenberg-V5Rgg

Conversation

@MarvinSchenkel

Copy link
Copy Markdown
Contributor

What does this implement/fix?

When a HEOS-connected AVR is fully power-cycled, pyheos internally marks the device as unavailable, but Music Assistant was not listening for the disconnection event. This left the player showing as available in MA while the underlying transport connection was gone, causing every playback command to fail with CommandError: Not connected to device until the MA addon was restarted.

The fix subscribes to pyheos's add_on_disconnected callback in _setup_controllers. When the callback fires, set_device_info() is called on each registered HEOS player, which reads the (now-False) available attribute from the pyheos device object and propagates it via update_state(). Recovery on reconnection was already handled correctly: pyheos fires EVENT_PLAYERS_CHANGED with a PlayerUpdateResult after reloading players, which triggers the existing _handle_controller_eventdiscover_players() path.

Related issue (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix

Checklist

  • The code change is tested and works locally.
  • pre-commit run --all-files passes.
  • pytest passes, and tests have been added/updated under tests/ where applicable.
  • For changes to shared models, the companion PR in music-assistant/models is linked.
  • For changes affecting the UI, the companion PR in music-assistant/frontend is linked.
  • I have read and complied with the project's AI Policy for any AI-assisted contributions.
  • I have raised a PR against the documentation repository targeting the main or beta branch as appropriate.

Generated by Claude Code

Subscribe to pyheos add_on_disconnected to propagate the availability
change to MA players when the HEOS controller loses its connection
(e.g. after a full AVR power cycle). Without this, players stayed
visible as available in MA until a restart even though pyheos had
already marked them unavailable internally.

Fixes: music-assistant/support#5565
https://claude.ai/code/session_01RCxBC9UUetxpuHWMZv8vF1
@github-actions github-actions Bot added the bugfix label Jun 3, 2026
@MarvinSchenkel MarvinSchenkel changed the title fix(heos): mark players unavailable on controller disconnection HEOS: Mark players unavailable on controller disconnection Jun 3, 2026
@MarvinSchenkel

Copy link
Copy Markdown
Contributor Author

@Tommatheussen my issues agent came up with this fix, could you sanity check this please?

@MarvinSchenkel MarvinSchenkel marked this pull request as ready for review June 3, 2026 06:37
Copilot AI review requested due to automatic review settings June 3, 2026 06:37

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.

Pull request overview

This PR improves the HEOS player provider’s connection lifecycle handling by reacting to pyheos controller disconnection events so Music Assistant immediately reflects HEOS players as unavailable after an AVR power-cycle/disconnect.

Changes:

  • Subscribes to pyheos add_on_disconnected during controller setup.
  • Adds a disconnection callback that refreshes each HEOS player’s device info and pushes an updated state so availability is propagated promptly.

@OzGav OzGav added this to the 2.9.0 milestone Jun 3, 2026
@Tommatheussen

Copy link
Copy Markdown
Contributor

LGTM, I can test on phyiscal devices later today if you want

@MarvinSchenkel

Copy link
Copy Markdown
Contributor Author

Would be great since I do not have any :)

@Tommatheussen

Copy link
Copy Markdown
Contributor

@MarvinSchenkel technically, the changes are correct, the problem is a bit deeper though. pyheos doesn't invoke the _on_disconnected all that often, seems to happen mainly when we programmatically disconnect (so a known disconnection), or when the device gets rebooted. Basically when the connection really gets cleanly closed.
Seems turning off the AVR doesn't properly close the connection, resulting in commands timing out instead. This timeout doesn't trigger the callback.
I'll check with the pyheos creator if this is intented or not, to me it makes sense that commands timing out (at least connection heartbeat commands) would indicate a broken connection.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants