-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaquatemp.py
77 lines (62 loc) · 3.87 KB
/
aquatemp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import requests
import json
import hashlib
import logging
import time
class aquatempConnect():
_cloudURL = "https://cloud.linked-go.com:449/crmservice/api" #requires TLSv1.1
_token = ""
_tokenTimestamp = 0
_header = {"Content-Type": "application/json", "charset":"utf-8"}
def __init__(self, username, password):
self._username = username
self._password = str(hashlib.md5(password.encode()).hexdigest())
self.checkToken() #Initial login
#setup devices
r = requests.post(self._cloudURL+"/app/device/deviceList", headers=self._header)
self.devices = r.json()["objectResult"]
def checkToken(self):
if self._token == "" or (time.time()-self._tokenTimestamp>3600): #assuming token validity for 1hour
#get a new token
print("Getting a new token")
payload = {"userName":self._username, "password":self._password, "type":"2"}
r = requests.post(self._cloudURL+"/app/user/login", headers=self._header, json=payload)
if r.json()["error_code"] != "0": raise Exception("Connection Error "+r.json()["error_msg"])
self._token = r.json()["objectResult"]["x-token"]
self._header["x-token"] = self._token
self._tokenTimestamp = time.time()
return(self._token)
def setPower(self, state, dev=0):
payload = {"param":[{"deviceCode": self.devices[dev]["device_code"], "protocolCode": "Power","value": str(state)}]}
r = requests.post(self._cloudURL+"/app/device/control", headers=self._header, json=payload)
if r.json()["error_code"] != "0": logging.debug(f"Set power not successful. Error message {r.json()['error_msg']}")
def setTemperature(self, temp, mode=None, dev=0):
# set temperature for the current mode if not specified. R01: cooling, R02: heating, R03: auto
if mode is None: mode = self.getStatus()["Mode"]
payload = {"param":[{"deviceCode": self.devices[dev]["device_code"], "protocolCode": "R0"+str(mode),"value": str(temp)}]}
r = requests.post(self._cloudURL+"/app/device/control", headers=self._header, json=payload)
if r.json()["error_code"] != "0": logging.debug(f"Set temperature not successful. Error message {r.json()['error_msg']}")
def setSilent(self, state="1", dev=0):
#set silent mode. Default is to set to silent
payload = {"param":[{"deviceCode": self.devices[dev]["device_code"], "protocolCode": "Manual-mute","value": str(state)}]}
r = requests.post(self._cloudURL+"/app/device/control", headers=self._header, json=payload)
if r.json()["error_code"] != "0": logging.debug(f"Set silent not successful. Error message {r.json()['error_msg']}")
def getStatus(self, dev=0):
codes = {
"T01":"Suction Temp",
"T02":"Inlet Water Temp",
"T03":"Outlet Water Temp",
"T04":"Coil 1 Temp",
"T05":"Ambient Temp",
"T07":"Compressor Current",
"T09":"Flow Rate Input"
}
payload = {"deviceCode": self.devices[dev]["device_code"], "protocalCodes":["Power","Mode","Manual-mute","T01","T02","2074","2075","2076","2077","H03","Set_Temp","R08","R09","R10","R11","R01","R02","R03","T03","1158","1159","F17","H02","T04","T05","T07","T14","T17"] }
r = requests.post(self._cloudURL+"/app/device/getDataByCode", headers=self._header, json=payload)
if r.json()["error_code"] == "0":
statusMap = {}
for d in r.json()["objectResult"]:
statusMap[d["code"]] = d["value"]
return statusMap
else:
logging.debug(f"Get status not successful. Error message {r.json()['error_msg']}")