-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnovatek.py
78 lines (63 loc) · 2.4 KB
/
novatek.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
78
import requests
import hashlib
class NovatekElectro:
models = {
243 : "EM-125",
293 : "EM-126T",
255 : "EM-125S",
285 : "EM-126TS",
271 : "EM-129"
}
def __init__(self,ip,password):
self._url = 'http://'+ip
self._password = password
self.Connect()
def Connect(self):
r = requests.get(self._url+'/api/login?device_info').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
prefix = self.models.get(r["device_id"])
r = requests.get(self._url+'/api/login?salt').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
sha_1 = hashlib.sha1()
sha_1.update(str(prefix+self._password+r["SALT"]).encode('utf-8'))
r = requests.get(self._url+'/api/login?login='+sha_1.hexdigest()).json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
self._endpoint = self._url + '/' + r["SID"]
def Voltage(self):
r = requests.get(self._endpoint+'/api/all/get?volt_msr').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
return float(r["volt_msr"])/10
def Current(self):
r = requests.get(self._endpoint+'/api/all/get?cur_msr').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
return float(r["cur_msr"])/100
def Frequency(self):
r = requests.get(self._endpoint+'/api/all/get?freq_msr').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
return float(r["freq_msr"])/100
def ActivePower(self):
r = requests.get(self._endpoint+'/api/all/get?powa_msr').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
return float(r["powa_msr"])
def FullPower(self):
r = requests.get(self._endpoint+'/api/all/get?pows_msr').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
return float(r["pows_msr"])
def ActiveEnergy(self):
r = requests.get(self._endpoint+'/api/all/get?enrga_msr').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
return float(r["enrga_msr"])
def FullEnergy(self):
r = requests.get(self._endpoint+'/api/all/get?enrgs_msr').json()
if "OK" != r["STATUS"]:
raise ConnectionAbortedError
return float(r["enrgs_msr"])