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

View File

@ -50,6 +50,10 @@ class WebSocketClient(Communicator): # type: ignore[misc]
class _WebSocketHandler(WebSocket): # type: ignore[misc] class _WebSocketHandler(WebSocket): # type: ignore[misc]
receiver = self._dispatcher 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: def received_message(self, message: WebSocket.received_message) -> None:
try: try:
json_message = json.loads(message.data.decode("utf-8")) json_message = json.loads(message.data.decode("utf-8"))

View File

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