Send camera activitiy in on connect

This commit is contained in:
Nicolas Mowen 2024-04-30 06:16:03 -06:00
parent 96061df5f5
commit 839f35f0a1
3 changed files with 23 additions and 11 deletions

View File

@ -2,6 +2,7 @@
import datetime
import logging
import json
from abc import ABC, abstractmethod
from typing import Any, Callable, Optional
@ -127,6 +128,8 @@ class Dispatcher:
).execute()
elif topic == UPDATE_CAMERA_ACTIVITY:
self.camera_activity = payload
elif topic == "onConnect":
self.publish("camera_activity", json.dumps(self.camera_activity))
else:
self.publish(topic, payload, retain=False)

View File

@ -50,6 +50,10 @@ class WebSocketClient(Communicator): # type: ignore[misc]
class _WebSocketHandler(WebSocket): # type: ignore[misc]
receiver = self._dispatcher
def opened(self) -> None:
"""A new websocket is opened, we need to send an update message"""
self.receiver("onConnect", "")
def received_message(self, message: WebSocket.received_message) -> None:
try:
json_message = json.loads(message.data.decode("utf-8"))

View File

@ -25,7 +25,7 @@ from frigate.config import (
SnapshotsConfig,
ZoomingModeEnum,
)
from frigate.const import CLIPS_DIR, UPDATE_CAMERA_ACTIVITY
from frigate.const import ALL_ATTRIBUTE_LABELS, CLIPS_DIR, UPDATE_CAMERA_ACTIVITY
from frigate.events.types import EventStateEnum, EventTypeEnum
from frigate.ptz.autotrack import PtzAutoTrackerThread
from frigate.util.image import (
@ -538,7 +538,9 @@ class CameraState:
):
max_target_box = self.ptz_autotracker_thread.ptz_autotracker.tracked_object_metrics[
self.name
]["max_target_box"]
][
"max_target_box"
]
side_length = max_target_box * (
max(
self.camera_config.detect.width,
@ -736,19 +738,22 @@ class CameraState:
< self.camera_config.detect.stationary.threshold
)
if (
obj.obj_data["position_changes"] > 0
and not obj.obj_data["false_positive"]
):
if object_type not in camera_activity:
camera_activity[object_type] = {
if not obj.false_positive:
label = object_type
if (
obj.obj_data.get("sub_label")
and obj.obj_data.get("sub_label")[0] in ALL_ATTRIBUTE_LABELS
):
label = obj.obj_data["sub_label"]
if label not in camera_activity:
camera_activity[label] = {
"active": 1 if active else 0,
"stationary": 1 if not active else 0,
}
else:
camera_activity[object_type][
"active" if active else "stationary"
] += 1
camera_activity[label]["active" if active else "stationary"] += 1
# if the object's thumbnail is not from the current frame
if obj.false_positive or obj.thumbnail_data["frame_time"] != frame_time: