diff --git a/frigate/app.py b/frigate/app.py index fce3467ab..f23ff9c62 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -183,8 +183,7 @@ class FrigateApp: if self.config.mqtt.enabled: comms.append(MqttClient(self.config)) - self.ws_client = WebSocketClient(self.config) - comms.append(self.ws_client) + comms.append(WebSocketClient(self.config)) self.dispatcher = Dispatcher(self.config, self.camera_metrics, comms) def start_detectors(self) -> None: @@ -417,7 +416,7 @@ class FrigateApp: logger.info(f"Stopping...") self.stop_event.set() - self.ws_client.stop() + self.dispatcher.stop() self.detected_frames_processor.join() self.event_processor.join() self.event_cleanup.join() diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.py index aab011fe9..d304509e4 100644 --- a/frigate/comms/dispatcher.py +++ b/frigate/comms/dispatcher.py @@ -27,6 +27,11 @@ class Communicator(ABC): """Pass receiver so communicators can pass commands.""" pass + @abstractmethod + def stop(self) -> None: + """Stop the communicator.""" + pass + class Dispatcher: """Handle communication between Frigate and communicators.""" @@ -72,6 +77,10 @@ class Dispatcher: for comm in self.comms: comm.publish(topic, payload, retain) + def stop(self) -> None: + for comm in self.comms: + comm.stop() + def _on_detect_command(self, camera_name: str, payload: str) -> None: """Callback for detect topic.""" detect_settings = self.config.cameras[camera_name].detect diff --git a/frigate/comms/mqtt.py b/frigate/comms/mqtt.py index b8c1a0ea6..d106aae71 100644 --- a/frigate/comms/mqtt.py +++ b/frigate/comms/mqtt.py @@ -35,6 +35,9 @@ class MqttClient(Communicator): # type: ignore[misc] f"{self.mqtt_config.topic_prefix}/{topic}", payload, retain=retain ) + def stop(self) -> None: + self.client.disconnect() + def _set_initial_topics(self) -> None: """Set initial state topics.""" for camera_name, camera in self.config.cameras.items(): diff --git a/frigate/comms/ws.py b/frigate/comms/ws.py index 0a3aea169..c9cc3988a 100644 --- a/frigate/comms/ws.py +++ b/frigate/comms/ws.py @@ -95,3 +95,4 @@ class WebSocketClient(Communicator): # type: ignore[misc] self.websocket_server.manager.join() self.websocket_server.shutdown() self.websocket_thread.join() + logger.info("Exiting websocket client...")