88import pydantic
99import yaml
1010
11+ from virtualship .utils import _validate_numeric_mins_to_timedelta
12+
1113
1214class ArgoFloatConfig (pydantic .BaseModel ):
1315 """Configuration for argos floats."""
@@ -37,6 +39,10 @@ class ADCPConfig(pydantic.BaseModel):
3739 def _serialize_period (self , value : timedelta , _info ):
3840 return value .total_seconds () / 60.0
3941
42+ @pydantic .field_validator ("period" , mode = "before" )
43+ def _validate_period (cls , value : int | float | timedelta ) -> timedelta :
44+ return _validate_numeric_mins_to_timedelta (value )
45+
4046
4147class CTDConfig (pydantic .BaseModel ):
4248 """Configuration for CTD instrument."""
@@ -55,6 +61,10 @@ class CTDConfig(pydantic.BaseModel):
5561 def _serialize_stationkeeping_time (self , value : timedelta , _info ):
5662 return value .total_seconds () / 60.0
5763
64+ @pydantic .field_validator ("stationkeeping_time" , mode = "before" )
65+ def _validate_stationkeeping_time (cls , value : int | float | timedelta ) -> timedelta :
66+ return _validate_numeric_mins_to_timedelta (value )
67+
5868
5969class ShipUnderwaterSTConfig (pydantic .BaseModel ):
6070 """Configuration for underwater ST."""
@@ -71,6 +81,10 @@ class ShipUnderwaterSTConfig(pydantic.BaseModel):
7181 def _serialize_period (self , value : timedelta , _info ):
7282 return value .total_seconds () / 60.0
7383
84+ @pydantic .field_validator ("period" , mode = "before" )
85+ def _validate_period (cls , value : int | float | timedelta ) -> timedelta :
86+ return _validate_numeric_mins_to_timedelta (value )
87+
7488
7589class DrifterConfig (pydantic .BaseModel ):
7690 """Configuration for drifters."""
@@ -88,6 +102,10 @@ class DrifterConfig(pydantic.BaseModel):
88102 def _serialize_lifetime (self , value : timedelta , _info ):
89103 return value .total_seconds () / 60.0
90104
105+ @pydantic .field_validator ("lifetime" , mode = "before" )
106+ def _validate_lifetime (cls , value : int | float | timedelta ) -> timedelta :
107+ return _validate_numeric_mins_to_timedelta (value )
108+
91109
92110class XBTConfig (pydantic .BaseModel ):
93111 """Configuration for xbt instrument."""
0 commit comments