Skip to content

Add a Home Assistant pairing toggle to Audio output cards - #321

Merged
bbangert merged 1 commit into
mainfrom
feat/ha-sendspin-auto-pair-ui
Nov 10, 2026
Merged

bbangert merged 1 commit into
mainfrom
feat/ha-sendspin-auto-pair-ui

Conversation

@bbangert

@bbangert bbangert commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #320. Retarget this PR to main before #320 is merged with --delete-branch. Otherwise deleting the base branch closes this PR.

Summary

UI half of #229. Each output card on the Audio tab gets a "Pair through Home Assistant" toggle, in the same style as the CEC toggle rows. It selects the one output whose Sendspin client is reported to Home Assistant (backend in #320).

  • Turning it on for an output selects that output and replaces any other selection. Turning it on the selected output off clears the selection.
  • The toggle reflects {:home_assistant_pairing, key} broadcasts on HomeAssistantPairing.topic/0, so every open page shows the same selection. The selection is read at mount, so a persisted one shows after a reload.
  • While an output is selected, its row shows a short hint: HA hands the token to MA, only over encrypted API connections, one output at a time.
  • A failed change (output gone, audio subsystem down, DETS error) flashes "Home Assistant pairing change failed".
  • Inputs get no toggle: they still offer only old-wire dynamic_pin.
  • The token never goes into the DOM through this feature: the toggle only selects. The existing Show/Copy disclosure is unchanged.

Design decisions

  • The toggle is offered on every output card. Every shown output runs a Sendspin player, and a disabled output can still be selected, in which case HA gets DISABLED until the output is turned on.
  • The handler doesn't update the assign itself. It waits for the broadcast, so the state on the page is always the state on the server.
  • The calls go through the existing :audio_facade test seam (Audio.home_assistant_pairing/0, select_home_assistant_pairing/1, clear_home_assistant_pairing/0).

Testing

  • New LiveView tests: off by default on every card, persisted selection at mount, select, move to another output, clear, broadcast-driven state, error flash, and stale or invalid ids ignored.
  • mise run test: 3815 passed (8 doctests, 3807 tests), 3 excluded
  • Argus: 0 new findings
  • mix dialyzer (host, dev): passed
  • mix format --check-formatted: clean

HW validation still required on the rpi3 against HA 2026.11 + MA 2.11 dev (the issue's "Done when" boxes):

  • HA pairs a selected output with MA end to end
  • Changing the selection makes HA see the new client_id after it reconnects

Refs #229

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Required rpi3 validation with HA 2026.11 and MA 2.11 dev remains outstanding for end-to-end pairing and client_id updates after switching outputs and reconnecting HA.

No open issues 🎉

What changed in this PR

Adds the Audio-tab UI for #229, building on #320’s backend so users can choose one output for Home Assistant pairing with Music Assistant.

Changes:

  • Adds a pairing toggle to every output card without exposing the token through the toggle.
  • Loads the persisted selection at mount, follows broadcast updates, and displays failures.
  • Adds LiveView tests for selection, switching, clearing, persistence, broadcasts, errors, and invalid IDs.
File Description
test/​universal_proxy_web/​live/​audio_live_test.exs Adds facade stubs and tests for pairing-toggle behavior.
lib/​universal_proxy_web/​live/​audio_live.ex Adds pairing controls, selection state, broadcast handling, and error feedback.

Review effort: Balanced

@bbangert
bbangert force-pushed the feat/ha-sendspin-auto-pair-ui branch from f2d8912 to c9a39de Compare November 10, 2026 01:39
@bbangert
bbangert requested a balanced review from Copilot November 10, 2026 01:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Required rpi3 validation with HA 2026.11 and MA 2.11 dev remains outstanding because LiveView tests do not establish end-to-end pairing or HA client_id refresh after switching outputs and reconnecting.

No open issues 🎉

Review effort: Balanced

@bbangert
bbangert force-pushed the feat/ha-sendspin-auto-pair-ui branch from c9a39de to 5e2334c Compare November 10, 2026 02:00
Each output card gets a "Pair through Home Assistant" toggle that selects (or clears) the one output reported to HA, following the selection broadcast so every open page agrees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bbangert
bbangert force-pushed the feat/ha-sendspin-auto-pair-ui branch from 5e2334c to 37c9875 Compare November 10, 2026 02:23
Base automatically changed from feat/ha-sendspin-auto-pair to main November 10, 2026 02:39
@bbangert
bbangert merged commit 692ddb4 into main Nov 10, 2026
8 checks passed
@bbangert
bbangert deleted the feat/ha-sendspin-auto-pair-ui branch November 10, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants