forked from zonoskar/Goodwe2PVoutput
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goodweData.py
149 lines (118 loc) · 5.82 KB
/
goodweData.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import goodweSample
class goodweData :
#--------------------------------------------------------------------------
def __init__( self, urlData):
#Initialization of the goodweSample data object. All data members are set
#to default values.
self.m_sample = goodweSample.goodweSample()
# Parse and filter the urlData. This can throw an IOError or EOFError.
self.parse_data( urlData)
#--------------------------------------------------------------------------
def parse_data( self, response):
#Parses the URL data. This will select the correct table from the
#URL data and strip all units from the data strings ready to be
#converted to float or integers.
#
# Select from the HTTP data the table row with DG_Item
title = response[response.find('<title>')+7:response.find('</title>')]
table = response[response.find('var pw_info ='):response.find('var pw_id')]
inverter = table[table.find('inverter'):]
inverter = inverter[12:inverter.find('next_device')]
inverter = inverter.replace('"', '')
# Check against empty string. This could mean that the session has expired.
if not inverter:
raise EOFError("Inverter data empty, probably the session expired.")
values = inverter.split(',')
data = {}
# Convert the list into a dictionary for easy access.
for f in values:
k = f[:f.find(":")]
v = f[f.find(":")+1:]
data[k] = v
# Get the data from the dictionary
try:
self.m_sample.set_line( 1)
if data['status'] == "1":
self.m_sample.set_inverter_status( 'Normal')
else:
self.m_sample.set_inverter_status( 'Error')
self.m_sample.set_inverter_sn( data['sn'])
self.m_sample.set_description( "last refresh: " + data['last_refresh_time'])
self.m_sample.set_error( data['warning'])
self.m_sample.set_pgrid( self._convert_line_to_float( data['pac']))
self.m_sample.set_eday( self._convert_line_to_float( data['eDay']))
self.m_sample.set_etotal( self._convert_line_to_float( data['eTotal']))
self.m_sample.set_htotal( self._convert_line_to_float( data['hTotal']))
self.m_sample.set_temperature( self._convert_line_to_float(data['tempperature']))
self.m_sample.set_vpv( 0, self._convert_line_to_float(data['vpv1']))
self.m_sample.set_vpv( 1, self._convert_line_to_float(data['vpv2']))
self.m_sample.set_ipv( 0, self._convert_line_to_float(data['ipv1']))
self.m_sample.set_ipv( 1, self._convert_line_to_float(data['ipv2']))
self.m_sample.set_vac( 0, self._convert_line_to_float(data['vac1']))
self.m_sample.set_vac( 1, self._convert_line_to_float(data['vac2']))
self.m_sample.set_vac( 2, self._convert_line_to_float(data['vac3']))
self.m_sample.set_iac( 0, self._convert_line_to_float(data['iac1']))
self.m_sample.set_iac( 1, self._convert_line_to_float(data['iac2']))
self.m_sample.set_iac( 2, self._convert_line_to_float(data['iac3']))
self.m_sample.set_fac( 0, self._convert_line_to_float(data['fac1']))
self.m_sample.set_fac( 1, self._convert_line_to_float(data['fac2']))
self.m_sample.set_fac( 2, self._convert_line_to_float(data['fac3']))
self.m_sample.set_consume_day( 0.0)
self.m_sample.set_consume_total( 0.0)
# Calculate efficiency (PowerAC / powerDC)
try:
ppv = ((self.m_sample.get_vpv(0) * self.m_sample.get_ipv(0)) + (self.m_sample.get_vpv(1) * self.m_sample.get_ipv(1)))
if ppv > 0.0:
self.m_sample.set_efficiency( self.m_sample.get_pgrid() / ppv)
except Exception, arg:
print "Calculate Efficiency Error: " + str(arg)
self.m_sample.set_efficiency( 0.0)
except:
pass
except Exception, ex:
raise IOError("Data from Goodwe portal not correct: " + str(ex))
#--------------------------------------------------------------------------
def _convert_line_to_float( self, line):
retval = 0.0
try:
line=line.replace('A', '')
line=line.replace('V', '')
line=line.replace('K', '')
line=line.replace('W', '')
line=line.replace('h', '')
line=line.replace('k', '')
line=line.replace('H', '')
line=line.replace('z', '')
line=line.replace('%', '')
line=line.replace(' ', '')
retval = float(line)
except(ValueError):
retval = 0.0
return retval
return retval
#--------------------------------------------------------------------------
def to_csv_string( self):
#Creates a string representation of the class, separated by ','.
#
return str(self.m_sample.to_csv_string())
#--------------------------------------------------------------------------
def is_online( self):
#TRUE when the GoodWe inverter returns the correct status
#
return self.m_sample.is_online()
#--------------------------------------------------------------------------
def is_identical( self, sample):
#Compares select data members to determine if two instances of the
#goodweData class are identical
#
return self.m_sample.is_identical(sample.m_sample)
#--------------------------------------------------------------------------
def get_sample( self):
return self.m_sample
#--------------------------------------------------------------------------
def to_string( self):
return self.m_sample.to_string()
#--------------------------------------------------------------------------
def to_short_string( self):
return self.m_sample.to_short_string()
#---------------- End of file ------------------------------------------------