Upgrade Frigate to v0.14.0 #12

This commit is contained in:
ashish committed 2024-08-11 19:28:53 -05:00
1 parent de4b7792d1
commit 16493e884d
3 files changed
+32 -24

No files matched your search

+13 -13
View File
@@ -8,25 +8,25 @@ import paho.mqtt.client as mqtt
class FrigateEventNotifier:
def __init__(self, mqtt_username, mqtt_password, quiet_period=3 * 60):
self.mqtt_client = mqtt.Client()
self._mqtt_client = mqtt.Client()
if mqtt_username is not None and mqtt_password is not None:
self.mqtt_client.username_pw_set(mqtt_username, password=mqtt_password)
self.mqtt_client.on_connect = self._on_connect
self.mqtt_client.on_message = self._on_message
self._mqtt_client.username_pw_set(mqtt_username, password=mqtt_password)
self._mqtt_client.on_connect = self._on_connect
self._mqtt_client.on_message = self._on_message
frigate_api_response = requests.get("http://frigate:5000/api/config")
frigate_api_response.raise_for_status()
frigate_config = json.loads(frigate_api_response.content)
self.camera_zones = {camera_name: {required_zone: {object_label for object_label in camera_config["zones"][required_zone]["objects"]} for required_zone in camera_config["record"]["events"]["required_zones"]} for camera_name, camera_config in frigate_config["cameras"].items()}
self._camera_zones = {camera_name: {required_zone: {object_label for object_label in camera_config["zones"][required_zone]["objects"]} for required_zone in camera_config["review"]["alerts"]["required_zones"]} for camera_name, camera_config in frigate_config["cameras"].items()}
self.quiet_period = quiet_period
self.last_notification_time = {}
self._quiet_period = quiet_period
self._camera_to_last_notification_time = {}
def send_notification(self, event_id, camera, object_label, score, priority=3):
now = dt.datetime.now()
if now - self.last_notification_time.get(camera, dt.datetime.min) >= dt.timedelta(seconds=self.quiet_period):
if now - self._camera_to_last_notification_time.get(camera, dt.datetime.min) >= dt.timedelta(seconds=self._quiet_period):
# Quiet period has passed since the last notification for this camera
self.last_notification_time[camera] = now
self._camera_to_last_notification_time[camera] = now
camera_location = " ".join(word.capitalize() for word in camera.split("_"))
ntfy_api_response = requests.post("https://ntfy.homelab.net", json={
@@ -83,8 +83,8 @@ class FrigateEventNotifier:
ntfy_api_response.raise_for_status()
def start(self):
self.mqtt_client.connect(host="mqtt", port=1883)
self.mqtt_client.loop_forever()
self._mqtt_client.connect(host="mqtt", port=1883)
self._mqtt_client.loop_forever()
def _on_connect(self, client, userdata, flags, rc):
print(f"Connected with return code {rc}")
@@ -95,7 +95,7 @@ class FrigateEventNotifier:
camera = payload["after"]["camera"]
object_label = payload["after"]["label"]
if not self.camera_zones[camera]:
if not self._camera_zones[camera]:
# No required zones, send notification on receipt of new event
if payload["type"] == "new":
event_id = payload["after"]["id"]
@@ -105,7 +105,7 @@ class FrigateEventNotifier:
else:
new_zones = set(payload["after"]["entered_zones"]) - set(payload["before"]["entered_zones"])
for zone in new_zones:
if zone in self.camera_zones[camera] and (not self.camera_zones[camera][zone] or object_label in self.camera_zones[camera][zone]):
if zone in self._camera_zones[camera] and (not self._camera_zones[camera][zone] or object_label in self._camera_zones[camera][zone]):
event_id = payload["after"]["id"]
score = payload["after"]["top_score"]