homebridge-solaxcloud-api 2.3.2 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +140 -127
- package/LICENSE +175 -175
- package/config.sample +15 -15
- package/config.schema.json +105 -105
- package/dist/batteryAccessory.d.ts +70 -70
- package/dist/batteryAccessory.d.ts.map +1 -1
- package/dist/batteryAccessory.js +124 -123
- package/dist/batteryAccessory.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/lightSensorAccessory.d.ts +34 -34
- package/dist/lightSensorAccessory.js +58 -58
- package/dist/motionAccessory.d.ts +53 -53
- package/dist/motionAccessory.js +93 -93
- package/dist/outletAccessory.d.ts +100 -100
- package/dist/outletAccessory.js +187 -187
- package/dist/platform.d.ts +62 -56
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +294 -265
- package/dist/platform.js.map +1 -1
- package/dist/platformAccessory.d.ts +70 -70
- package/dist/platformAccessory.js +102 -102
- package/dist/platformInverter.d.ts +180 -176
- package/dist/platformInverter.d.ts.map +1 -1
- package/dist/platformInverter.js +348 -343
- package/dist/platformInverter.js.map +1 -1
- package/dist/platformMeters.d.ts +68 -68
- package/dist/platformMeters.js +2 -2
- package/dist/settings.d.ts +8 -8
- package/dist/settings.js +11 -11
- package/dist/solaxcloudfetch.d.ts +1 -1
- package/dist/solaxcloudfetch.js +21 -21
- package/dist/solaxcloudfetch.js.map +1 -1
- package/dist/statistics.d.ts +36 -36
- package/dist/statistics.js +88 -88
- package/dist/util.d.ts +23 -23
- package/dist/util.js +42 -42
- package/package.json +55 -54
- package/config.json +0 -16
- package/dist/solaxcloudapi.d.ts +0 -163
- package/dist/solaxcloudapi.d.ts.map +0 -1
- package/dist/solaxcloudapi.js +0 -226
- package/dist/solaxcloudapi.js.map +0 -1
- package/test/solaxcloudapi.test.ts +0 -164
package/dist/platformInverter.js
CHANGED
|
@@ -1,344 +1,349 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolaxCloudAPIPlatformInverter = exports.ACCESSORY_KEYS = exports.INVERTER_BRAND = void 0;
|
|
4
|
-
const
|
|
5
|
-
const outletAccessory_1 = require("./outletAccessory");
|
|
6
|
-
const lightSensorAccessory_1 = require("./lightSensorAccessory");
|
|
7
|
-
const motionAccessory_1 = require("./motionAccessory");
|
|
8
|
-
const batteryAccessory_1 = require("./batteryAccessory");
|
|
9
|
-
/**
|
|
10
|
-
* Inverter brand.
|
|
11
|
-
*/
|
|
12
|
-
exports.INVERTER_BRAND = {
|
|
13
|
-
SOLAX: 0,
|
|
14
|
-
QCELLS: 1,
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Standard names for accessories.
|
|
18
|
-
*/
|
|
19
|
-
exports.ACCESSORY_KEYS = {
|
|
20
|
-
pv: 'pv',
|
|
21
|
-
inverterToBattery: 'inverterToBattery',
|
|
22
|
-
inverterFromBattery: 'inverterFromBattery',
|
|
23
|
-
inverterAC: 'inverterAC',
|
|
24
|
-
inverterToGrid: 'inverterToGrid',
|
|
25
|
-
inverterToHouse: 'inverterToHouse',
|
|
26
|
-
gridToHouse: 'gridToHouse',
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Standard names for accessories.
|
|
30
|
-
*/
|
|
31
|
-
const ACCESSORY_NAMES = {
|
|
32
|
-
pv: 'PV',
|
|
33
|
-
inverterToBattery: 'To Battery',
|
|
34
|
-
inverterFromBattery: 'From Battery',
|
|
35
|
-
inverterAC: 'AC',
|
|
36
|
-
inverterToGrid: 'To Grid',
|
|
37
|
-
inverterToHouse: 'To House',
|
|
38
|
-
gridToHouse: 'From Grid',
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Standar prefixes for accessory serials.
|
|
42
|
-
*/
|
|
43
|
-
const ACCESSORY_SERIAL_PREFIXES = {
|
|
44
|
-
pv: 'pv',
|
|
45
|
-
inverterToBattery: 'inv-tobat',
|
|
46
|
-
inverterFromBattery: 'inv-frombat',
|
|
47
|
-
inverterAC: 'inv-ac',
|
|
48
|
-
inverterToGrid: 'inv-grid',
|
|
49
|
-
inverterToHouse: 'inv-house',
|
|
50
|
-
gridToHouse: 'grid-house',
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* SolaxCloudAPIPlatformInverter.
|
|
54
|
-
* This class is the main constructor for your inverter accessories
|
|
55
|
-
* to be used by Homebridge.
|
|
56
|
-
*/
|
|
57
|
-
class SolaxCloudAPIPlatformInverter {
|
|
58
|
-
/**
|
|
59
|
-
* Platform inverter constructor.
|
|
60
|
-
* @param log
|
|
61
|
-
* @param config
|
|
62
|
-
* @param api
|
|
63
|
-
* @param brand
|
|
64
|
-
* @param tokenId
|
|
65
|
-
* @param sn
|
|
66
|
-
* @param name
|
|
67
|
-
* @param hasBattery
|
|
68
|
-
* @param smoothingWindow
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
constructor(log, config, api, brand, tokenId, sn, name, hasBattery, smoothingWindow) {
|
|
72
|
-
/** Array with all accessories */
|
|
73
|
-
this.solaxAccessories = [];
|
|
74
|
-
// store values in properties
|
|
75
|
-
this.log = log;
|
|
76
|
-
this.config = config;
|
|
77
|
-
this.api = api;
|
|
78
|
-
// setup inverter data
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
*
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return '
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
this.setRawPower(exports.ACCESSORY_KEYS.
|
|
194
|
-
this.setRawPower(exports.ACCESSORY_KEYS.
|
|
195
|
-
this.
|
|
196
|
-
this.setRawPower(exports.ACCESSORY_KEYS.
|
|
197
|
-
this.
|
|
198
|
-
this.setRawPower(exports.ACCESSORY_KEYS.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
this.setSmoothPower(exports.ACCESSORY_KEYS.
|
|
204
|
-
this.setSmoothPower(exports.ACCESSORY_KEYS.
|
|
205
|
-
this.setSmoothPower(exports.ACCESSORY_KEYS.
|
|
206
|
-
this.setSmoothPower(exports.ACCESSORY_KEYS.
|
|
207
|
-
this.setSmoothPower(exports.ACCESSORY_KEYS.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
*
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
*
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
*
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
*
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolaxCloudAPIPlatformInverter = exports.ACCESSORY_KEYS = exports.INVERTER_BRAND = void 0;
|
|
4
|
+
const solax_cloud_api_1 = require("solax-cloud-api");
|
|
5
|
+
const outletAccessory_1 = require("./outletAccessory");
|
|
6
|
+
const lightSensorAccessory_1 = require("./lightSensorAccessory");
|
|
7
|
+
const motionAccessory_1 = require("./motionAccessory");
|
|
8
|
+
const batteryAccessory_1 = require("./batteryAccessory");
|
|
9
|
+
/**
|
|
10
|
+
* Inverter brand.
|
|
11
|
+
*/
|
|
12
|
+
exports.INVERTER_BRAND = {
|
|
13
|
+
SOLAX: 0,
|
|
14
|
+
QCELLS: 1,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Standard names for accessories.
|
|
18
|
+
*/
|
|
19
|
+
exports.ACCESSORY_KEYS = {
|
|
20
|
+
pv: 'pv',
|
|
21
|
+
inverterToBattery: 'inverterToBattery',
|
|
22
|
+
inverterFromBattery: 'inverterFromBattery',
|
|
23
|
+
inverterAC: 'inverterAC',
|
|
24
|
+
inverterToGrid: 'inverterToGrid',
|
|
25
|
+
inverterToHouse: 'inverterToHouse',
|
|
26
|
+
gridToHouse: 'gridToHouse',
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Standard names for accessories.
|
|
30
|
+
*/
|
|
31
|
+
const ACCESSORY_NAMES = {
|
|
32
|
+
pv: 'PV',
|
|
33
|
+
inverterToBattery: 'To Battery',
|
|
34
|
+
inverterFromBattery: 'From Battery',
|
|
35
|
+
inverterAC: 'AC',
|
|
36
|
+
inverterToGrid: 'To Grid',
|
|
37
|
+
inverterToHouse: 'To House',
|
|
38
|
+
gridToHouse: 'From Grid',
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Standar prefixes for accessory serials.
|
|
42
|
+
*/
|
|
43
|
+
const ACCESSORY_SERIAL_PREFIXES = {
|
|
44
|
+
pv: 'pv',
|
|
45
|
+
inverterToBattery: 'inv-tobat',
|
|
46
|
+
inverterFromBattery: 'inv-frombat',
|
|
47
|
+
inverterAC: 'inv-ac',
|
|
48
|
+
inverterToGrid: 'inv-grid',
|
|
49
|
+
inverterToHouse: 'inv-house',
|
|
50
|
+
gridToHouse: 'grid-house',
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* SolaxCloudAPIPlatformInverter.
|
|
54
|
+
* This class is the main constructor for your inverter accessories
|
|
55
|
+
* to be used by Homebridge.
|
|
56
|
+
*/
|
|
57
|
+
class SolaxCloudAPIPlatformInverter {
|
|
58
|
+
/**
|
|
59
|
+
* Platform inverter constructor.
|
|
60
|
+
* @param log
|
|
61
|
+
* @param config
|
|
62
|
+
* @param api
|
|
63
|
+
* @param brand
|
|
64
|
+
* @param tokenId
|
|
65
|
+
* @param sn
|
|
66
|
+
* @param name
|
|
67
|
+
* @param hasBattery
|
|
68
|
+
* @param smoothingWindow
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
constructor(log, config, api, brand, tokenId, sn, name, hasBattery, smoothingWindow, virtual = false, brandName = SolaxCloudAPIPlatformInverter.getInverterBrandName(brand)) {
|
|
72
|
+
/** Array with all accessories */
|
|
73
|
+
this.solaxAccessories = [];
|
|
74
|
+
// store values in properties
|
|
75
|
+
this.log = log;
|
|
76
|
+
this.config = config;
|
|
77
|
+
this.api = api;
|
|
78
|
+
// setup inverter data
|
|
79
|
+
this.sn = sn.toLowerCase();
|
|
80
|
+
this.name = name;
|
|
81
|
+
this.brandName = brandName;
|
|
82
|
+
this.virtual = virtual;
|
|
83
|
+
this.smoothingWindow = smoothingWindow;
|
|
84
|
+
this.batteryInstalled = hasBattery;
|
|
85
|
+
this.log.info(`Initialing acessories for inverter "${name}" (SN="${sn}") from ${this.brandName}...`);
|
|
86
|
+
let inverterModel = 'Unknown';
|
|
87
|
+
if (!this.virtual) {
|
|
88
|
+
// init new Solax Cloud API object with give tokenID and sn
|
|
89
|
+
this.solaxCloudAPI = new solax_cloud_api_1.SolaxCloudAPI(brand, tokenId, sn);
|
|
90
|
+
// initial data set
|
|
91
|
+
const apiData = this.solaxCloudAPI.getAPIData();
|
|
92
|
+
this.log.debug(`apiData = ${JSON.stringify(apiData)}`);
|
|
93
|
+
if (apiData.success) {
|
|
94
|
+
inverterModel = solax_cloud_api_1.SolaxCloudAPI.getInverterType(apiData.result.inverterType);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.log.info(`Could not retrieve initial values from ${this.brandName} ` +
|
|
98
|
+
'Cloud, accessory Serial Number and Model properties deferred...');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// setup raw outlet accessories
|
|
102
|
+
this.rawOutlets = {
|
|
103
|
+
pv: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.pv}`, `${ACCESSORY_SERIAL_PREFIXES.pv}-${this.sn}`, inverterModel),
|
|
104
|
+
inverterFromBattery: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterFromBattery}`, `${ACCESSORY_SERIAL_PREFIXES.inverterFromBattery}-${this.sn}`, inverterModel),
|
|
105
|
+
inverterToBattery: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToBattery}`, `${ACCESSORY_SERIAL_PREFIXES.inverterToBattery}-${this.sn}`, inverterModel),
|
|
106
|
+
inverterAC: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterAC}`, `${ACCESSORY_SERIAL_PREFIXES.inverterAC}-${this.sn}`, inverterModel),
|
|
107
|
+
inverterToGrid: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToGrid}`, `${ACCESSORY_SERIAL_PREFIXES.inverterToGrid}-${this.sn}`, inverterModel),
|
|
108
|
+
inverterToHouse: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToHouse}`, `${ACCESSORY_SERIAL_PREFIXES.inverterToHouse}-${this.sn}`, inverterModel),
|
|
109
|
+
gridToHouse: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.gridToHouse}`, `${ACCESSORY_SERIAL_PREFIXES.gridToHouse}-${this.sn}`, inverterModel),
|
|
110
|
+
};
|
|
111
|
+
// setup update motion sensor
|
|
112
|
+
this.motionUpdate =
|
|
113
|
+
new motionAccessory_1.SolaxMotionAccessory(this.log, this.api, `${this.name} Update`, `update-${this.sn}`, inverterModel);
|
|
114
|
+
// create array with all valid base accessories
|
|
115
|
+
this.solaxAccessories =
|
|
116
|
+
[this.rawOutlets.pv, this.rawOutlets.inverterAC, this.rawOutlets.inverterToGrid,
|
|
117
|
+
this.rawOutlets.inverterToHouse, this.rawOutlets.gridToHouse, this.motionUpdate];
|
|
118
|
+
if (this.hasBattery()) {
|
|
119
|
+
this.battery = new batteryAccessory_1.SolaxBatteryAccessory(this.log, this.api, `${this.name} Battery`, `bat-${this.sn}`, inverterModel);
|
|
120
|
+
this.solaxAccessories.push(this.battery, this.rawOutlets.inverterFromBattery, this.rawOutlets.inverterToBattery);
|
|
121
|
+
}
|
|
122
|
+
// check if "pure" Home App accessories are needed
|
|
123
|
+
if (this.config.pureHomeApp) {
|
|
124
|
+
// add raw light sensors
|
|
125
|
+
this.rawLightSensors = {
|
|
126
|
+
pv: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.pv} sensor`, `${ACCESSORY_SERIAL_PREFIXES.pv}-light-${this.sn}`, inverterModel),
|
|
127
|
+
inverterFromBattery: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterFromBattery} sensor`, `${ACCESSORY_SERIAL_PREFIXES.inverterFromBattery}-light-${this.sn}`, inverterModel),
|
|
128
|
+
inverterToBattery: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToBattery} sensor`, `${ACCESSORY_SERIAL_PREFIXES.inverterToBattery}-light-${this.sn}`, inverterModel),
|
|
129
|
+
inverterAC: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterAC} sensor`, `${ACCESSORY_SERIAL_PREFIXES.inverterAC}-light-${this.sn}`, inverterModel),
|
|
130
|
+
inverterToGrid: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToGrid} sensor`, `${ACCESSORY_SERIAL_PREFIXES.inverterToGrid}-light-${this.sn}`, inverterModel),
|
|
131
|
+
inverterToHouse: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToHouse} sensor`, `${ACCESSORY_SERIAL_PREFIXES.inverterToHouse}-light-${this.sn}`, inverterModel),
|
|
132
|
+
gridToHouse: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.gridToHouse} sensor`, `${ACCESSORY_SERIAL_PREFIXES.gridToHouse}-light-${this.sn}`, inverterModel),
|
|
133
|
+
};
|
|
134
|
+
this.solaxAccessories.push(this.rawLightSensors.pv, this.rawLightSensors.inverterAC, this.rawLightSensors.inverterToGrid, this.rawLightSensors.inverterToHouse, this.rawLightSensors.gridToHouse);
|
|
135
|
+
if (this.batteryInstalled) {
|
|
136
|
+
this.solaxAccessories.push(this.rawLightSensors.inverterFromBattery, this.rawLightSensors.inverterToBattery);
|
|
137
|
+
}
|
|
138
|
+
if (this.config.smoothMeters) {
|
|
139
|
+
// add smooth light sensors
|
|
140
|
+
this.smoothLightSensors = {
|
|
141
|
+
pv: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.pv} sensor (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.pv}-light-smooth-${this.sn}`, inverterModel),
|
|
142
|
+
inverterFromBattery: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterFromBattery} sensor (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterFromBattery}-light-smooth-${this.sn}`, inverterModel),
|
|
143
|
+
inverterToBattery: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToBattery} sensor (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterToBattery}-light-smooth-${this.sn}`, inverterModel),
|
|
144
|
+
inverterAC: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterAC} sensor (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterAC}-light-smooth-${this.sn}`, inverterModel),
|
|
145
|
+
inverterToGrid: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToGrid} sensor (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterToGrid}-light-smooth-${this.sn}`, inverterModel),
|
|
146
|
+
inverterToHouse: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToHouse} sensor (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterToHouse}-light-smooth-${this.sn}`, inverterModel),
|
|
147
|
+
gridToHouse: new lightSensorAccessory_1.SolaxLightSensorAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.gridToHouse} sensor (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.gridToHouse}-light-smooth-${this.sn}`, inverterModel),
|
|
148
|
+
};
|
|
149
|
+
this.solaxAccessories.push(this.smoothLightSensors.pv, this.smoothLightSensors.inverterAC, this.smoothLightSensors.inverterToGrid, this.smoothLightSensors.inverterToHouse, this.smoothLightSensors.gridToHouse);
|
|
150
|
+
if (this.batteryInstalled) {
|
|
151
|
+
this.solaxAccessories.push(this.smoothLightSensors.inverterFromBattery, this.smoothLightSensors.inverterToBattery);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
if (this.config.smoothMeters) {
|
|
157
|
+
// setup smooth outlet accessories
|
|
158
|
+
this.smoothOutlets = {
|
|
159
|
+
pv: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.pv} (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.pv}-smooth-${this.sn}`, inverterModel),
|
|
160
|
+
inverterFromBattery: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterFromBattery} (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterFromBattery}-smooth-${this.sn}`, inverterModel),
|
|
161
|
+
inverterToBattery: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToBattery} (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterToBattery}-smooth-${this.sn}`, inverterModel),
|
|
162
|
+
inverterAC: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterAC} (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterAC}-smooth-${this.sn}`, inverterModel),
|
|
163
|
+
inverterToGrid: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToGrid} (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterToGrid}-smooth-${this.sn}`, inverterModel),
|
|
164
|
+
inverterToHouse: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.inverterToHouse} (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.inverterToHouse}-smooth-${this.sn}`, inverterModel),
|
|
165
|
+
gridToHouse: new outletAccessory_1.SolaxOutletAccessory(this.log, this.api, `${this.name} ${ACCESSORY_NAMES.gridToHouse} (smooth)`, `${ACCESSORY_SERIAL_PREFIXES.gridToHouse}-smooth-${this.sn}`, inverterModel),
|
|
166
|
+
};
|
|
167
|
+
this.solaxAccessories.push(this.smoothOutlets.pv, this.smoothOutlets.inverterAC, this.smoothOutlets.inverterToGrid, this.smoothOutlets.inverterToHouse, this.smoothOutlets.gridToHouse);
|
|
168
|
+
if (this.batteryInstalled) {
|
|
169
|
+
this.solaxAccessories.push(this.smoothOutlets.inverterFromBattery, this.smoothOutlets.inverterToBattery);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Gets the inverter brand name.
|
|
176
|
+
* @param {number} brand Inverter brand type.
|
|
177
|
+
* @returns Inverter brand name.
|
|
178
|
+
*/
|
|
179
|
+
static getInverterBrandName(brand) {
|
|
180
|
+
switch (brand) {
|
|
181
|
+
case exports.INVERTER_BRAND.QCELLS:
|
|
182
|
+
return 'QCells';
|
|
183
|
+
default:
|
|
184
|
+
return 'Solax';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Update all platform accessory status based on the values read from the API.
|
|
189
|
+
* @param {SolaxCloudAPIResponse} apiData API data from Solax Cloud.
|
|
190
|
+
*/
|
|
191
|
+
updateAccessories(apiData) {
|
|
192
|
+
// update raw sensors
|
|
193
|
+
this.setRawPower(exports.ACCESSORY_KEYS.pv, solax_cloud_api_1.SolaxCloudAPI.getPVPower(apiData.result));
|
|
194
|
+
this.setRawPower(exports.ACCESSORY_KEYS.inverterFromBattery, solax_cloud_api_1.SolaxCloudAPI.getInverterPowerFromBattery(apiData.result));
|
|
195
|
+
this.setRawPower(exports.ACCESSORY_KEYS.inverterToBattery, solax_cloud_api_1.SolaxCloudAPI.getInverterPowerToBattery(apiData.result));
|
|
196
|
+
this.setRawPower(exports.ACCESSORY_KEYS.inverterAC, solax_cloud_api_1.SolaxCloudAPI.getInverterACPower(apiData.result));
|
|
197
|
+
this.setRawEnergy(exports.ACCESSORY_KEYS.inverterAC, solax_cloud_api_1.SolaxCloudAPI.getYieldTotal(apiData.result));
|
|
198
|
+
this.setRawPower(exports.ACCESSORY_KEYS.inverterToGrid, solax_cloud_api_1.SolaxCloudAPI.getInverterPowerToGrid(apiData.result));
|
|
199
|
+
this.setRawPower(exports.ACCESSORY_KEYS.inverterToHouse, solax_cloud_api_1.SolaxCloudAPI.getInverterPowerToHouse(apiData.result));
|
|
200
|
+
this.setRawPower(exports.ACCESSORY_KEYS.gridToHouse, solax_cloud_api_1.SolaxCloudAPI.getGridPowerToHouse(apiData.result));
|
|
201
|
+
if (this.config.smoothMeters) {
|
|
202
|
+
// update smooth light sensors from raw outlets by applying smoothing function to power consumption
|
|
203
|
+
this.setSmoothPower(exports.ACCESSORY_KEYS.pv);
|
|
204
|
+
this.setSmoothPower(exports.ACCESSORY_KEYS.inverterFromBattery);
|
|
205
|
+
this.setSmoothPower(exports.ACCESSORY_KEYS.inverterToBattery);
|
|
206
|
+
this.setSmoothPower(exports.ACCESSORY_KEYS.inverterAC);
|
|
207
|
+
this.setSmoothPower(exports.ACCESSORY_KEYS.inverterToGrid);
|
|
208
|
+
this.setSmoothPower(exports.ACCESSORY_KEYS.inverterToHouse);
|
|
209
|
+
this.setSmoothPower(exports.ACCESSORY_KEYS.gridToHouse);
|
|
210
|
+
}
|
|
211
|
+
// check for battery
|
|
212
|
+
if (this.hasBattery()) {
|
|
213
|
+
this.setBatteryLevel(solax_cloud_api_1.SolaxCloudAPI.getBatterySoC(apiData.result));
|
|
214
|
+
if (this.getRawPower(exports.ACCESSORY_KEYS.inverterToBattery) > 0) {
|
|
215
|
+
this.setBatteryChargeState(batteryAccessory_1.BATTERY_CHARGING_STATE.CHARGING);
|
|
216
|
+
}
|
|
217
|
+
else if (this.getRawPower(exports.ACCESSORY_KEYS.inverterFromBattery) > 0) {
|
|
218
|
+
this.setBatteryChargeState(batteryAccessory_1.BATTERY_CHARGING_STATE.NOT_CHARGING);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
this.setBatteryChargeState(batteryAccessory_1.BATTERY_CHARGING_STATE.NOT_CHARGEABLE);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// notify update with motion sensor
|
|
225
|
+
this.setMotionUpdate();
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Sets the battery charge state for this inverter.
|
|
229
|
+
* @param {number} state The desired battery charge state.
|
|
230
|
+
*/
|
|
231
|
+
setBatteryChargeState(state) {
|
|
232
|
+
this.battery.setChargeState(state);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Gets the battery charge state for this inverter.
|
|
236
|
+
* @returns {number} Battery charge state.
|
|
237
|
+
*/
|
|
238
|
+
getBatteryChargeState() {
|
|
239
|
+
return this.battery.getChargeStateValue();
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Sets the current battery level for this inverter.
|
|
243
|
+
* @param {number} percentage Battery level to set (percentage).
|
|
244
|
+
*/
|
|
245
|
+
setBatteryLevel(percentage) {
|
|
246
|
+
this.battery.setLevel(percentage);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Gets the current battery level for this inverter.
|
|
250
|
+
* @returns {number} The current battery level (percentage).
|
|
251
|
+
*/
|
|
252
|
+
getBatteryLevel() {
|
|
253
|
+
return this.battery.getLevelValue();
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Sets virtual update motion detector to true to notify of new data update.
|
|
257
|
+
*/
|
|
258
|
+
setMotionUpdate() {
|
|
259
|
+
this.motionUpdate.setState(true);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Gets raw accessory power for this inverter.
|
|
263
|
+
* @param {string} key Accessory key.
|
|
264
|
+
* @returns {number} Power consumptions for this accessory.
|
|
265
|
+
*/
|
|
266
|
+
getRawPower(key) {
|
|
267
|
+
return this.rawOutlets[key].getPowerConsumptionValue();
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Sets raw accessory power for this inverter.
|
|
271
|
+
* @param {string} key Accessory key.
|
|
272
|
+
* @param {number} power Power to set (in Watt).
|
|
273
|
+
*/
|
|
274
|
+
setRawPower(key, power) {
|
|
275
|
+
this.rawOutlets[key].setPowerConsumption(power);
|
|
276
|
+
if (this.config.pureHomeApp) {
|
|
277
|
+
this.rawLightSensors[key].setAmbientLightLevel(power);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Gets raw accessory energy for this inverter.
|
|
282
|
+
* @param {string} key Accessory key.
|
|
283
|
+
* @returns {number} The energy consumption for the desired acessory (in Wh).
|
|
284
|
+
*/
|
|
285
|
+
getRawEnergy(key) {
|
|
286
|
+
return this.rawOutlets[key].getTotalEnergyConsumptionValue();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Sets raw accessory energy for this inverter.
|
|
290
|
+
* @param {string} key Accessory key.
|
|
291
|
+
* @param {number} energy Energy consumption to set (in Wh).
|
|
292
|
+
*/
|
|
293
|
+
setRawEnergy(key, energy) {
|
|
294
|
+
this.rawOutlets[key].setTotalEnergyConsumption(energy);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Sets smooth accessory power from raw accessory power for this inverter.
|
|
298
|
+
* @param {string} key Accessory key.
|
|
299
|
+
*/
|
|
300
|
+
setSmoothPower(key) {
|
|
301
|
+
const smoothPower = this.rawOutlets[key].getSmoothPowerConsumption(this.config.smoothingMethod, this.smoothingWindow);
|
|
302
|
+
if (this.config.pureHomeApp) {
|
|
303
|
+
this.smoothLightSensors[key].setAmbientLightLevel(smoothPower);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
this.smoothOutlets[key].setPowerConsumption(smoothPower);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Update data from this inverter by using the Solax Cloud API
|
|
311
|
+
*/
|
|
312
|
+
updateInverterDataFromCloud() {
|
|
313
|
+
try {
|
|
314
|
+
if (this.virtual || !this.solaxCloudAPI) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this.log.info(`Retrieving data from ${this.brandName} ` +
|
|
318
|
+
`Cloud API for inverter "${this.name}" (SN="${this.sn}")`);
|
|
319
|
+
const apiData = this.solaxCloudAPI.getAPIData();
|
|
320
|
+
if (apiData.success) {
|
|
321
|
+
this.log.debug(`Retrieved inverter status: ${JSON.stringify(apiData.result)}`);
|
|
322
|
+
this.updateAccessories(apiData);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
throw new Error(apiData.exception);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
this.log.error(`Failed to read from ${this.brandName} ` +
|
|
330
|
+
`Cloud API for inverter "${this.name}" (SN="${this.sn})". Error: ${error}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Returns whether this inverter has a battery installed.
|
|
335
|
+
* @returns {boolean} Whether this inverter battery has a battery installed.
|
|
336
|
+
*/
|
|
337
|
+
hasBattery() {
|
|
338
|
+
return this.batteryInstalled;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Get array with full list of accessories for this inverter.
|
|
342
|
+
* @returns {AccessoryPlugin[]} Array of accessories for this inverter.
|
|
343
|
+
*/
|
|
344
|
+
getAccessories() {
|
|
345
|
+
return this.solaxAccessories;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
exports.SolaxCloudAPIPlatformInverter = SolaxCloudAPIPlatformInverter;
|
|
344
349
|
//# sourceMappingURL=platformInverter.js.map
|