From 91982c4f7ef8aa50e1a3cb3bda615083299a64eb Mon Sep 17 00:00:00 2001
From: Nicolas Mowen <nickmowen213@gmail.com>
Date: Fri, 25 Nov 2022 19:10:09 -0700
Subject: [PATCH] Remove topic prefix (#4515)

---
 frigate/app.py               |  1 -
 frigate/object_processing.py | 28 ++++++++++------------------
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/frigate/app.py b/frigate/app.py
index 2f020bdc6..f62d4a78a 100644
--- a/frigate/app.py
+++ b/frigate/app.py
@@ -218,7 +218,6 @@ class FrigateApp:
         self.detected_frames_processor = TrackedObjectProcessor(
             self.config,
             self.dispatcher,
-            self.config.mqtt.topic_prefix,
             self.detected_frames_queue,
             self.event_queue,
             self.event_processed_queue,
diff --git a/frigate/object_processing.py b/frigate/object_processing.py
index f87373569..4ea3b5e6c 100644
--- a/frigate/object_processing.py
+++ b/frigate/object_processing.py
@@ -634,7 +634,6 @@ class TrackedObjectProcessor(threading.Thread):
         self,
         config: FrigateConfig,
         dispatcher: Dispatcher,
-        topic_prefix,
         tracked_objects_queue,
         event_queue,
         event_processed_queue,
@@ -646,7 +645,6 @@ class TrackedObjectProcessor(threading.Thread):
         self.name = "detected_frames_processor"
         self.config = config
         self.dispatcher = dispatcher
-        self.topic_prefix = topic_prefix
         self.tracked_objects_queue = tracked_objects_queue
         self.event_queue = event_queue
         self.event_processed_queue = event_processed_queue
@@ -669,9 +667,7 @@ class TrackedObjectProcessor(threading.Thread):
                 "after": after,
                 "type": "new" if obj.previous["false_positive"] else "update",
             }
-            self.dispatcher.publish(
-                f"{self.topic_prefix}/events", json.dumps(message), retain=False
-            )
+            self.dispatcher.publish("events", json.dumps(message), retain=False)
             obj.previous = after
             self.event_queue.put(
                 ("update", camera, obj.to_dict(include_thumbnail=True))
@@ -724,9 +720,7 @@ class TrackedObjectProcessor(threading.Thread):
                     "after": obj.to_dict(),
                     "type": "end",
                 }
-                self.dispatcher.publish(
-                    f"{self.topic_prefix}/events", json.dumps(message), retain=False
-                )
+                self.dispatcher.publish("/events", json.dumps(message), retain=False)
 
             self.event_queue.put(("end", camera, obj.to_dict(include_thumbnail=True)))
 
@@ -747,15 +741,13 @@ class TrackedObjectProcessor(threading.Thread):
                     )
                 else:
                     self.dispatcher.publish(
-                        f"{self.topic_prefix}/{camera}/{obj.obj_data['label']}/snapshot",
+                        f"{camera}/{obj.obj_data['label']}/snapshot",
                         jpg_bytes,
                         retain=True,
                     )
 
         def object_status(camera, object_name, status):
-            self.dispatcher.publish(
-                f"{self.topic_prefix}/{camera}/{object_name}", status, retain=False
-            )
+            self.dispatcher.publish(f"{camera}/{object_name}", status, retain=False)
 
         for camera in self.config.cameras.keys():
             camera_state = CameraState(camera, self.config, self.frame_manager)
@@ -854,7 +846,7 @@ class TrackedObjectProcessor(threading.Thread):
             # only send ON if motion isn't already active
             if self.last_motion_detected.get(camera, 0) == 0:
                 self.dispatcher.publish(
-                    f"{self.topic_prefix}/{camera}/motion",
+                    f"{camera}/motion",
                     "ON",
                     retain=False,
                 )
@@ -867,7 +859,7 @@ class TrackedObjectProcessor(threading.Thread):
             # If no motion, make sure the off_delay has passed
             if frame_time - self.last_motion_detected.get(camera, 0) >= mqtt_delay:
                 self.dispatcher.publish(
-                    f"{self.topic_prefix}/{camera}/motion",
+                    f"{camera}/motion",
                     "OFF",
                     retain=False,
                 )
@@ -963,7 +955,7 @@ class TrackedObjectProcessor(threading.Thread):
                         new_count = sum(zone_label.values())
                         if new_count != current_count:
                             self.dispatcher.publish(
-                                f"{self.topic_prefix}/{zone}/{label}",
+                                f"{zone}/{label}",
                                 new_count,
                                 retain=False,
                             )
@@ -976,7 +968,7 @@ class TrackedObjectProcessor(threading.Thread):
                         if label in obj_counter:
                             zone_label[camera] = obj_counter[label]
                             self.dispatcher.publish(
-                                f"{self.topic_prefix}/{zone}/{label}",
+                                f"{zone}/{label}",
                                 obj_counter[label],
                                 retain=False,
                             )
@@ -993,7 +985,7 @@ class TrackedObjectProcessor(threading.Thread):
 
                     if new_count != current_count:
                         self.dispatcher.publish(
-                            f"{self.topic_prefix}/{zone}/all",
+                            f"{zone}/all",
                             new_count,
                             retain=False,
                         )
@@ -1001,7 +993,7 @@ class TrackedObjectProcessor(threading.Thread):
                 else:
                     zone_label[camera] = total_label_count
                     self.dispatcher.publish(
-                        f"{self.topic_prefix}/{zone}/all",
+                        f"{zone}/all",
                         total_label_count,
                         retain=False,
                     )