77from importlib .metadata import version
88from datetime import datetime
99from pathlib import Path
10- from typing import TypedDict , Any
10+ from typing import TypedDict , Any , overload
1111from urllib .parse import urljoin , urlparse
1212
1313import requests
@@ -127,7 +127,7 @@ def settings_monitor(self, uuid: str) -> MonitorCaptureSettings:
127127 :param uuid: The UUID we want the settings of.
128128 """
129129 r = self .session .get (urljoin (self .root_url , str (Path ('settings_monitor' , uuid ))))
130- return MonitorCaptureSettings ( ** r .json ())
130+ return MonitorCaptureSettings . model_validate ( r .json ())
131131
132132 def stop_monitor (self , uuid : str ) -> bool | dict [str , str ]:
133133 """Stop monitoring a specific capture
@@ -170,17 +170,17 @@ def update_monitor(self, monitor_uuid: str, *,
170170 _comp_s : CompareSettings | None
171171 _ns : NotificationSettings | None
172172 if isinstance (capture_settings , dict ):
173- _cs = LookylooCaptureSettings ( ** capture_settings )
173+ _cs = LookylooCaptureSettings . model_validate ( capture_settings )
174174 else :
175175 _cs = capture_settings
176176
177177 if isinstance (compare_settings , dict ):
178- _comp_s = CompareSettings ( ** compare_settings )
178+ _comp_s = CompareSettings . model_validate ( compare_settings )
179179 else :
180180 _comp_s = compare_settings
181181
182182 if isinstance (notification , dict ):
183- _ns = NotificationSettings ( ** notification )
183+ _ns = NotificationSettings . model_validate ( notification )
184184 else :
185185 _ns = notification
186186
@@ -194,10 +194,28 @@ def update_monitor(self, monitor_uuid: str, *,
194194 notification = _ns
195195 )
196196 r = self .session .post (urljoin (self .root_url , str (Path ('update_monitor' , monitor_uuid ))),
197- data = to_post .model_dump_json ())
197+ data = to_post .model_dump_json (exclude_none = True ))
198198 return r .json ()
199199
200- def monitor (self , capture_settings : LookylooCaptureSettings | dict [str , Any ], / , frequency : str , * ,
200+ @overload
201+ def monitor (self , * , monitor_capture_settings : MonitorCaptureSettings | dict [str , Any ] | None = None ) -> str :
202+ ...
203+
204+ @overload
205+ def monitor (self , * ,
206+ capture_settings : LookylooCaptureSettings | dict [str , Any ] | None = None ,
207+ frequency : str | None = None ,
208+ expire_at : datetime | str | int | float | None = None ,
209+ never_expire : bool = False ,
210+ collection : str | None = None ,
211+ compare_settings : CompareSettings | dict [str , Any ] | None = None ,
212+ notification : NotificationSettings | dict [str , Any ] | None = None ) -> str :
213+ ...
214+
215+ def monitor (self , * ,
216+ monitor_capture_settings : MonitorCaptureSettings | dict [str , Any ] | None = None ,
217+ capture_settings : LookylooCaptureSettings | dict [str , Any ] | None = None ,
218+ frequency : str | None = None ,
201219 expire_at : datetime | str | int | float | None = None ,
202220 never_expire : bool = False ,
203221 collection : str | None = None ,
@@ -213,34 +231,42 @@ def monitor(self, capture_settings: LookylooCaptureSettings | dict[str, Any], /,
213231 :param compare_settings: The comparison settings.
214232 :param notification: The notification settings.
215233 """
216- _cs : LookylooCaptureSettings | None
217- _comp_s : CompareSettings | None
218- _ns : NotificationSettings | None
219- if isinstance (capture_settings , dict ):
220- _cs = LookylooCaptureSettings (** capture_settings )
221- else :
222- _cs = capture_settings
223-
224- if isinstance (compare_settings , dict ):
225- _comp_s = CompareSettings (** compare_settings )
234+ to_post : MonitorCaptureSettings
235+ if monitor_capture_settings :
236+ if isinstance (monitor_capture_settings , dict ):
237+ to_post = MonitorCaptureSettings .model_validate (monitor_capture_settings )
238+ else :
239+ to_post = monitor_capture_settings
226240 else :
227- _comp_s = compare_settings
228-
229- if isinstance (notification , dict ):
230- _ns = NotificationSettings (** notification )
231- else :
232- _ns = notification
233-
234- to_post = MonitorCaptureSettings (
235- capture_settings = _cs ,
236- frequency = frequency ,
237- never_expire = never_expire ,
238- expire_at = expire_at ,
239- collection = collection ,
240- compare_settings = _comp_s ,
241- notification = _ns
242- )
243- r = self .session .post (urljoin (self .root_url , 'monitor' ), data = to_post .model_dump_json ())
241+ print (capture_settings )
242+ _cs : LookylooCaptureSettings | None
243+ _comp_s : CompareSettings | None
244+ _ns : NotificationSettings | None
245+ if isinstance (capture_settings , dict ):
246+ _cs = LookylooCaptureSettings .model_validate (capture_settings )
247+ else :
248+ _cs = capture_settings
249+
250+ if isinstance (compare_settings , dict ):
251+ _comp_s = CompareSettings .model_validate (compare_settings )
252+ else :
253+ _comp_s = compare_settings
254+
255+ if isinstance (notification , dict ):
256+ _ns = NotificationSettings .model_validate (notification )
257+ else :
258+ _ns = notification
259+
260+ to_post = MonitorCaptureSettings (
261+ capture_settings = _cs ,
262+ frequency = frequency ,
263+ never_expire = never_expire ,
264+ expire_at = expire_at ,
265+ collection = collection ,
266+ compare_settings = _comp_s ,
267+ notification = _ns
268+ )
269+ r = self .session .post (urljoin (self .root_url , 'monitor' ), data = to_post .model_dump_json (exclude_none = True ))
244270 return r .json ()
245271
246272 def instance_settings (self ) -> MonitoringInstanceSettings :
0 commit comments