Skip to content

fix(integration): stop replaying stale sound events#65

Open
pantunes wants to merge 1 commit into
thekoma:mainfrom
pantunes:codex/fix-sound-event-replay
Open

fix(integration): stop replaying stale sound events#65
pantunes wants to merge 1 commit into
thekoma:mainfrom
pantunes:codex/fix-sound-event-replay

Conversation

@pantunes

@pantunes pantunes commented Jul 14, 2026

Copy link
Copy Markdown

Device

Tested with two Philips Avent Connected SCD923/26 baby monitors connected through the Philips Avent Home Assistant integration with working Tuya LAN push.

Bug

DPS 141 (decibel_upload) is an event payload, but the coordinator merges it into persistent self.data. Once a real sound event has occurred, that value can remain in the merged state indefinitely.

AventSoundDetected currently reads the merged state on every coordinator update. Consequently, an old sound event is treated as new when:

  • the normal cloud poll completes every 120 seconds;
  • an unrelated LAN update arrives, such as temperature DPS 207;
  • a Home Assistant control produces an optimistic coordinator update.

Each replay restarts the 30-second clear timer, producing regular Detected -> Clear entries even in a quiet room.

Debug logging confirmed the distinction:

  • quiet-room false detections aligned with coordinator refreshes that contained no fresh DPS 141 LAN payload;
  • deliberate noise produced a fresh LAN push ... {'141': 'decibel_upload'} event;
  • subsequent unrelated updates could retrigger the retained event.

Solution

Keep the latest raw LAN payload and a monotonically increasing LAN-update sequence alongside the existing merged coordinator data. Each sound binary sensor remembers the last sequence it processed and only treats DPS 141 as a new event when it appears in a fresh, unprocessed LAN payload.

The merged coordinator data remains unchanged for normal state entities. Equal sound payloads received separately from the camera still count as distinct real events.

This intentionally makes sound-event triggering depend on LAN push. If LAN connectivity is unavailable, the integration no longer replays ambiguous sticky cloud state as sound events.

No configuration changes are required.

Tests

Added regression coverage to the existing LAN tests for:

  • keeping a fresh unrelated LAN payload separate from retained merged DPS 141 state;
  • recognizing separately received, identical decibel_upload payloads as distinct events.

Validated locally with:

PYTHONPATH=. pytest tests/test_philips_avent/ -q
104 passed

ruff check custom_components/ examples/ tools/ --ignore E501
All checks passed!

Summary by CodeRabbit

  • Bug Fixes
    • Improved Philips Avent sound detection to respond only to newly received LAN events.
    • Prevented stale or retained data from triggering duplicate sound notifications.
    • Ensured identical sound events received separately are detected independently.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c8c1a99-d17a-4e54-9e84-5b8f591f39de

📥 Commits

Reviewing files that changed from the base of the PR and between ab3d67e and aa427e1.

📒 Files selected for processing (3)
  • custom_components/philips_avent/binary_sensor.py
  • custom_components/philips_avent/coordinator.py
  • tests/test_philips_avent/test_lan.py

📝 Walkthrough

Walkthrough

The coordinator now tracks each LAN DPS update separately from merged state. AventSoundDetected processes only new LAN sequences, and tests cover retained sound events and identical payloads received in separate updates.

Changes

LAN sound-event tracking

Layer / File(s) Summary
LAN update tracking
custom_components/philips_avent/coordinator.py
Initializes LAN tracking state, stores each received DPS payload, and increments the update sequence for every update.
Fresh sound detection
custom_components/philips_avent/binary_sensor.py, tests/test_philips_avent/test_lan.py
Processes only fresh LAN payloads and tests retained-state separation plus repeated identical sound payloads.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: thekoma

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: preventing stale Philips Avent sound events from replaying.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (trivial_assertion). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

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