@@ -55,7 +55,7 @@ def _get(self, path):
5555 fields = {}
5656 for group in response .text .split ("," ):
5757 element = group .split ("=" )
58- if element [0 ] == "name" :
58+ if element [0 ] in ( "name" , "key" ) :
5959 fields [element [0 ]] = urllib .parse .unquote (element [1 ])
6060 else :
6161 fields [element [0 ]] = element [1 ]
@@ -164,6 +164,32 @@ def _get_remote(self):
164164 """
165165 return self ._get ("/common/get_remote_method" )
166166
167+ def _get_wifi (self ):
168+ """
169+ Example:
170+ ret=OK,ssid=wireless_ssid,security=mixed,key=%77%69%66%69%6b%65%79,link=1
171+ :return: dict
172+ """
173+ return self ._get ("/common/get_wifi_setting" )
174+
175+ def _do_reboot (self ):
176+ return self ._get ("/common/reboot" )
177+
178+ def _set_wifi (self , ssid , key , do_reboot = True ):
179+ """
180+ Set the wifi settings
181+ :param ssid: ssid of the new network
182+ :param key: key of the new network
183+ :param do_reboot: boolean indicating whether to reboot, to activate the settings
184+ :return: None
185+ """
186+ key_encoded = "" .join ('%' + hex (ord (c ))[2 :].rjust (2 , '0' ) for c in key )
187+ data = {'ssid' : ssid , 'key' : key_encoded , 'security' : 'mixed' }
188+ self ._set ("/common/set_wifi_setting" , data )
189+ if do_reboot :
190+ res = self ._do_reboot ()
191+ logging .debug ("Reboot ordered to activate wifi changes: %s" % res )
192+
167193 @property
168194 def power (self ):
169195 """
@@ -216,6 +242,15 @@ def fan_direction(self):
216242 """
217243 return int (self ._get_control ()["f_dir" ])
218244
245+ @property
246+ def wifi_settings (self ):
247+ """
248+ wifi settings
249+ :return: tuple containing ssid and key of wifi network
250+ """
251+ wifi = self ._get_wifi ()
252+ return wifi ['ssid' ], wifi ['key' ]
253+
219254 @power .setter
220255 def power (self , value ):
221256 self ._control_set ("pow" , value )
@@ -240,6 +275,11 @@ def fan_rate(self, value):
240275 def fan_direction (self , value ):
241276 self ._control_set ("f_dir" , value )
242277
278+ @wifi_settings .setter
279+ def wifi_settings (self , value ):
280+ ssid , key = value
281+ self ._set_wifi (ssid , key )
282+
243283 def _control_set (self , key , value ):
244284 """
245285 set a get_control() item via one of the property.setters
0 commit comments