Skip to content

Optimistic UI updates after commands#3

Merged
cdheiser merged 1 commit intomainfrom
optimistic-updates
Apr 19, 2026
Merged

Optimistic UI updates after commands#3
cdheiser merged 1 commit intomainfrom
optimistic-updates

Conversation

@cdheiser
Copy link
Copy Markdown
Owner

Summary

After turn_on / turn_off / set_volume / select_source, push the expected new state straight into the coordinator's data so the UI flips immediately instead of waiting on the next poll. async_request_refresh() still fires so the poll confirms actual state — if the command didn't take, the UI self-corrects on the next update.

  • turn_onpower: …ON
  • turn_offpower: …OFF
  • set_volume_level(x)volume: round(x*100)
  • select_source(s)source: <code> and power: …ON (selecting a source turns the zone on)
  • volume_up / volume_down — left as plain refresh, since we don't know the target value
  • mute — already optimistic via _muted

Test plan

  • 4 new unit tests: each command pushes optimistic data into coordinator.data and reflects in the entity's state / volume_level / source immediately
  • Ruff + Mypy clean
  • Verify in HA that tapping source or power gives instant UI feedback

🤖 Generated with Claude Code

The coordinator's async_request_refresh still fires so the poll
confirms real state, but the UI now flips instantly rather than
waiting on a Crestron response round-trip. Selecting a source
also flips power to ON since that's what the device does.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@cdheiser cdheiser merged commit 2e16a12 into main Apr 19, 2026
3 checks passed
@cdheiser cdheiser deleted the optimistic-updates branch April 19, 2026 00:02
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.

1 participant