NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Enable mypy for DB and fix types (#19434)
Nicolas Mowen7c1681e34425
diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.ymlindex 02fde5861e..ebe107d3d2 100644--- a/.github/workflows/pull_request.yml+++ b/.github/workflows/pull_request.yml@@ -107,7 +107,7 @@ jobs:- name: Set up Docker Buildxuses: docker/setup-buildx-action@v3- name: Build- run: make+ run: make debug- name: Run mypyrun: docker run --rm --entrypoint=python3 frigate:latest -u -m mypy --config-file frigate/mypy.ini frigate- name: Run testsdiff --git a/Makefile b/Makefileindex 1c4e137a19..2baac5aada 100644--- a/Makefile+++ b/Makefile@@ -20,6 +20,12 @@ local: version--tag frigate:latest \--load+debug: version+ docker buildx build --target=frigate --file docker/main/Dockerfile . \+ --build-arg DEBUG=true \+ --tag frigate:latest \+ --load+amd64:docker buildx build --target=frigate --file docker/main/Dockerfile . \--tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) \diff --git a/docker/main/Dockerfile b/docker/main/Dockerfileindex 2f5db433ba..ca93f4a3b1 100644--- a/docker/main/Dockerfile+++ b/docker/main/Dockerfile@@ -148,6 +148,7 @@ RUN --mount=type=bind,source=docker/main/install_s6_overlay.sh,target=/deps/instFROM base AS wheelsARG DEBIAN_FRONTENDARG TARGETARCH+ARG DEBUG=false# Use a separate container to build wheels to prevent build dependencies in final imageRUN apt-get -qq update \@@ -177,6 +178,8 @@ RUN wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py \&& python3 get-pip.py "pip"COPY docker/main/requirements.txt /requirements.txt+COPY docker/main/requirements-dev.txt /requirements-dev.txt+RUN pip3 install -r /requirements.txt# Build pysqlite3 from source@@ -184,7 +187,10 @@ COPY docker/main/build_pysqlite3.sh /build_pysqlite3.shRUN /build_pysqlite3.shCOPY docker/main/requirements-wheels.txt /requirements-wheels.txt-RUN pip3 wheel --wheel-dir=/wheels -r /requirements-wheels.txt+RUN pip3 wheel --wheel-dir=/wheels -r /requirements-wheels.txt && \+ if [ "$DEBUG" = "true" ]; then \+ pip3 wheel --wheel-dir=/wheels -r /requirements-dev.txt; \+ fi# Install HailoRT & WheelsRUN --mount=type=bind,source=docker/main/install_hailort.sh,target=/deps/install_hailort.sh \diff --git a/docker/main/requirements-dev.txt b/docker/main/requirements-dev.txtindex af3ee57638..ac9d357583 100644--- a/docker/main/requirements-dev.txt+++ b/docker/main/requirements-dev.txt@@ -1 +1,4 @@ruff++# types+types-peewee == 3.17.*diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.pyindex 8d6a7dd81e..302c22170c 100644--- a/frigate/comms/dispatcher.py+++ b/frigate/comms/dispatcher.py@@ -3,7 +3,7 @@import datetimeimport jsonimport logging-from typing import Any, Callable, Optional+from typing import Any, Callable, Optional, castfrom frigate.camera import PTZMetricsfrom frigate.camera.activity_manager import CameraActivityManager@@ -135,7 +135,7 @@ class Dispatcher:def handle_update_event_description() -> None:event: Event = Event.get(Event.id == payload["id"])- event.data["description"] = payload["description"]+ cast(dict, event.data)["description"] = payload["description"]event.save()self.publish("tracked_object_update",diff --git a/frigate/comms/webpush.py b/frigate/comms/webpush.pyindex 8b723483f2..4a7f14f7df 100644--- a/frigate/comms/webpush.py+++ b/frigate/comms/webpush.py@@ -70,7 +70,7 @@ class WebPushClient(Communicator):# Pull keys from PEM or generate if they do not existself.vapid = Vapid01.from_file(os.path.join(CONFIG_DIR, "notifications.pem"))- users: list[User] = (+ users: list[dict[str, Any]] = (User.select(User.username, User.notification_tokens).dicts().iterator())for user in users:diff --git a/frigate/models.py b/frigate/models.pyindex 0ef4650b39..61889fd1e1 100644--- a/frigate/models.py+++ b/frigate/models.py@@ -13,7 +13,7 @@ from peewee import (from playhouse.sqlite_ext import JSONField-class Event(Model): # type: ignore[misc]+class Event(Model):id = CharField(null=False, primary_key=True, max_length=30)label = CharField(index=True, max_length=20)sub_label = CharField(max_length=100, null=True)@@ -51,7 +51,7 @@ class Event(Model): # type: ignore[misc]data = JSONField() # ex: tracked object box, region, etc.-class Timeline(Model): # type: ignore[misc]+class Timeline(Model):timestamp = DateTimeField()camera = CharField(index=True, max_length=20)source = CharField(index=True, max_length=20) # ex: tracked object, audio, external@@ -60,13 +60,13 @@ class Timeline(Model): # type: ignore[misc]data = JSONField() # ex: tracked object id, region, box, etc.-class Regions(Model): # type: ignore[misc]+class Regions(Model):camera = CharField(null=False, primary_key=True, max_length=20)grid = JSONField() # json blob of gridlast_update = DateTimeField()-class Recordings(Model): # type: ignore[misc]+class Recordings(Model):id = CharField(null=False, primary_key=True, max_length=30)camera = CharField(index=True, max_length=20)path = CharField(unique=True)@@ -80,7 +80,7 @@ class Recordings(Model): # type: ignore[misc]regions = IntegerField(null=True)-class Export(Model): # type: ignore[misc]+class Export(Model):id = CharField(null=False, primary_key=True, max_length=30)camera = CharField(index=True, max_length=20)name = CharField(index=True, max_length=100)@@ -90,7 +90,7 @@ class Export(Model): # type: ignore[misc]in_progress = BooleanField()-class ReviewSegment(Model): # type: ignore[misc]+class ReviewSegment(Model):id = CharField(null=False, primary_key=True, max_length=30)camera = CharField(index=True, max_length=20)start_time = DateTimeField()@@ -100,7 +100,7 @@ class ReviewSegment(Model): # type: ignore[misc]data = JSONField() # additional data about detection like list of labels, zone, areas of significant motion-class UserReviewStatus(Model): # type: ignore[misc]+class UserReviewStatus(Model):user_id = CharField(max_length=30)review_segment = ForeignKeyField(ReviewSegment, backref="user_reviews")has_been_reviewed = BooleanField(default=False)@@ -109,7 +109,7 @@ class UserReviewStatus(Model): # type: ignore[misc]indexes = ((("user_id", "review_segment"), True),)-class Previews(Model): # type: ignore[misc]+class Previews(Model):id = CharField(null=False, primary_key=True, max_length=30)camera = CharField(index=True, max_length=20)path = CharField(unique=True)@@ -119,14 +119,14 @@ class Previews(Model): # type: ignore[misc]# Used for temporary table in record/cleanup.py-class RecordingsToDelete(Model): # type: ignore[misc]+class RecordingsToDelete(Model):id = CharField(null=False, primary_key=False, max_length=30)class Meta:temporary = True-class User(Model): # type: ignore[misc]+class User(Model):username = CharField(null=False, primary_key=True, max_length=30)role = CharField(max_length=20,@@ -136,7 +136,7 @@ class User(Model): # type: ignore[misc]notification_tokens = JSONField()-class Trigger(Model): # type: ignore[misc]+class Trigger(Model):camera = CharField(max_length=20)name = CharField()type = CharField(max_length=10)