Skip to content

Replace Ring event polling with RingEventListener push stream#1

Merged
atmelmicro merged 2 commits into
mainfrom
copilot/change-event-detection-to-stream
Mar 2, 2026
Merged

Replace Ring event polling with RingEventListener push stream#1
atmelmicro merged 2 commits into
mainfrom
copilot/change-event-detection-to-stream

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

The event detection loop polled ring.active_alerts() every 5 seconds. This is replaced with RingEventListener, which receives push notifications via Firebase Cloud Messaging for real-time event delivery.

Changes

app/database.py

  • Added ListenerCredentials table to persist FCM registration credentials across restarts, avoiding re-registration on every startup

app/ring_manager.py

  • Replaced the 5-second polling loop in start_listener() with RingEventListener:
    self._event_listener = RingEventListener(
        self.ring,
        credentials,
        self._listener_credentials_updated,
    )
    self._event_listener.add_notification_callback(self._on_event)
    started = await self._event_listener.start()
  • Added _on_event(event) callback — resolves device from event.doorbot_id and dispatches capture_video via asyncio.create_task()
  • Added DB helpers to load/save FCM credentials; _listener_credentials_updated persists refreshed tokens
  • stop() and ring_logout() now call await event_listener.stop()
  • _finalise_auth() now awaits start_listener() directly (no longer needs a background task)

app/main.py

  • Startup now awaits start_listener() directly instead of wrapping in create_task
  • Removed unused asyncio import
Original prompt

Change the event detection from polling to a event stream.

Here is a useful part from the docs

event_listener = RingEventListener(ring, credentials, credentials_updated_callback)
event_listener.add_notification_callback(_event_handler(ring).on_event)
await event_listener.start()


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: atmelmicro <114749286+atmelmicro@users.noreply.github.com>
Copilot AI changed the title [WIP] Change event detection from polling to event stream Replace Ring event polling with RingEventListener push stream Mar 2, 2026
@atmelmicro atmelmicro marked this pull request as ready for review March 2, 2026 07:48
@atmelmicro atmelmicro merged commit 069c7ef into main Mar 2, 2026
2 checks passed
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.

2 participants