Improve storage mypy

This commit is contained in:
Nicolas Mowen 2026-03-25 13:11:09 -06:00
parent 9f87d4b72f
commit 7e2f5b98d5
2 changed files with 9 additions and 5 deletions

View File

@ -71,6 +71,9 @@ ignore_errors = false
[mypy-frigate.stats] [mypy-frigate.stats]
ignore_errors = false ignore_errors = false
[mypy-frigate.storage]
ignore_errors = false
[mypy-frigate.track.*] [mypy-frigate.track.*]
ignore_errors = false ignore_errors = false

View File

@ -3,6 +3,7 @@
import logging import logging
import shutil import shutil
import threading import threading
from multiprocessing.synchronize import Event as MpEvent
from pathlib import Path from pathlib import Path
from peewee import SQL, fn from peewee import SQL, fn
@ -23,7 +24,7 @@ MAX_CALCULATED_BANDWIDTH = 10000 # 10Gb/hr
class StorageMaintainer(threading.Thread): class StorageMaintainer(threading.Thread):
"""Maintain frigates recording storage.""" """Maintain frigates recording storage."""
def __init__(self, config: FrigateConfig, stop_event) -> None: def __init__(self, config: FrigateConfig, stop_event: MpEvent) -> None:
super().__init__(name="storage_maintainer") super().__init__(name="storage_maintainer")
self.config = config self.config = config
self.stop_event = stop_event self.stop_event = stop_event
@ -114,7 +115,7 @@ class StorageMaintainer(threading.Thread):
logger.debug( logger.debug(
f"Storage cleanup check: {hourly_bandwidth} hourly with remaining storage: {remaining_storage}." f"Storage cleanup check: {hourly_bandwidth} hourly with remaining storage: {remaining_storage}."
) )
return remaining_storage < hourly_bandwidth return remaining_storage < float(hourly_bandwidth)
def reduce_storage_consumption(self) -> None: def reduce_storage_consumption(self) -> None:
"""Remove oldest hour of recordings.""" """Remove oldest hour of recordings."""
@ -124,7 +125,7 @@ class StorageMaintainer(threading.Thread):
[b["bandwidth"] for b in self.camera_storage_stats.values()] [b["bandwidth"] for b in self.camera_storage_stats.values()]
) )
recordings: Recordings = ( recordings = (
Recordings.select( Recordings.select(
Recordings.id, Recordings.id,
Recordings.camera, Recordings.camera,
@ -138,7 +139,7 @@ class StorageMaintainer(threading.Thread):
.iterator() .iterator()
) )
retained_events: Event = ( retained_events = (
Event.select( Event.select(
Event.start_time, Event.start_time,
Event.end_time, Event.end_time,
@ -278,7 +279,7 @@ class StorageMaintainer(threading.Thread):
Recordings.id << deleted_recordings_list[i : i + max_deletes] Recordings.id << deleted_recordings_list[i : i + max_deletes]
).execute() ).execute()
def run(self): def run(self) -> None:
"""Check every 5 minutes if storage needs to be cleaned up.""" """Check every 5 minutes if storage needs to be cleaned up."""
if self.config.safe_mode: if self.config.safe_mode:
logger.info("Safe mode enabled, skipping storage maintenance") logger.info("Safe mode enabled, skipping storage maintenance")