@@ -36,7 +36,7 @@ class Daikin:
3636 "inside_temperature" ,
3737 "outside_temperature" ,
3838 "wifi_settings" ,
39- "datetime"
39+ "datetime" ,
4040 ]
4141
4242 _host = None
@@ -49,11 +49,15 @@ def __init__(self, host):
4949 self ._host = host
5050
5151 def _get (self , path ):
52- """ Internal function to connect to and get any information"""
52+ """Internal function to connect to and get any information"""
5353 response = requests .get ("http://" + self ._host + path , timeout = 10 )
5454 response .raise_for_status ()
5555 logging .debug (response .text )
56- if not len (response .text ) > 0 or not response .text [0 :4 ] == "ret=" or response .text [0 :6 ] == "ret=NG" :
56+ if (
57+ not len (response .text ) > 0
58+ or not response .text [0 :4 ] == "ret="
59+ or response .text [0 :6 ] == "ret=NG"
60+ ):
5761 return None
5862 fields = {}
5963 for group in response .text .split ("," ):
@@ -65,7 +69,7 @@ def _get(self, path):
6569 return fields
6670
6771 def _set (self , path , data ):
68- """ Internal function to connect to and update information"""
72+ """Internal function to connect to and update information"""
6973 logging .debug (data )
7074 response = requests .get ("http://" + self ._host + path , data , timeout = 10 )
7175 response .raise_for_status ()
@@ -108,7 +112,10 @@ def _get_year(self, ex=False):
108112 ret=OK,previous_year=0/0/0/0/0/0/0/0/0/0/0/0,this_year=0/0/0/0/0/0/0/0/0/1
109113 (*_year: values in 100Watts per month (jan-dec))
110114 Example (ex=True):
111- ret=OK,curr_year_heat=0/0/0/0/0/0/0/0/0/0/0/1,prev_year_heat=0/0/0/0/0/0/0/0/0/0/0/0,curr_year_cool=0/0/0/0/0/0/0/0/0/0/0/0,prev_year_cool=0/0/0/0/0/0/0/0/0/0/0/0
115+ ret=OK,curr_year_heat=0/0/0/0/0/0/0/0/0/0/0/1,
116+ prev_year_heat=0/0/0/0/0/0/0/0/0/0/0/0,
117+ curr_year_cool=0/0/0/0/0/0/0/0/0/0/0/0,
118+ prev_year_cool=0/0/0/0/0/0/0/0/0/0/0/0
112119 (*_year_*: values in 100Watts per month (jan-dec))
113120 :return: dict
114121 """
@@ -202,12 +209,12 @@ def _set_wifi(self, ssid, key, do_reboot=True):
202209 :param do_reboot: boolean indicating whether to reboot, to activate the settings
203210 :return: None
204211 """
205- key_encoded = "" .join ('%' + hex (ord (c ))[2 :].rjust (2 , '0' ) for c in key )
206- data = {' ssid' : ssid , ' key' : key_encoded , ' security' : ' mixed' }
212+ key_encoded = "" .join ("%" + hex (ord (c ))[2 :].rjust (2 , "0" ) for c in key )
213+ data = {" ssid" : ssid , " key" : key_encoded , " security" : " mixed" }
207214 self ._set ("/common/set_wifi_setting" , data )
208215 if do_reboot :
209216 res = self ._do_reboot ()
210- logging .debug ("Reboot ordered to activate wifi changes: %s" % res )
217+ logging .debug ("Reboot ordered to activate wifi changes: %s" , res )
211218
212219 @property
213220 def power (self ):
@@ -268,13 +275,14 @@ def wifi_settings(self):
268275 :return: tuple containing ssid and key of wifi network
269276 """
270277 wifi = self ._get_wifi ()
271- return wifi [' ssid' ], wifi [' key' ]
278+ return wifi [" ssid" ], wifi [" key" ]
272279
273280 @property
274281 def datetime (self ):
275282 """
276283 datetime on the device
277- :return: string of datetime on the device (yyyy/mm/dd HH:MM:SS), or None if not retrievable
284+ :return: string of datetime on the device (yyyy/mm/dd HH:MM:SS),
285+ or None if not retrievable
278286 """
279287 datetime = self ._get_datetime ()["cur" ]
280288 return datetime if datetime != "-" else None
@@ -370,48 +378,52 @@ def today_runtime(self):
370378 """
371379 return int (self ._get_week ()["today_runtime" ])
372380
373- def today_power_consumption_ex (self , ex = True , mode = "heat" ):
381+ def _today_power_consumption_ex (self , ex = True , mode = "heat" ):
374382 """
375383 unit power consumption today (in Watts)
376384 :param ex: boolean indicating whether to take form '_ex'
377- :param mode: string from ("heat", "cool") describing mode of operation; ignored if ex==False
385+ :param mode: string from ("heat", "cool") describing mode of operation;
386+ ignored if ex==False
378387 :return: Watts of power consumption
379388 """
380- assert not ex or mode in ("heat" , "cool" ), 'mode should be from ("heat", "cool") if ex==True'
389+ assert not ex or mode in (
390+ "heat" ,
391+ "cool" ,
392+ ), 'mode should be from ("heat", "cool") if ex==True'
381393 res = self ._get_week (ex = ex )
382394 if res is None :
383395 return None
384- res = int (res ["week_%s" % mode if ex else "datas" ].split ("/" )[0 if ex else - 1 ])
396+ res = int (res [f "week_{ mode } " if ex else "datas" ].split ("/" )[0 if ex else - 1 ])
385397 return res * 100 if ex else res
386398
387399 @property
388- def today_power_consumption (self , ex = False ):
400+ def today_power_consumption (self ):
389401 """
390402 unit power consumption today (in Watts)
391403 :return: Watts of power consumption
392404 """
393- return self .today_power_consumption_ex (ex = ex , mode = None )
405+ return self ._today_power_consumption_ex (ex = False , mode = None )
394406
395- def month_power_consumption (self , month = None ):
407+ def _month_power_consumption (self , month = None ):
396408 """
397409 energy consumption
398- :param month: optional argument to request a particular month-of-year (january=1); None defaults to current month
410+ :param month: request a particular month-of-year (january=1);
411+ None defaults to current month
399412 :return: current-of-year energy consumption in kWh or None if not retrievable
400413 """
401414 if month is None :
402- dt = self .datetime
403- if dt is None :
415+ if self .datetime is None :
404416 return None
405- month = int (dt .split ("/" )[1 ])
406- return int (self ._get_year ()["this_year" ].split ("/" )[month - 1 ]) / 10.0
417+ month = int (self . datetime .split ("/" )[1 ])
418+ return int (self ._get_year ()["this_year" ].split ("/" )[month - 1 ]) / 10.0
407419
408420 @property
409- def current_month_power_consumption (self , month = None ):
421+ def current_month_power_consumption (self ):
410422 """
411423 energy consumption
412424 :return: current month to date energy consumption in kWh or None if not retrievable
413425 """
414- return self .month_power_consumption ( month = month )
426+ return self ._month_power_consumption ( )
415427
416428 @property
417429 def price_int (self ):
0 commit comments