Skip to content

Track FCM receiver health in the event listener - #555

Open
thomasgregg wants to merge 1 commit into
python-ring-doorbell:masterfrom
thomasgregg:codex/listener-lifecycle
Open

thomasgregg wants to merge 1 commit into
python-ring-doorbell:masterfrom
thomasgregg:codex/listener-lifecycle

Conversation

@thomasgregg

Copy link
Copy Markdown

Summary

  • Make RingEventListener.started reflect the FCM receiver's actual logged-in state.
  • Wait for confirmed MCS login inside the existing startup timeout.
  • Serialize concurrent start/stop operations and make repeated starts share one healthy receiver.
  • Fully clean up timed-out and partially initialized starts without masking pre-start registration errors.
  • Track the actual internal callback ID instead of assuming it is always 1.

Why

FcmPushClient.start() schedules its background tasks and returns before MCS login. RingEventListener currently sets an independent started = True immediately afterward. If login never succeeds, or if the receiver later terminates after repeated errors, the Ring listener can continue to report that it is started even though no notifications can arrive.

That stale state is the failure described in #526: downstream callers cannot distinguish “no event occurred” from “the receiver is dead.” It also makes a safe retry difficult because overlapping starts can add duplicate internal callbacks and leave partial state behind.

After this change, startup succeeds only after FcmPushClient.is_started() confirms login. The public started property then follows that receiver health, so a later receiver termination becomes visible to callers. This PR deliberately does not add an automatic retry policy; it provides the trustworthy lifecycle contract required for a caller such as Home Assistant to implement one.

The callback-ID change also covers the documented usage pattern where a consumer registers its callback before calling start(). In that order, the library's internal callback is not ID 1.

This does not touch push-payload parsing and therefore does not overlap with #540.

Fixes #526.

Tests

Added regression coverage for:

  • delayed MCS readiness;
  • receiver death after a successful start;
  • concurrent starts;
  • startup timeout cleanup;
  • registration failure before receiver start; and
  • a user callback registered before startup.

Full suite: 46 passed. Ruff format/lint, mypy, and git diff --check pass.

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.

RingEventListener can remain started after FCM push receiver shuts down, leaving notifications dead until restart

1 participant