@@ -34,6 +34,7 @@ class Daikin:
3434 "compressor_frequency" ,
3535 "inside_temperature" ,
3636 "outside_temperature" ,
37+ "wifi_settings" ,
3738 ]
3839
3940 _host = None
@@ -55,7 +56,7 @@ def _get(self, path):
5556 fields = {}
5657 for group in response .text .split ("," ):
5758 element = group .split ("=" )
58- if element [0 ] == "name" :
59+ if element [0 ] in ( "name" , "key" ) :
5960 fields [element [0 ]] = urllib .parse .unquote (element [1 ])
6061 else :
6162 fields [element [0 ]] = element [1 ]
@@ -164,6 +165,32 @@ def _get_remote(self):
164165 """
165166 return self ._get ("/common/get_remote_method" )
166167
168+ def _get_wifi (self ):
169+ """
170+ Example:
171+ ret=OK,ssid=wireless_ssid,security=mixed,key=%77%69%66%69%6b%65%79,link=1
172+ :return: dict
173+ """
174+ return self ._get ("/common/get_wifi_setting" )
175+
176+ def _do_reboot (self ):
177+ return self ._get ("/common/reboot" )
178+
179+ def _set_wifi (self , ssid , key , do_reboot = True ):
180+ """
181+ Set the wifi settings
182+ :param ssid: ssid of the new network
183+ :param key: key of the new network
184+ :param do_reboot: boolean indicating whether to reboot, to activate the settings
185+ :return: None
186+ """
187+ key_encoded = "" .join ('%' + hex (ord (c ))[2 :].rjust (2 , '0' ) for c in key )
188+ data = {'ssid' : ssid , 'key' : key_encoded , 'security' : 'mixed' }
189+ self ._set ("/common/set_wifi_setting" , data )
190+ if do_reboot :
191+ res = self ._do_reboot ()
192+ logging .debug ("Reboot ordered to activate wifi changes: %s" % res )
193+
167194 @property
168195 def power (self ):
169196 """
@@ -216,6 +243,15 @@ def fan_direction(self):
216243 """
217244 return int (self ._get_control ()["f_dir" ])
218245
246+ @property
247+ def wifi_settings (self ):
248+ """
249+ wifi settings
250+ :return: tuple containing ssid and key of wifi network
251+ """
252+ wifi = self ._get_wifi ()
253+ return wifi ['ssid' ], wifi ['key' ]
254+
219255 @power .setter
220256 def power (self , value ):
221257 self ._control_set ("pow" , value )
@@ -240,6 +276,11 @@ def fan_rate(self, value):
240276 def fan_direction (self , value ):
241277 self ._control_set ("f_dir" , value )
242278
279+ @wifi_settings .setter
280+ def wifi_settings (self , value ):
281+ ssid , key = value
282+ self ._set_wifi (ssid , key )
283+
243284 def _control_set (self , key , value ):
244285 """
245286 set a get_control() item via one of the property.setters
@@ -358,6 +399,7 @@ def _get_all(self):
358399 fields .update (self ._get_control ())
359400 fields .update (self ._get_model ())
360401 fields .update (self ._get_remote ())
402+ fields .update (self ._get_wifi ())
361403 return fields
362404
363405 def __str__ (self ):
0 commit comments