1414
1515import octoprint .plugin
1616from octoprint .server import admin_permission
17-
18-
19-
17+ from octoprint_netconnectd .analytics import Analytics
2018
2119class NetconnectdSettingsPlugin (octoprint .plugin .SettingsPlugin ,
2220 octoprint .plugin .TemplatePlugin ,
@@ -27,8 +25,10 @@ class NetconnectdSettingsPlugin(octoprint.plugin.SettingsPlugin,
2725
2826 def __init__ (self ):
2927 self .address = None
28+ self ._analytics = None
3029
3130 def initialize (self ):
31+ self ._analytics = Analytics (self )
3232 self .address = self ._settings .get (["socket" ])
3333 self .forwardUrl = self ._settings .get (["forwardUrl" ])
3434 self ._log_state_timed (self .LOG_STATE_DELAY )
@@ -100,32 +100,41 @@ def on_api_get(self, request):
100100 ))
101101
102102 def on_api_command (self , command , data , adminRequired = True ):
103- if command == "refresh_wifi" :
104- return jsonify (self ._get_wifi_list (force = True ))
105-
106- # any commands processed after this check require admin permissions
107- if adminRequired and not admin_permission .can ():
108- return make_response ("Insufficient rights" , 403 )
109-
110- if command == "configure_wifi" :
111- if data ["psk" ]:
112- self ._logger .info ("Configuring wifi {ssid} and psk..." .format (** data ))
113- else :
114- self ._logger .info ("Configuring wifi {ssid}..." .format (** data ))
103+ try :
104+ if command == "refresh_wifi" :
105+ self ._analytics .write_wifi_config_command (command , success = True )
106+ return jsonify (self ._get_wifi_list (force = True ))
107+
108+ # any commands processed after this check require admin permissions
109+ if adminRequired and not admin_permission .can ():
110+ self ._analytics .write_wifi_config_command (command , success = False , err = 'Insufficient rights' )
111+ return make_response ("Insufficient rights" , 403 )
112+
113+ if command == "configure_wifi" :
114+ if data ["psk" ]:
115+ self ._logger .info ("Configuring wifi {ssid} and psk..." .format (** data ))
116+ else :
117+ self ._logger .info ("Configuring wifi {ssid}..." .format (** data ))
118+
119+ self ._configure_and_select_wifi (data ["ssid" ], data ["psk" ], force = data ["force" ] if "force" in data else False )
120+
121+ elif command == "forget_wifi" :
122+ self ._forget_wifi ()
115123
116- self ._configure_and_select_wifi (data ["ssid" ], data ["psk" ], force = data ["force" ] if "force" in data else False )
124+ elif command == "reset" :
125+ self ._reset ()
117126
118- elif command == "forget_wifi " :
119- self ._forget_wifi ()
127+ elif command == "start_ap " :
128+ self ._start_ap ()
120129
121- elif command == "reset " :
122- self ._reset ()
130+ elif command == "stop_ap " :
131+ self ._stop_ap ()
123132
124- elif command == "start_ap" :
125- self ._start_ap ()
133+ self ._analytics .write_wifi_config_command (command , success = True )
126134
127- elif command == "stop_ap" :
128- self ._stop_ap ()
135+ except RuntimeError as e :
136+ self ._analytics .write_wifi_config_command (command , success = False , err = str (e ))
137+ raise RuntimeError
129138
130139 ##~~ AssetPlugin API
131140
0 commit comments