Enable mypy for DB and fix types (#19434)

* Install peewee type hints

* Models now have proper types

* Fix iterator type

* Enable debug builds with dev reqs installed

* Install as wheel

* Fix cast type
This commit is contained in:
Nicolas Mowen
2025-08-16 10:20:33 -05:00
committed by Blake Blackshear
parent 6ecc631486
commit 7c1681e344
7 changed files with 31 additions and 16 deletions
+2 -2
View File
@@ -3,7 +3,7 @@
import datetime
import json
import logging
from typing import Any, Callable, Optional
from typing import Any, Callable, Optional, cast
from frigate.camera import PTZMetrics
from 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",
+1 -1
View File
@@ -70,7 +70,7 @@ class WebPushClient(Communicator):
# Pull keys from PEM or generate if they do not exist
self.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:
+11 -11
View File
@@ -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 grid
last_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)