From 407ed24d36a01159c63f5498e6ecbeecb7a80a96 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Tue, 22 Nov 2022 12:35:10 -0700 Subject: [PATCH] Setup communication layer --- frigate/communication/dispatcher.py | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 frigate/communication/dispatcher.py diff --git a/frigate/communication/dispatcher.py b/frigate/communication/dispatcher.py new file mode 100644 index 000000000..8459dc2f0 --- /dev/null +++ b/frigate/communication/dispatcher.py @@ -0,0 +1,33 @@ +"""Handle communication between frigate and other applications.""" + +from abc import ABC, abstractmethod + +from frigate.config import FrigateConfig +from frigate.types import CameraMetricsTypes + + +class Communicator(ABC): + """pub/sub model via specific protocol.""" + + @abstractmethod + def publish(topic: str, payload, retain: bool = False): + """Send data via specific protocol.""" + pass + + @abstractmethod + def subscribe(receiver): + pass + + +class Dispatcher: + """Handle communication between frigate and communicators.""" + + def __init__( + self, + config: FrigateConfig, + camera_metrics: dict[str, CameraMetricsTypes], + communicators: list[Communicator], + ) -> None: + self.config = config + self.camera_metrics = camera_metrics + self.comms = communicators