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

Commit

Permalink
make pylint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
arska committed Feb 3, 2023
1 parent 64fd625 commit 14c56e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
60 changes: 36 additions & 24 deletions daikinapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Daikin:
"inside_temperature",
"outside_temperature",
"wifi_settings",
"datetime"
"datetime",
]

_host = None
Expand All @@ -49,11 +49,15 @@ def __init__(self, host):
self._host = host

def _get(self, path):
""" Internal function to connect to and get any information"""
"""Internal function to connect to and get any information"""
response = requests.get("http://" + self._host + path, timeout=10)
response.raise_for_status()
logging.debug(response.text)
if not len(response.text) > 0 or not response.text[0:4] == "ret=" or response.text[0:6] == "ret=NG":
if (
not len(response.text) > 0
or not response.text[0:4] == "ret="
or response.text[0:6] == "ret=NG"
):
return None
fields = {}
for group in response.text.split(","):
Expand All @@ -65,7 +69,7 @@ def _get(self, path):
return fields

def _set(self, path, data):
""" Internal function to connect to and update information"""
"""Internal function to connect to and update information"""
logging.debug(data)
response = requests.get("http://" + self._host + path, data, timeout=10)
response.raise_for_status()
Expand Down Expand Up @@ -108,7 +112,10 @@ def _get_year(self, ex=False):
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
(*_year: values in 100Watts per month (jan-dec))
Example (ex=True):
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
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
(*_year_*: values in 100Watts per month (jan-dec))
:return: dict
"""
Expand Down Expand Up @@ -202,12 +209,12 @@ def _set_wifi(self, ssid, key, do_reboot=True):
:param do_reboot: boolean indicating whether to reboot, to activate the settings
:return: None
"""
key_encoded = "".join('%' + hex(ord(c))[2:].rjust(2, '0') for c in key)
data = {'ssid': ssid, 'key': key_encoded, 'security': 'mixed'}
key_encoded = "".join("%" + hex(ord(c))[2:].rjust(2, "0") for c in key)
data = {"ssid": ssid, "key": key_encoded, "security": "mixed"}
self._set("/common/set_wifi_setting", data)
if do_reboot:
res = self._do_reboot()
logging.debug("Reboot ordered to activate wifi changes: %s" % res)
logging.debug("Reboot ordered to activate wifi changes: %s", res)

@property
def power(self):
Expand Down Expand Up @@ -268,13 +275,14 @@ def wifi_settings(self):
:return: tuple containing ssid and key of wifi network
"""
wifi = self._get_wifi()
return wifi['ssid'], wifi['key']
return wifi["ssid"], wifi["key"]

@property
def datetime(self):
"""
datetime on the device
:return: string of datetime on the device (yyyy/mm/dd HH:MM:SS), or None if not retrievable
:return: string of datetime on the device (yyyy/mm/dd HH:MM:SS),
or None if not retrievable
"""
datetime = self._get_datetime()["cur"]
return datetime if datetime != "-" else None
Expand Down Expand Up @@ -370,48 +378,52 @@ def today_runtime(self):
"""
return int(self._get_week()["today_runtime"])

def today_power_consumption_ex(self, ex=True, mode="heat"):
def _today_power_consumption_ex(self, ex=True, mode="heat"):
"""
unit power consumption today (in Watts)
:param ex: boolean indicating whether to take form '_ex'
:param mode: string from ("heat", "cool") describing mode of operation; ignored if ex==False
:param mode: string from ("heat", "cool") describing mode of operation;
ignored if ex==False
:return: Watts of power consumption
"""
assert not ex or mode in ("heat", "cool"), 'mode should be from ("heat", "cool") if ex==True'
assert not ex or mode in (
"heat",
"cool",
), 'mode should be from ("heat", "cool") if ex==True'
res = self._get_week(ex=ex)
if res is None:
return None
res = int(res["week_%s" % mode if ex else "datas"].split("/")[0 if ex else -1])
res = int(res[f"week_{mode}" if ex else "datas"].split("/")[0 if ex else -1])
return res * 100 if ex else res

@property
def today_power_consumption(self, ex=False):
def today_power_consumption(self):
"""
unit power consumption today (in Watts)
:return: Watts of power consumption
"""
return self.today_power_consumption_ex(ex=ex, mode=None)
return self._today_power_consumption_ex(ex=False, mode=None)

def month_power_consumption(self, month=None):
def _month_power_consumption(self, month=None):
"""
energy consumption
:param month: optional argument to request a particular month-of-year (january=1); None defaults to current month
:param month: request a particular month-of-year (january=1);
None defaults to current month
:return: current-of-year energy consumption in kWh or None if not retrievable
"""
if month is None:
dt = self.datetime
if dt is None:
if self.datetime is None:
return None
month = int(dt.split("/")[1])
return int(self._get_year()["this_year"].split("/")[month-1]) / 10.0
month = int(self.datetime.split("/")[1])
return int(self._get_year()["this_year"].split("/")[month - 1]) / 10.0

@property
def current_month_power_consumption(self, month=None):
def current_month_power_consumption(self):
"""
energy consumption
:return: current month to date energy consumption in kWh or None if not retrievable
"""
return self.month_power_consumption(month=month)
return self._month_power_consumption()

@property
def price_int(self):
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ basepython = python3.11
deps =
pylint
-rrequirements.txt
commands = pylint daikinapi
commands = pylint --disable=R0904 daikinapi
# ignore too many >20 public methods since they are all attributes

[flake8]
exclude = .tox,venv,*.egg*,.git,__pycache__,*.pyc*,build,dist
Expand Down

0 comments on commit 14c56e7

Please sign in to comment.