homebridge-enphase-envoy 10.2.3 → 10.2.5-beta.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/index.js +1 -1
- package/package.json +1 -1
- package/src/energymeter.js +23 -42
- package/src/envoydata.js +12 -30
- package/src/envoydevice.js +24 -31
- package/src/functions.js +17 -0
- package/src/impulsegenerator.js +19 -30
package/index.js
CHANGED
|
@@ -98,7 +98,7 @@ class EnvoyPlatform {
|
|
|
98
98
|
const impulseGenerator = new ImpulseGenerator()
|
|
99
99
|
.on('start', async () => {
|
|
100
100
|
try {
|
|
101
|
-
const envoyDevice = new DeviceClass(api,
|
|
101
|
+
const envoyDevice = new DeviceClass(api, log, device, envoyIdFile, envoyTokenFile, prefDir, energyMeterHistoryFileName)
|
|
102
102
|
.on('devInfo', (info) => logLevel.devInfo && log.info(info))
|
|
103
103
|
.on('success', (msg) => logLevel.success && log.success(`Device: ${host} ${accessoryName}, ${msg}`))
|
|
104
104
|
.on('info', (msg) => logLevel.info && log.info(`Device: ${host} ${accessoryName}, ${msg}`))
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"private": false,
|
|
3
3
|
"displayName": "Enphase Envoy",
|
|
4
4
|
"name": "homebridge-enphase-envoy",
|
|
5
|
-
"version": "10.2.
|
|
5
|
+
"version": "10.2.5-beta.0",
|
|
6
6
|
"description": "Homebridge p7ugin for Photovoltaic Energy System manufactured by Enphase.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "grzegorz914",
|
package/src/energymeter.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { Agent } from 'https';
|
|
3
1
|
import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser';
|
|
4
2
|
import EventEmitter from 'events';
|
|
5
3
|
import EnvoyToken from './envoytoken.js';
|
|
@@ -10,7 +8,7 @@ import fakegato from 'fakegato-history';
|
|
|
10
8
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
11
9
|
|
|
12
10
|
class EnergyMeter extends EventEmitter {
|
|
13
|
-
constructor(api,
|
|
11
|
+
constructor(api, log, device, envoyIdFile, envoyTokenFile, prefDir, energyMeterHistoryFileName) {
|
|
14
12
|
super();
|
|
15
13
|
|
|
16
14
|
Accessory = api.platformAccessory;
|
|
@@ -21,16 +19,14 @@ class EnergyMeter extends EventEmitter {
|
|
|
21
19
|
|
|
22
20
|
//device configuration
|
|
23
21
|
this.log = log;
|
|
24
|
-
this.name =
|
|
25
|
-
this.host = host;
|
|
26
|
-
|
|
27
|
-
this.envoyFirmware7xxTokenGenerationMode = envoyFirmware7xxTokenGenerationMode;
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.envoyTokenInstaller = envoyTokenInstaller;
|
|
33
|
-
this.powerProductionSummary = device.powerProductionSummary || 1;
|
|
22
|
+
this.name = device.ame;
|
|
23
|
+
this.host = device.host;
|
|
24
|
+
|
|
25
|
+
this.envoyFirmware7xxTokenGenerationMode = device.envoyFirmware7xxTokenGenerationMode;
|
|
26
|
+
this.enlightenUser = device.enlightenUser;
|
|
27
|
+
this.enlightenPasswd = device.enlightenPasswd;
|
|
28
|
+
this.envoyToken = device.envoyToken;
|
|
29
|
+
this.envoyTokenInstaller = device.envoyTokenInstaller;
|
|
34
30
|
this.energyProductionLifetimeOffset = device.energyProductionLifetimeOffset || 0;
|
|
35
31
|
this.energyConsumptionTotalLifetimeOffset = device.energyConsumptionTotalLifetimeOffset || 0;
|
|
36
32
|
this.energyConsumptionNetLifetimeOffset = device.energyConsumptionNetLifetimeOffset || 0;
|
|
@@ -235,23 +231,6 @@ class EnergyMeter extends EventEmitter {
|
|
|
235
231
|
});
|
|
236
232
|
}
|
|
237
233
|
|
|
238
|
-
createAxiosInstance(authHeader = null, cookie = null) {
|
|
239
|
-
return axios.create({
|
|
240
|
-
baseURL: this.url,
|
|
241
|
-
headers: {
|
|
242
|
-
Accept: 'application/json',
|
|
243
|
-
...(authHeader ? { Authorization: authHeader } : {}),
|
|
244
|
-
...(cookie ? { Cookie: cookie } : {}),
|
|
245
|
-
},
|
|
246
|
-
withCredentials: true,
|
|
247
|
-
httpsAgent: new Agent({
|
|
248
|
-
keepAlive: true,
|
|
249
|
-
rejectUnauthorized: false
|
|
250
|
-
}),
|
|
251
|
-
timeout: 60000
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
234
|
handleError(error) {
|
|
256
235
|
const errorString = error.toString();
|
|
257
236
|
const tokenNotValid = errorString.includes('status code 401');
|
|
@@ -269,7 +248,8 @@ class EnergyMeter extends EventEmitter {
|
|
|
269
248
|
async startStopImpulseGenerator(state) {
|
|
270
249
|
try {
|
|
271
250
|
//start impulse generator
|
|
272
|
-
const
|
|
251
|
+
const timers = state ? this.timers : [];
|
|
252
|
+
await this.impulseGenerator.state(state, timers)
|
|
273
253
|
return true;
|
|
274
254
|
} catch (error) {
|
|
275
255
|
throw new Error(`Impulse generator start error: ${error}`);
|
|
@@ -504,7 +484,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
504
484
|
const jwt = this.feature.info.jwtToken;
|
|
505
485
|
|
|
506
486
|
// Create a token-authenticated Axios instance
|
|
507
|
-
const axiosInstance = this.createAxiosInstance(`Bearer ${jwt.token}`, null);
|
|
487
|
+
const axiosInstance = this.functions.createAxiosInstance(`Bearer ${jwt.token}`, null);
|
|
508
488
|
|
|
509
489
|
// Send validation request
|
|
510
490
|
const response = await axiosInstance.get(ApiUrls.CheckJwt);
|
|
@@ -525,7 +505,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
525
505
|
}
|
|
526
506
|
|
|
527
507
|
// Replace axios instance with cookie-authenticated one
|
|
528
|
-
this.axiosInstance = this.createAxiosInstance(null, cookie);
|
|
508
|
+
this.axiosInstance = this.functions.createAxiosInstance(null, cookie);
|
|
529
509
|
|
|
530
510
|
// Update internal state
|
|
531
511
|
this.feature.info.tokenValid = true;
|
|
@@ -552,8 +532,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
552
532
|
if (metersInstalled) {
|
|
553
533
|
const arr = [];
|
|
554
534
|
for (const meter of responseData) {
|
|
555
|
-
const
|
|
556
|
-
const key = MetersKeyMap[measurementType];
|
|
535
|
+
const key = MetersKeyMap[meter.measurementType];
|
|
557
536
|
if (!key) {
|
|
558
537
|
if (this.logDebug) this.emit('debug', `Unknown meter measurement type: ${meter.measurementType}`);
|
|
559
538
|
continue;
|
|
@@ -655,10 +634,9 @@ class EnergyMeter extends EventEmitter {
|
|
|
655
634
|
const metersReportsInstalled = Array.isArray(responseData) && responseData.length > 0;
|
|
656
635
|
if (metersReportsInstalled) {
|
|
657
636
|
for (const meter of responseData) {
|
|
658
|
-
const
|
|
659
|
-
const key = MetersKeyMap[measurementType];
|
|
637
|
+
const key = MetersKeyMap[meter.reportType];
|
|
660
638
|
if (!key) {
|
|
661
|
-
if (!this.logDebug) this.emit('debug', `Unknown meters reports type: ${
|
|
639
|
+
if (!this.logDebug) this.emit('debug', `Unknown meters reports type: ${meter.reportType}`);
|
|
662
640
|
continue;
|
|
663
641
|
}
|
|
664
642
|
|
|
@@ -999,6 +977,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
999
977
|
sourceEnergy = meterEnabled ? sourceEim : sourcePcu;
|
|
1000
978
|
power = this.functions.isValidValue(sourceMeter.power) ? sourceMeter.power : null;
|
|
1001
979
|
energyLifetime = this.functions.isValidValue(sourceMeter.energyLifetime) ? sourceMeter.energyLifetime / 1000 : null;
|
|
980
|
+
energyLifetimeWithOffset = this.functions.isValidValue(sourceMeter.energyLifetime) ? energyLifetime + this.energyProductionLifetimeOffset : null;
|
|
1002
981
|
break;
|
|
1003
982
|
}
|
|
1004
983
|
case 'consumptionNet': {
|
|
@@ -1006,6 +985,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
1006
985
|
sourceEnergy = this.pv.powerAndEnergy.consumptionNet;
|
|
1007
986
|
power = this.functions.isValidValue(sourceMeter.power) ? sourceMeter.power : null;
|
|
1008
987
|
energyLifetime = this.functions.isValidValue(sourceMeter.energyLifetime) ? sourceMeter.energyLifetime / 1000 : null;
|
|
988
|
+
energyLifetimeWithOffset = this.functions.isValidValue(sourceMeter.energyLifetime) ? energyLifetime + this.energyConsumptionNetLifetimeOffset : null;
|
|
1009
989
|
break;
|
|
1010
990
|
}
|
|
1011
991
|
case 'consumptionTotal': {
|
|
@@ -1013,6 +993,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
1013
993
|
sourceEnergy = this.pv.powerAndEnergy.consumptionTotal;
|
|
1014
994
|
power = this.functions.isValidValue(sourceMeter.power) ? sourceMeter.power : null;
|
|
1015
995
|
energyLifetime = this.functions.isValidValue(sourceMeter.energyLifetime) ? sourceMeter.energyLifetime / 1000 : null;
|
|
996
|
+
energyLifetimeWithOffset = this.functions.isValidValue(sourceMeter.energyLifetime) ? energyLifetime + this.energyConsumptionTotalLifetimeOffset : null;
|
|
1016
997
|
break;
|
|
1017
998
|
}
|
|
1018
999
|
}
|
|
@@ -1029,7 +1010,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
1029
1010
|
type,
|
|
1030
1011
|
measurementType,
|
|
1031
1012
|
power,
|
|
1032
|
-
|
|
1013
|
+
energyLifetimeWithOffset,
|
|
1033
1014
|
gridQualityState: meterEnabled,
|
|
1034
1015
|
};
|
|
1035
1016
|
|
|
@@ -1042,7 +1023,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
1042
1023
|
// Create characteristics energy meter
|
|
1043
1024
|
const characteristics = [
|
|
1044
1025
|
{ type: Characteristic.EvePower, value: obj.power },
|
|
1045
|
-
{ type: Characteristic.EveEnergyLifetime, value: obj.
|
|
1026
|
+
{ type: Characteristic.EveEnergyLifetime, value: obj.energyLifetimeWithOffset },
|
|
1046
1027
|
];
|
|
1047
1028
|
|
|
1048
1029
|
// Create characteristics energy meter
|
|
@@ -1137,7 +1118,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
1137
1118
|
// Create characteristics
|
|
1138
1119
|
const characteristics = [
|
|
1139
1120
|
{ type: Characteristic.EvePower, label: 'power', value: source.power, unit: 'W' },
|
|
1140
|
-
{ type: Characteristic.EveEnergyLifetime, label: 'energy lifetime', value: source.
|
|
1121
|
+
{ type: Characteristic.EveEnergyLifetime, label: 'energy lifetime', value: source.energyLifetimeWithOffset, unit: 'kWh' },
|
|
1141
1122
|
];
|
|
1142
1123
|
|
|
1143
1124
|
if (source.gridQualityState) {
|
|
@@ -1187,7 +1168,7 @@ class EnergyMeter extends EventEmitter {
|
|
|
1187
1168
|
|
|
1188
1169
|
try {
|
|
1189
1170
|
// Create axios instance
|
|
1190
|
-
this.axiosInstance = this.createAxiosInstance();
|
|
1171
|
+
this.axiosInstance = this.functions.createAxiosInstance();
|
|
1191
1172
|
|
|
1192
1173
|
// Get basic PV info
|
|
1193
1174
|
const getInfo = await this.getInfo();
|
package/src/envoydata.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { Agent } from 'https';
|
|
3
1
|
import { XMLParser, XMLBuilder, XMLValidator } from 'fast-xml-parser';
|
|
4
2
|
import EventEmitter from 'events';
|
|
5
3
|
import EnvoyToken from './envoytoken.js';
|
|
@@ -10,17 +8,17 @@ import Functions from './functions.js';
|
|
|
10
8
|
import { ApiUrls, PartNumbers, Authorization, ApiCodes, MetersKeyMap } from './constants.js';
|
|
11
9
|
|
|
12
10
|
class EnvoyData extends EventEmitter {
|
|
13
|
-
constructor(
|
|
11
|
+
constructor(device, envoyIdFile, envoyTokenFile) {
|
|
14
12
|
super();
|
|
15
13
|
|
|
16
14
|
//device configuration
|
|
17
15
|
this.host = host;
|
|
18
|
-
this.envoyFirmware7xxTokenGenerationMode = envoyFirmware7xxTokenGenerationMode;
|
|
19
|
-
this.envoyPasswd = envoyPasswd;
|
|
20
|
-
this.enlightenUser = enlightenUser;
|
|
21
|
-
this.enlightenPasswd = enlightenPasswd;
|
|
22
|
-
this.envoyToken = envoyToken;
|
|
23
|
-
this.envoyTokenInstaller = envoyTokenInstaller;
|
|
16
|
+
this.envoyFirmware7xxTokenGenerationMode = device.envoyFirmware7xxTokenGenerationMode;
|
|
17
|
+
this.envoyPasswd = device.envoyPasswd;
|
|
18
|
+
this.enlightenUser = device.enlightenUser;
|
|
19
|
+
this.enlightenPasswd = device.enlightenPasswd;
|
|
20
|
+
this.envoyToken = device.envoyToken;
|
|
21
|
+
this.envoyTokenInstaller = device.envoyTokenInstaller;
|
|
24
22
|
this.envoyIdFile = envoyIdFile;
|
|
25
23
|
this.envoyTokenFile = envoyTokenFile;
|
|
26
24
|
|
|
@@ -454,23 +452,6 @@ class EnvoyData extends EventEmitter {
|
|
|
454
452
|
});
|
|
455
453
|
}
|
|
456
454
|
|
|
457
|
-
createAxiosInstance(authHeader = null, cookie = null) {
|
|
458
|
-
return axios.create({
|
|
459
|
-
baseURL: this.url,
|
|
460
|
-
headers: {
|
|
461
|
-
Accept: 'application/json',
|
|
462
|
-
...(authHeader ? { Authorization: authHeader } : {}),
|
|
463
|
-
...(cookie ? { Cookie: cookie } : {}),
|
|
464
|
-
},
|
|
465
|
-
withCredentials: true,
|
|
466
|
-
httpsAgent: new Agent({
|
|
467
|
-
keepAlive: false,
|
|
468
|
-
rejectUnauthorized: false
|
|
469
|
-
}),
|
|
470
|
-
timeout: 60000
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
|
|
474
455
|
handleError(error) {
|
|
475
456
|
const errorString = error.toString();
|
|
476
457
|
const tokenNotValid = errorString.includes('status code 401');
|
|
@@ -488,7 +469,8 @@ class EnvoyData extends EventEmitter {
|
|
|
488
469
|
async startStopImpulseGenerator(state) {
|
|
489
470
|
try {
|
|
490
471
|
//start impulse generator
|
|
491
|
-
const
|
|
472
|
+
const timers = state ? this.timers : [];
|
|
473
|
+
await this.impulseGenerator.state(state, timers)
|
|
492
474
|
return true;
|
|
493
475
|
} catch (error) {
|
|
494
476
|
throw new Error(`Impulse generator start error: ${error}`);
|
|
@@ -731,7 +713,7 @@ class EnvoyData extends EventEmitter {
|
|
|
731
713
|
const jwt = this.feature.info.jwtToken;
|
|
732
714
|
|
|
733
715
|
// Create a token-authenticated Axios instance
|
|
734
|
-
const axiosInstance = this.createAxiosInstance(`Bearer ${jwt.token}`, null);
|
|
716
|
+
const axiosInstance = this.functions.createAxiosInstance(`Bearer ${jwt.token}`, null);
|
|
735
717
|
|
|
736
718
|
// Send validation request
|
|
737
719
|
const response = await axiosInstance.get(ApiUrls.CheckJwt);
|
|
@@ -752,7 +734,7 @@ class EnvoyData extends EventEmitter {
|
|
|
752
734
|
}
|
|
753
735
|
|
|
754
736
|
// Replace axios instance with cookie-authenticated one
|
|
755
|
-
this.axiosInstance = this.createAxiosInstance(null, cookie);
|
|
737
|
+
this.axiosInstance = this.functions.createAxiosInstance(null, cookie);
|
|
756
738
|
|
|
757
739
|
// Update internal state
|
|
758
740
|
this.feature.info.tokenValid = true;
|
|
@@ -2750,7 +2732,7 @@ class EnvoyData extends EventEmitter {
|
|
|
2750
2732
|
|
|
2751
2733
|
try {
|
|
2752
2734
|
// Create axios instance
|
|
2753
|
-
this.axiosInstance = this.createAxiosInstance();
|
|
2735
|
+
this.axiosInstance = this.functions.createAxiosInstance();
|
|
2754
2736
|
|
|
2755
2737
|
// Get basic PV info
|
|
2756
2738
|
const getInfo = await this.getInfo();
|
package/src/envoydevice.js
CHANGED
|
@@ -7,7 +7,7 @@ import { PartNumbers, ApiCodes, MetersKeyMap, DeviceTypeMap, LedStatus } from '.
|
|
|
7
7
|
let Accessory, Characteristic, Service, Categories, AccessoryUUID;
|
|
8
8
|
|
|
9
9
|
class EnvoyDevice extends EventEmitter {
|
|
10
|
-
constructor(api,
|
|
10
|
+
constructor(api, log, device, envoyIdFile, envoyTokenFile) {
|
|
11
11
|
super();
|
|
12
12
|
|
|
13
13
|
Accessory = api.platformAccessory;
|
|
@@ -18,16 +18,9 @@ class EnvoyDevice extends EventEmitter {
|
|
|
18
18
|
|
|
19
19
|
//device configuration
|
|
20
20
|
this.device = device;
|
|
21
|
-
this.name =
|
|
22
|
-
this.host = host;
|
|
23
|
-
this.displayType = displayType;
|
|
24
|
-
|
|
25
|
-
this.envoyFirmware7xxTokenGenerationMode = envoyFirmware7xxTokenGenerationMode;
|
|
26
|
-
this.envoyPasswd = envoyPasswd;
|
|
27
|
-
this.enlightenUser = enlightenUser;
|
|
28
|
-
this.enlightenPasswd = enlightenPasswd;
|
|
29
|
-
this.envoyToken = envoyToken;
|
|
30
|
-
this.envoyTokenInstaller = envoyTokenInstaller;
|
|
21
|
+
this.name = device.ame;
|
|
22
|
+
this.host = device.host;
|
|
23
|
+
this.displayType = device.displayType;
|
|
31
24
|
|
|
32
25
|
this.lockControl = device.lockControl || false;
|
|
33
26
|
this.lockControlPrefix = device.lockControlPrefix || false;
|
|
@@ -63,32 +56,32 @@ class EnvoyDevice extends EventEmitter {
|
|
|
63
56
|
this.acBatterieBackupLevelAccessory = device.acBatterieBackupLevelAccessory || {};
|
|
64
57
|
|
|
65
58
|
//enpower
|
|
66
|
-
this.enpowerDryContactsControl = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerDryContactsControl || false) : false;
|
|
67
|
-
this.enpowerDryContactsSensor = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerDryContactsSensor || false) : false;
|
|
68
|
-
this.enpowerGridStateControl = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerGridStateControl || {}) : {};
|
|
69
|
-
this.enpowerGridStateSensor = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerGridStateSensor || {}) : {};
|
|
70
|
-
this.enpowerGridModeSensors = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerGridModeSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
59
|
+
this.enpowerDryContactsControl = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerDryContactsControl || false) : false;
|
|
60
|
+
this.enpowerDryContactsSensor = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerDryContactsSensor || false) : false;
|
|
61
|
+
this.enpowerGridStateControl = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerGridStateControl || {}) : {};
|
|
62
|
+
this.enpowerGridStateSensor = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerGridStateSensor || {}) : {};
|
|
63
|
+
this.enpowerGridModeSensors = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enpowerGridModeSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
71
64
|
|
|
72
65
|
//encharge
|
|
73
66
|
this.enchargeName = device.enchargeName || 'Encharge';
|
|
74
|
-
this.enchargeBackupLevelSummaryAccessory = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeBackupLevelSummaryAccessory || {}) : {};
|
|
75
|
-
this.enchargeBackupLevelSummarySensors = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeBackupLevelSummarySensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
76
|
-
this.enchargeBackupLevelAccessory = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeBackupLevelAccessory || {}) : {};
|
|
77
|
-
this.enchargeStateSensor = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeStateSensor || {}) : {};
|
|
78
|
-
this.enchargeProfileControls = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeProfileControls || []).filter(control => (control.displayType ?? 0) > 0) : [];
|
|
79
|
-
this.enchargeProfileSensors = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeProfileSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
80
|
-
this.enchargeGridStateSensor = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeGridStateSensor || {}) : {};
|
|
81
|
-
this.enchargeGridModeSensors = envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeGridModeSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
67
|
+
this.enchargeBackupLevelSummaryAccessory = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeBackupLevelSummaryAccessory || {}) : {};
|
|
68
|
+
this.enchargeBackupLevelSummarySensors = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeBackupLevelSummarySensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
69
|
+
this.enchargeBackupLevelAccessory = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeBackupLevelAccessory || {}) : {};
|
|
70
|
+
this.enchargeStateSensor = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeStateSensor || {}) : {};
|
|
71
|
+
this.enchargeProfileControls = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeProfileControls || []).filter(control => (control.displayType ?? 0) > 0) : [];
|
|
72
|
+
this.enchargeProfileSensors = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeProfileSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
73
|
+
this.enchargeGridStateSensor = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeGridStateSensor || {}) : {};
|
|
74
|
+
this.enchargeGridModeSensors = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.enchargeGridModeSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
82
75
|
|
|
83
76
|
//solar
|
|
84
|
-
this.solarGridStateSensor = envoyFirmware7xxTokenGenerationMode > 0 ? (device.solarGridStateSensor || {}) : {};
|
|
85
|
-
this.solarGridModeSensors = envoyFirmware7xxTokenGenerationMode > 0 ? (device.solarGridModeSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
77
|
+
this.solarGridStateSensor = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.solarGridStateSensor || {}) : {};
|
|
78
|
+
this.solarGridModeSensors = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.solarGridModeSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
86
79
|
|
|
87
80
|
//generator
|
|
88
|
-
this.generatorStateControl = envoyFirmware7xxTokenGenerationMode > 0 ? (device.generatorStateControl || {}) : {};
|
|
89
|
-
this.generatorStateSensor = envoyFirmware7xxTokenGenerationMode > 0 ? (device.generatorStateSensor || {}) : {};
|
|
90
|
-
this.generatorModeContols = envoyFirmware7xxTokenGenerationMode > 0 ? (device.generatorModeControls || []).filter(control => (control.displayType ?? 0) > 0) : [];
|
|
91
|
-
this.generatorModeSensors = envoyFirmware7xxTokenGenerationMode > 0 ? (device.generatorModeSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
81
|
+
this.generatorStateControl = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.generatorStateControl || {}) : {};
|
|
82
|
+
this.generatorStateSensor = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.generatorStateSensor || {}) : {};
|
|
83
|
+
this.generatorModeContols = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.generatorModeControls || []).filter(control => (control.displayType ?? 0) > 0) : [];
|
|
84
|
+
this.generatorModeSensors = device.envoyFirmware7xxTokenGenerationMode > 0 ? (device.generatorModeSensors || []).filter(sensor => (sensor.displayType ?? 0) > 0) : [];
|
|
92
85
|
|
|
93
86
|
//data refresh
|
|
94
87
|
this.dataSamplingControl = device.dataRefreshControl || {};
|
|
@@ -2969,7 +2962,7 @@ class EnvoyDevice extends EventEmitter {
|
|
|
2969
2962
|
|
|
2970
2963
|
try {
|
|
2971
2964
|
// Envoy Data
|
|
2972
|
-
this.envoyData = new EnvoyData(this.
|
|
2965
|
+
this.envoyData = new EnvoyData(this.device, this.envoyIdFile, this.envoyTokenFile)
|
|
2973
2966
|
.on('deviceInfo', (feature, info, timeZone) => {
|
|
2974
2967
|
this.feature = Object.assign(this.feature, feature);
|
|
2975
2968
|
this.pv.info = info;
|
package/src/functions.js
CHANGED
|
@@ -112,5 +112,22 @@ class Functions {
|
|
|
112
112
|
return powerPeakStored;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
createAxiosInstance(authHeader = null, cookie = null) {
|
|
116
|
+
return axios.create({
|
|
117
|
+
baseURL: this.url,
|
|
118
|
+
headers: {
|
|
119
|
+
Accept: 'application/json',
|
|
120
|
+
...(authHeader ? { Authorization: authHeader } : {}),
|
|
121
|
+
...(cookie ? { Cookie: cookie } : {}),
|
|
122
|
+
},
|
|
123
|
+
withCredentials: true,
|
|
124
|
+
httpsAgent: new Agent({
|
|
125
|
+
keepAlive: false,
|
|
126
|
+
rejectUnauthorized: false
|
|
127
|
+
}),
|
|
128
|
+
timeout: 60000
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
115
132
|
}
|
|
116
133
|
export default Functions
|
package/src/impulsegenerator.js
CHANGED
|
@@ -7,48 +7,37 @@ class ImpulseGenerator extends EventEmitter {
|
|
|
7
7
|
this.timers = [];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
async
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
async state(state, timers = []) {
|
|
11
|
+
// Stop current timers before new start
|
|
12
|
+
if (this.timersState && state) {
|
|
13
|
+
await this.state(false);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (const timer of timers) {
|
|
19
|
-
this.emit(timer.name);
|
|
16
|
+
if (state) {
|
|
17
|
+
if (!Array.isArray(timers)) throw new Error('Timers must be an array');
|
|
20
18
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
}, timer.sampling);
|
|
19
|
+
for (const { name, sampling } of timers) {
|
|
20
|
+
if (!name || !sampling) continue;
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
}
|
|
22
|
+
this.emit(name);
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
async stop() {
|
|
33
|
-
if (!this.timersState) {
|
|
34
|
-
this.state(false);
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
24
|
+
const interval = setInterval(() => {
|
|
25
|
+
this.emit(name);
|
|
26
|
+
}, sampling);
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
this.timers.push(interval);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
this.timers.forEach(clearInterval);
|
|
32
|
+
this.timers = [];
|
|
40
33
|
}
|
|
41
34
|
|
|
42
|
-
this.timers = [];
|
|
43
|
-
this.state(false);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
state(state) {
|
|
48
35
|
this.timersState = state;
|
|
49
36
|
this.emit('state', state);
|
|
37
|
+
return true;
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
|
|
53
41
|
export default ImpulseGenerator;
|
|
54
42
|
|
|
43
|
+
|