@@ -1185,10 +1185,10 @@ def motion_camera_ui_to_dict(ui, prev_config=None):
11851185 url = re .sub ('\\ s' , '+' , ui ['web_hook_notifications_url' ])
11861186
11871187 on_event_start .append (
1188- "{script} ' {useragent}' ' {accept}' '{method}' '{url}'" .format (
1188+ "{script} {useragent} {accept} '{method}' '{url}'" .format (
11891189 script = meyectl .find_command ('webhook' ),
1190- useragent = ui ['web_hook_notifications_user_agent' ],
1191- accept = ui ['web_hook_notifications_accept' ],
1190+ useragent = f"' { ui ['web_hook_notifications_user_agent' ]} '" if ui [ 'web_hook_notifications_user_agent' ] else '' ,
1191+ accept = f"' { ui ['web_hook_notifications_accept' ]} '" if ui [ 'web_hook_notifications_accept' ] else '' ,
11921192 method = ui ['web_hook_notifications_http_method' ],
11931193 url = url ,
11941194 )
@@ -1208,14 +1208,13 @@ def motion_camera_ui_to_dict(ui, prev_config=None):
12081208 url = re .sub (r'\s' , '+' , ui ['web_hook_end_notifications_url' ])
12091209
12101210 on_event_end .append (
1211- "%(script)s '%(useragent)s' '%(accept)s' '%(method)s' '%(url)s'"
1212- % {
1213- 'script' : meyectl .find_command ('webhook' ),
1214- 'useragent' : ui ['web_hook_end_notifications_user_agent' ],
1215- 'accept' : ui ['web_hook_end_notifications_accept' ],
1216- 'method' : ui ['web_hook_end_notifications_http_method' ],
1217- 'url' : url ,
1218- }
1211+ "{script} {useragent} {accept} '{method}' '{url}'" .format (
1212+ script = meyectl .find_command ('webhook' ),
1213+ useragent = f"'{ ui ['web_hook_end_notifications_user_agent' ]} '" if ui ['web_hook_end_notifications_user_agent' ] else '' ,
1214+ accept = f"'{ ui ['web_hook_end_notifications_accept' ]} '" if ui ['web_hook_end_notifications_accept' ] else '' ,
1215+ method = ui ['web_hook_end_notifications_http_method' ],
1216+ url = url ,
1217+ )
12191218 )
12201219
12211220 if ui ['command_end_notifications_enabled' ]:
@@ -1287,7 +1286,7 @@ def motion_camera_ui_to_dict(ui, prev_config=None):
12871286 return prev_config
12881287
12891288
1290- def motion_camera_dict_to_ui (data ):
1289+ def motion_camera_dict_to_ui (data ): # noqa: C901
12911290
12921291 ui = {
12931292 # device
@@ -1699,15 +1698,15 @@ def motion_camera_dict_to_ui(data):
16991698 elif ' webhook ' in e :
17001699 e = shlex .split (e )
17011700
1702- if len (e ) < 3 :
1701+ if len (e ) < 7 :
17031702 continue
17041703
17051704 ui ['web_hook_notifications_enabled' ] = True
17061705 ui ['web_hook_notifications_http_method' ] = e [- 2 ]
17071706 ui ['web_hook_notifications_url' ] = e [- 1 ]
17081707
17091708 # support pre-v0.43.0 configs
1710- if len (e ) < 5 :
1709+ if len (e ) < 9 :
17111710 continue
17121711
17131712 ui ['web_hook_notifications_accept' ] = e [- 3 ]
@@ -1733,15 +1732,15 @@ def motion_camera_dict_to_ui(data):
17331732 if ' webhook ' in e :
17341733 e = shlex .split (e )
17351734
1736- if len (e ) < 3 :
1735+ if len (e ) < 7 :
17371736 continue
17381737
17391738 ui ['web_hook_end_notifications_enabled' ] = True
17401739 ui ['web_hook_end_notifications_http_method' ] = e [- 2 ]
17411740 ui ['web_hook_end_notifications_url' ] = e [- 1 ]
17421741
17431742 # support pre-v0.43.0 configs
1744- if len (e ) < 5 :
1743+ if len (e ) < 9 :
17451744 continue
17461745
17471746 ui ['web_hook_end_notifications_accept' ] = e [- 3 ]
0 commit comments