Repository navigation
fix(media_player): centralise power-state decision engine, document sound system state machine, and add intercom ducking trace replay (#682) - #683
Merged
Conversation
…ound system state machine, and add intercom ducking trace replay (OpenWebNet-HA#682)
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ower transitions, support string dimensions, and add wake-window ducking tests
…rds and drop unused current_state
GreenGrassBlueOcean
merged commit Oct 10, 2026
386df80
into
OpenWebNet-HA:v2-phase1-architecture
16 checks passed
GreenGrassBlueOcean
deleted the
fix/issue-682-media-player-state-complexity
branch
October 21, 2026 19:35
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the problem
The WHO 16 sound system implementation has grown into a complex state machine distributed across multiple entity layers (
media_player.py,media_player_group.py,media_player_decoder.py,media_player_source.py). While modularizing the code improved readability, the interaction between amplifier power state, volume rocker commands, Dimension 1 volume status reports, video door entry (intercom ducking), multi-room grouping, and anti-hiss auto-off remained difficult to reason about and caused recurring false wake-up regressions:*#16*WHERE*1*<vol>##and*#22*3#A#P*1*<vol>##) across the SCS bus to duck audio during speech and restore it afterwards. Because amplifiers retain their volume registers even while unpowered, loosely coupled status checks previously interpreted these volume reports as an indication that the amplifier was on, causing unpowered amplifiers throughout the home to falsely turn ON.*16*1001..1015*WHERE##) intentionally wake an amplifier, but volume-down rockers (*16*1101..1115*WHERE##) or status queries must never turn an inactive amplifier on.if/elifbranches without a centralized decision engine, creating vulnerabilities to edge cases (e.g., string vs integer dimensions from trace fixtures, spurious mock attributes, or concurrent ducking during wake sequences).OFF,WAKE_PENDING,ON,PENDING_OFF,PARKED) and their interactions with physical hardware and bus frames were not formally documented.How it is solved
custom_components/myhome/media_player_power.py):determine_power_transition(...)as a pure, deterministic decision function with strict priority ordering:is_dimension_1_volume_report): Explicitly tested first. Frames matching*#16*WHERE*1*<vol>##or*#22*3#A#P*1*<vol>##returnPowerTransition.NO_CHANGE. Supports both integer and string dimension representations (int(dimension) == 1).is_volume_rocker_down): Rocker frames*16*1101..1115*WHERE##step volume down only and returnPowerTransition.NO_CHANGE.*16*3*10S##and*16*13*10S##returnPowerTransition.NO_CHANGE.WAKE_ECHO_OFF(suppressed within 3.0s echo window),PARKED_CONFIRM_OFF(confirms anti-hiss off while preserving group topology), orREAL_OFF(powers off zone and coordinates group leave/handover).*16*3*WHERE##/*16*0*WHERE##returnsPowerTransition.WAKE_ON.*16*1001..1015*WHERE##returnsPowerTransition.WAKE_ON.*16*3*1ES##), Dimension 5 queries, and unrecognised frames returnPowerTransition.NO_CHANGE.custom_components/myhome/media_player.py):is_on/is_off/is_volume_uplogic with clean dispatch todetermine_power_transition(...).WAKE_ECHO_WINDOW = 3.0s,AUTO_OFF_IDLE_DELAY = 3.0s,AUTO_OFF_PAUSED_DELAY = 60.0s,GROUP_LEAVE_GRACE = 5.0s).docs/configuration/media_player.md):How it is tested
tests/test_media_player_power.py):media_player_power.py.dimension=1,dimension="1",_dimension=1).is_on=True.1101..1115) and non-power WHAT codes (1000,1016,1100,1116,2001,5000, etc.) returnNO_CHANGE.tests/test_intercom_ducking_trace_replay.py):_wake_off_sent_at).tests/test_audio_group_live_replay.py):ruff check custom_components tests scripts: 0 errors.scripts/verify_ha_standards.py: Passed (Platinum quality scale satisfied).scripts/sync_documentation.py --check: Passed (0 drift).Where are the traces
tests/fixtures/traces/mh202_sound_intercom_ducking/myhome_trace_MH202_sound_intercom_ducking.jsontests/fixtures/traces/mh202_sound_intercom_ducking/README.mdtests/golden/corpus.json(267 calibrated frames)tests/golden/frames/who16_sound.yamltests/golden/frames/who22_sound_diffusion.yamldocs/trace-availability.mdandREADME.md.State Machine & Decision Diagram
Amplifier Lifecycle States
OFFoff*16*13*<WHERE>##). Zero bus audio is demodulated. Standby power is minimal.WAKE_PENDINGoff/on*16*13*<WHERE>##followed by*16*3*<WHERE>##). A 3-second echo suppression window (WAKE_ECHO_WINDOW = 3.0s) ignores the initial OFF echo.ONplaying/on*16*3*<WHERE>##). Demodulating stereo audio and driving room speakers.PENDING_OFFpaused/idlePARKEDpaused/idle*16*13*<WHERE>##) to eliminate analog bus hiss during extended pauses. In Home Assistant, the entity reportspaused/idleand preserves group topology. Resumes immediately upon playback.State Transition Diagram
stateDiagram-v2 [*] --> OFF OFF --> WAKE_PENDING: play_media / turn_on WAKE_PENDING --> ON: *16*3*<WHERE>## confirmed OFF --> ON: Physical Vol-Up Rocker (*16*1001..1015*<WHERE>##) OFF --> ON: External Bus ON (*16*3*<WHERE>##) ON --> PENDING_OFF: Decoder Idle/Off (3s) or Paused (60s) ON --> PENDING_OFF: Member Unjoined (5s grace period) PENDING_OFF --> ON: Decoder resumes playing (Timer Cancelled) PENDING_OFF --> PARKED: Auto-Off Timer Expires (Group Preserved) PENDING_OFF --> OFF: Grace Period Expires (Standalone / Unjoined) PARKED --> ON: media_play / play_media / turn_on PARKED --> OFF: turn_off / Physical Wall Switch OFF (*16*13*<WHERE>##) ON --> OFF: turn_off / Physical Wall Switch OFF (*16*13*<WHERE>##)Bus Frame Decision Engine
*16*3*<WHERE>##*16*0*<WHERE>##PowerTransition.WAKE_ON*16*1001*<WHERE>##to
*16*1015*<WHERE>##PowerTransition.WAKE_ON*16*1101*<WHERE>##to
*16*1115*<WHERE>##PowerTransition.NO_CHANGE*#16*<WHERE>*1*<LEVEL>##*#22*3#A#P*1*<LEVEL>##PowerTransition.NO_CHANGEvolume_levelonly. Never wakes or turns on an OFF amplifier (#669, #682).*#16*<WHERE>*#1*<LEVEL>##PowerTransition.NO_CHANGE*16*3*1ES##PowerTransition.NO_CHANGEEto sourceS. Handled by routing logic; does not change power state.*16*3*10S##PowerTransition.NO_CHANGES. Does not alter room amplifier power.*16*13*<WHERE>##*16*10*<WHERE>##PowerTransition.WAKE_ECHO_OFFPowerTransition.PARKED_CONFIRM_OFFPowerTransition.REAL_OFF• If amplifier is parked: acknowledged as auto-off echo.
• Otherwise: real OFF from wall switch or gateway; powers off entity and disbands group.