Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit c997057

Browse files
gjdvarska
authored andcommitted
corrected existing power consumption attributes and added additional power consumption values
1 parent a865d56 commit c997057

1 file changed

Lines changed: 72 additions & 11 deletions

File tree

daikinapi.py

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _get(self, path):
5151
response = requests.get("http://" + self._host + path, timeout=10)
5252
response.raise_for_status()
5353
logging.debug(response.text)
54-
if not len(response.text) > 0 or not response.text[0:4] == "ret=":
54+
if not len(response.text) > 0 or not response.text[0:4] == "ret=" or response.text[0:6] == "ret=NG":
5555
return None
5656
fields = {}
5757
for group in response.text.split(","):
@@ -88,21 +88,29 @@ def _get_notify(self):
8888
"""
8989
return self._get("/common/get_notify")
9090

91-
def _get_week(self):
91+
def _get_week(self, ex=False):
9292
"""
93-
Example:
93+
Example (ex=False):
9494
ret=OK,today_runtime=601,datas=0/0/0/0/0/0/1000
95+
(datas: values in Watts, last day last)
96+
Example (ex=True):
97+
ret=OK,s_dayw=2,week_heat=10/0/0/0/0/0/0/0/0/0/0/0/0/0,week_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0
98+
(week_*: values in 100Watts, last day first)
9599
:return: dict
96100
"""
97-
return self._get("/aircon/get_week_power")
101+
return self._get("/aircon/get_week_power" + ("_ex" if ex else ""))
98102

99-
def _get_year(self):
103+
def _get_year(self, ex=False):
100104
"""
101-
Example:
102-
ret=OK,previous_year=0/0/0/0/0/0/0/0/0/0/0/0,this_year=0/0/0/1
105+
Example (ex=False):
106+
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
107+
(*_year: values in 100Watts per month (jan-dec))
108+
Example (ex=True):
109+
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
110+
(*_year_*: values in 100Watts per month (jan-dec))
103111
:return: dict
104112
"""
105-
return self._get("/aircon/get_year_power")
113+
return self._get("/aircon/get_year_power" + ("_ex" if ex else ""))
106114

107115
def _get_target(self):
108116
"""
@@ -173,6 +181,14 @@ def _get_wifi(self):
173181
"""
174182
return self._get("/common/get_wifi_setting")
175183

184+
def _get_datetime(self):
185+
"""
186+
Example:
187+
ret=OK,sta=1,cur=2022/12/01 22:01:02,reg=eu,dst=1,zone=10
188+
:return:
189+
"""
190+
return self._get("/common/get_datetime")
191+
176192
def _do_reboot(self):
177193
return self._get("/common/reboot")
178194

@@ -252,6 +268,15 @@ def wifi_settings(self):
252268
wifi = self._get_wifi()
253269
return wifi['ssid'], wifi['key']
254270

271+
@property
272+
def datetime(self):
273+
"""
274+
datetime on the device
275+
:return: string of datetime on the device (yyyy/mm/dd HH:MM:SS), or None if not retrievable
276+
"""
277+
datetime = self._get_datetime()["cur"]
278+
return datetime if datetime != "-" else None
279+
255280
@power.setter
256281
def power(self, value):
257282
self._control_set("pow", value)
@@ -343,13 +368,48 @@ def today_runtime(self):
343368
"""
344369
return int(self._get_week()["today_runtime"])
345370

371+
def today_power_consumption_ex(self, ex=True, mode="heat"):
372+
"""
373+
unit power consumption today (in Watts)
374+
:param ex: boolean indicating whether to take form '_ex'
375+
:param mode: string from ("heat", "cool") describing mode of operation; ignored if ex==False
376+
:return: Watts of power consumption
377+
"""
378+
assert not ex or mode in ("heat", "cool"), 'mode should be from ("heat", "cool") if ex==True'
379+
res = self._get_week(ex=ex)
380+
if res is None:
381+
return None
382+
res = int(res["week_%s" % mode if ex else "datas"].split("/")[0 if ex else -1])
383+
return res * 100 if ex else res
384+
385+
@property
386+
def today_power_consumption(self, ex=False):
387+
"""
388+
unit power consumption today (in Watts)
389+
:return: Watts of power consumption
390+
"""
391+
return self.today_power_consumption_ex(ex=ex, mode=None)
392+
393+
def month_power_consumption(self, month=None):
394+
"""
395+
energy consumption
396+
:param month: optional argument to request a particular month-of-year (january=1); None defaults to current month
397+
:return: current-of-year energy consumption in kWh or None if not retrievable
398+
"""
399+
if month is None:
400+
dt = self.datetime
401+
if dt is None:
402+
return None
403+
month = int(dt.split("/")[1])
404+
return int(self._get_year()["this_year"].split("/")[month-1]) / 10.0
405+
346406
@property
347-
def current_month_power_consumption(self):
407+
def current_month_power_consumption(self, month=None):
348408
"""
349409
energy consumption
350-
:return: current month to date energy consumption in kWh
410+
:return: current month to date energy consumption in kWh or None if not retrievable
351411
"""
352-
return int(self._get_year()["this_year"].split("/")[-1])
412+
return self.month_power_consumption(month=month)
353413

354414
@property
355415
def price_int(self):
@@ -408,6 +468,7 @@ def _get_all(self):
408468
fields.update(self._get_model())
409469
fields.update(self._get_remote())
410470
fields.update(self._get_wifi())
471+
fields.update(self._get_datetime())
411472
return fields
412473

413474
def __str__(self):

0 commit comments

Comments
 (0)