From 999d676e0a09a3bb2dbd6ea4de9491a94f92e017 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Wed, 10 Jul 2024 12:01:37 -0600 Subject: [PATCH] Add basic notification implementation --- docker/main/requirements-wheels.txt | 4 ++- frigate/comms/firebase.py | 46 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 frigate/comms/firebase.py diff --git a/docker/main/requirements-wheels.txt b/docker/main/requirements-wheels.txt index 4b4e13850..ab3152090 100644 --- a/docker/main/requirements-wheels.txt +++ b/docker/main/requirements-wheels.txt @@ -36,4 +36,6 @@ chromadb == 0.5.0 # Generative AI google-generativeai == 0.6.* ollama == 0.2.* -openai == 1.30.* \ No newline at end of file +openai == 1.30.* +# Notifications +firebase_admin == 6.5.0 \ No newline at end of file diff --git a/frigate/comms/firebase.py b/frigate/comms/firebase.py new file mode 100644 index 000000000..cb8fe461e --- /dev/null +++ b/frigate/comms/firebase.py @@ -0,0 +1,46 @@ +import logging +from typing import Any, Callable + +import firebase_admin +from firebase_admin import messaging + +from frigate.comms.dispatcher import Communicator +from frigate.config import FrigateConfig + +logger = logging.getLogger(__name__) + + +class FirebaseClient(Communicator): # type: ignore[misc] + """Frigate wrapper for firebase client.""" + + def __init__(self, config: FrigateConfig) -> None: + firebase_admin.initialize_app( + options={ + "apiKey": "AIzaSyCoweRLtvai8iNwhsoT-GH_CH_0pckqMmA", + "authDomain": "frigate-ed674.firebaseapp.com", + "projectId": "frigate-ed674", + "storageBucket": "frigate-ed674.appspot.com", + "messagingSenderId": "76314288339", + "appId": "1:76314288339:web:090e170610d3bf0966f426", + "measurementId": "G-GZ1JKNDJZK", + } + ) + + def subscribe(self, receiver: Callable) -> None: + """Wrapper for allowing dispatcher to subscribe.""" + pass + + def publish(self, topic: str, payload: Any, retain: bool = False) -> None: + """Wrapper for publishing when client is in valid state.""" + if topic == "review": + message = messaging.MulticastMessage( + notification=messaging.Notification( + title="Something happened", + body="There is a body", + ), + tokens=[], + ) + messaging.send_multicast(message) + + def stop(self) -> None: + pass