Skip to content

Handle FCM events without ding IDs - #540

Open
danielcolquitt wants to merge 1 commit into
python-ring-doorbell:masterfrom
danielcolquitt:fix-fcm-missing-event-id
Open

danielcolquitt wants to merge 1 commit into
python-ring-doorbell:masterfrom
danielcolquitt:fix-fcm-missing-event-id

Conversation

@danielcolquitt

Copy link
Copy Markdown

Summary

  • Handle Ring FCM payloads that omit event.ding.id.
  • Derive a deterministic fallback event ID from created_at.
  • Preserve event delivery and duplicate-update detection.
  • Prevent repeated KeyError callback failures from shutting down real-time events for all devices.
  • Add regression coverage for repeated ID-less motion notifications.

Fixes #537

Testing

  • uv run pre-commit run --files ring_doorbell/listen/eventlistener.py tests/test_listen.py --verbose
  • uv run pytest tests/ --force-enable-socket --cov=ring_doorbell --cov-report=xml --cov-report=term-missing --import-mode importlib
  • Built and tested in Home Assistant Container.
  • Confirmed motion event entities update for multiple Ring cameras and doorbells.

@danielcolquitt

Copy link
Copy Markdown
Author

Brief follow-up after a couple of weeks: this fix remains in production use and ID-less FCM events are being handled correctly without the repeated callback failures. It has also since been referenced from Home Assistant Core issue #177118. Happy to adjust the fallback-ID approach if preferred.

@sjmatta

sjmatta commented Sep 9, 2026

Copy link
Copy Markdown

Seeing this too on Home Assistant Container 2026.9.1 with ring-doorbell 0.9.14 and Python 3.14. Same KeyError: 'id' at event["ding"]["id"] in _get_ring_event, followed by Unexpected exception calling notification callback. It was also happening before the HA update.

+1 for this fix. Keeping those notifications flowing through to HA would be useful so motion/doorbell events don't get dropped. I haven't tested the patch yet.

@mparmpathomas

Copy link
Copy Markdown

Another confirmation from Home Assistant 2026.9.1 with ring-doorbell==0.9.14, plus one detail I have not seen in this thread: the failure is self-perpetuating, so the symptom is not a single missed event but a listener that stays dead until someone intervenes.

What happened here on 2026-09-11: three notifications from the previous morning were still sitting unacked in the FCM queue. They were replayed on every connect, _get_ring_event raised KeyError: 'id' on each one, and firebase-messaging counted three sequential NOTIFY errors and shut the receiver down (abort_on_sequential_error_count = 3 in fcmpushclient.py) in the same breath as the acks — so the same three messages came back and killed it again on the next connect. The listener was down for about a day and a half. Roughly twenty Ring app notifications produced zero Home Assistant events, while history polling carried on updating normally, which makes it look like a Home Assistant problem rather than a push problem.

Two things that may save someone else time:

  1. A stuck backlog is distinguishable from a live event by the FCM message id (0:<epoch-ms><digits>%...). Hours old means replay, not a fresh notification. The library raises before it can log the payload, so firebase_messaging: debug and ring_doorbell: debug are needed to see the ids at all.

  2. Clearing the backlog does not by itself restore delivery. Deleting listen_token from the config entry forces a fresh FCM registration and orphans the poisoned messages, which stops the crash loop — but Ring binds push to the device record, keyed on the hardware_id/device_id the integration registered with. A new token against the old device record is accepted and then silently ignored: no crash, no events, nothing in the log at default level. Only the integration's Reconfigure flow mints a new hardware_id (Reauth deliberately reuses the old one), followed by a restart.

That second point is the reason the crash loop and the loss of delivery need separate fixes today. This PR removes the first one, which is the one that matters: it would have turned a day and a half of silence into a handful of ignored notifications.

Gerrrt added a commit to Gerrrt/HomeLab that referenced this pull request Oct 21, 2026
…0101) (#1241)

* feat(home-assistant): patch ring_doorbell's push parser locally (ADR-0101)

ring_doorbell 0.9.14's RingEventListener._get_ring_event raises KeyError
on Ring pushes with no ding.id, and firebase_messaging shuts the push
receiver down after three in a row. After that no Ring motion or doorbell
event reaches Home Assistant. On trinity that happened at 13:12 and
again seconds after the 14:09 restart (python-ring-doorbell/python-ring-doorbell#537. Upstream PRs
python-ring-doorbell/python-ring-doorbell#540 and #556 are open, with
no release since February.)

custom_components/ring_push_guard, mounted read-only and loaded by
packages/ring_push_guard.yaml, replaces that one method for 0.9.14 only.
The id falls back to eventito.timestamp, then created_at in ms, and
anything unparseable is skipped instead of raised. Any other version is
left alone, with a warning. If Ring set up first, its entry is reloaded
once so the listener restarts patched.

Tested in the pinned image: the original raises on an id-less push. The
patch handles normal, id-less (both fallbacks), malformed and non-Ring
pushes. Three id-less pushes and a malformed one through the real
_on_notification raise nothing, and repeat detection still works. ruff
0.17.0 (the pinned version) and check_config pass.

Refs #1240

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(home-assistant): reload a Ring entry that is still setting up

Ring starts its push receiver during platform setup, while its entry
reads SETUP_IN_PROGRESS. A replayed bad push can stop the receiver in
that window, and the LOADED-only check then skipped the reload for good.
The guard now also reloads entries in SETUP_IN_PROGRESS and
SETUP_RETRY. async_reload takes the entry's setup lock, so a reload
asked for mid-setup waits for setup to finish. Tested across every
ConfigEntryState. ADR-0101 says the same.

Refs #1240

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Event listener dies: KeyError 'id' in _get_ring_event — some Ring FCM payloads no longer contain ding.id

3 participants