2024-09-28 22:21:42 +03:00
from enum import Enum
from pydantic import Field , field_validator
2026-10-12 14:54:50 -05:00
from frigate.util.env import EnvString
2024-09-28 22:21:42 +03:00
from ..base import FrigateBaseModel
from .objects import DEFAULT_TRACKED_OBJECTS
__all__ = [ "OnvifConfig" , "PtzAutotrackConfig" , "ZoomingModeEnum" ]
class ZoomingModeEnum ( str , Enum ):
disabled = "disabled"
absolute = "absolute"
relative = "relative"
class PtzAutotrackConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable Autotracking" ,
description = "Enable or disable automatic PTZ camera tracking of detected objects." ,
)
2024-09-28 22:21:42 +03:00
calibrate_on_startup : bool = Field (
2026-02-27 09:55:36 -06:00
default = False ,
title = "Calibrate on start" ,
description = "Measure PTZ motor speeds on startup to improve tracking accuracy. Frigate will update config with movement_weights after calibration." ,
2024-09-28 22:21:42 +03:00
)
zooming : ZoomingModeEnum = Field (
2026-02-27 09:55:36 -06:00
default = ZoomingModeEnum . disabled ,
title = "Zoom mode" ,
description = "Control zoom behavior: disabled (pan/tilt only), absolute (most compatible), or relative (concurrent pan/tilt/zoom)." ,
2024-09-28 22:21:42 +03:00
)
zoom_factor : float = Field (
default = 0.3 ,
2026-02-27 09:55:36 -06:00
title = "Zoom factor" ,
description = "Control zoom level on tracked objects. Lower values keep more scene in view; higher values zoom in closer but may lose tracking. Values between 0.1 and 0.75." ,
2024-09-28 22:21:42 +03:00
ge = 0.1 ,
le = 0.75 ,
)
2026-02-27 09:55:36 -06:00
track : list [ str ] = Field (
default = DEFAULT_TRACKED_OBJECTS ,
title = "Tracked objects" ,
description = "List of object types that should trigger autotracking." ,
)
2024-09-28 22:21:42 +03:00
required_zones : list [ str ] = Field (
default_factory = list ,
2026-02-27 09:55:36 -06:00
title = "Required zones" ,
description = "Objects must enter one of these zones before autotracking begins." ,
2024-09-28 22:21:42 +03:00
)
return_preset : str = Field (
default = "home" ,
2026-02-27 09:55:36 -06:00
title = "Return preset" ,
description = "ONVIF preset name configured in camera firmware to return to after tracking ends." ,
2024-09-28 22:21:42 +03:00
)
timeout : int = Field (
2026-02-27 09:55:36 -06:00
default = 10 ,
title = "Return timeout" ,
description = "Wait this many seconds after losing tracking before returning camera to preset position." ,
2024-09-28 22:21:42 +03:00
)
2026-07-06 09:28:02 -08:00
movement_weights : str | list [ str ] | None = Field (
2024-09-28 22:21:42 +03:00
default_factory = list ,
2026-02-27 09:55:36 -06:00
title = "Movement weights" ,
description = "Calibration values automatically generated by camera calibration. Do not modify manually." ,
2024-09-28 22:21:42 +03:00
)
2026-07-06 09:28:02 -08:00
enabled_in_config : bool | None = Field (
2026-02-27 09:55:36 -06:00
default = None ,
title = "Original autotrack state" ,
description = "Internal field to track whether autotracking was enabled in configuration." ,
2024-09-28 22:21:42 +03:00
)
@field_validator ( "movement_weights" , mode = "before" )
@classmethod
def validate_weights ( cls , v ):
if v is None :
return None
if isinstance ( v , str ):
weights = list ( map ( str , map ( float , v . split ( "," ))))
elif isinstance ( v , list ):
weights = [ str ( float ( val )) for val in v ]
else :
raise ValueError ( "Invalid type for movement_weights" )
2025-04-29 11:17:56 -05:00
if len ( weights ) != 6 :
2025-02-09 15:29:08 -06:00
raise ValueError (
2025-04-29 11:17:56 -05:00
"movement_weights must have exactly 6 floats, remove this line from your config and run autotracking calibration"
2025-02-09 15:29:08 -06:00
)
2024-09-28 22:21:42 +03:00
return weights
class OnvifConfig ( FrigateBaseModel ):
2026-03-22 17:34:11 -05:00
host : EnvString = Field (
2026-02-27 09:55:36 -06:00
default = "" ,
title = "ONVIF host" ,
description = "Host (and optional scheme) for the ONVIF service for this camera." ,
)
port : int = Field (
default = 8000 ,
title = "ONVIF port" ,
description = "Port number for the ONVIF service." ,
)
2026-07-06 09:28:02 -08:00
user : EnvString | None = Field (
2026-02-27 09:55:36 -06:00
default = None ,
title = "ONVIF username" ,
description = "Username for ONVIF authentication; some devices require admin user for ONVIF." ,
)
2026-07-06 09:28:02 -08:00
password : EnvString | None = Field (
2026-02-27 09:55:36 -06:00
default = None ,
title = "ONVIF password" ,
description = "Password for ONVIF authentication." ,
)
tls_insecure : bool = Field (
default = False ,
title = "Disable TLS verify" ,
description = "Skip TLS verification and disable digest auth for ONVIF (unsafe; use in safe networks only)." ,
)
2026-07-06 09:28:02 -08:00
profile : str | None = Field (
2026-03-25 08:57:47 -05:00
default = None ,
title = "ONVIF profile" ,
description = "Specific ONVIF media profile to use for PTZ control, matched by token or name. If not set, the first profile with valid PTZ configuration is selected automatically." ,
)
2024-09-28 22:21:42 +03:00
autotracking : PtzAutotrackConfig = Field (
default_factory = PtzAutotrackConfig ,
2026-02-27 09:55:36 -06:00
title = "Autotracking" ,
description = "Automatically track moving objects and keep them centered in the frame using PTZ camera movements." ,
2024-09-28 22:21:42 +03:00
)
ignore_time_mismatch : bool = Field (
default = False ,
2026-02-27 09:55:36 -06:00
title = "Ignore time mismatch" ,
description = "Ignore time synchronization differences between camera and Frigate server for ONVIF communication." ,
2024-09-28 22:21:42 +03:00
)