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