homebridge-enphase-envoy 10.3.8 → 10.3.9-beta.1

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/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.3.8",
5
+ "version": "10.3.9-beta.1",
6
6
  "description": "Homebridge p7ugin for Photovoltaic Energy System manufactured by Enphase.",
7
7
  "license": "MIT",
8
8
  "author": "grzegorz914",
package/src/envoydata.js CHANGED
@@ -8,7 +8,7 @@ import Functions from './functions.js';
8
8
  import { ApiUrls, PartNumbers, Authorization, ApiCodes, MetersKeyMap } from './constants.js';
9
9
 
10
10
  class EnvoyData extends EventEmitter {
11
- constructor(url, device, envoyIdFile, envoyTokenFile) {
11
+ constructor(url, device, envoyIdFile, envoyTokenFile, restFulEnabled, mqttEnabled) {
12
12
  super();
13
13
 
14
14
  //device configuration
@@ -30,6 +30,10 @@ class EnvoyData extends EventEmitter {
30
30
  this.logError = device.log?.error || true;
31
31
  this.logDebug = device.log?.debug || false;
32
32
 
33
+ //external integrations
34
+ this.restFulEnabled = restFulEnabled;
35
+ this.mqttEnabled = mqttEnabled;
36
+
33
37
  //setup variables
34
38
  this.functions = new Functions();
35
39
  this.checkTokenRunning = false;
@@ -440,8 +444,8 @@ class EnvoyData extends EventEmitter {
440
444
  this.emit(state ? 'success' : 'warn', `Impulse generator ${state ? 'started' : 'stopped'}`);
441
445
 
442
446
  this.emit('updateDataSampling', state);
443
- this.emit('restFul', 'dataSampling', state);
444
- this.emit('mqtt', 'Data Sampling', state);
447
+ if (this.restFulEnabled) this.emit('restFul', 'dataSampling', state);
448
+ if (this.mqttEnabled) this.emit('mqtt', 'Data Sampling', state);
445
449
  });
446
450
  }
447
451
 
@@ -559,8 +563,8 @@ class EnvoyData extends EventEmitter {
559
563
  this.feature.info.tokenRequired = obj.webTokens;
560
564
 
561
565
  // RESTFul + MQTT update
562
- this.emit('restFul', 'info', parsed);
563
- this.emit('mqtt', 'Info', parsed);
566
+ if (this.restFulEnabled) this.emit('restFul', 'info', parsed);
567
+ if (this.mqttEnabled) this.emit('mqtt', 'Info', parsed);
564
568
 
565
569
  return true;
566
570
  } catch (error) {
@@ -615,8 +619,8 @@ class EnvoyData extends EventEmitter {
615
619
  if (this.logDebug) this.emit('debug', `Token: ${tokenValid ? 'Valid' : 'Not valid'}`);
616
620
 
617
621
  // RESTFul and MQTT sync
618
- this.emit('restFul', 'token', jwt);
619
- this.emit('mqtt', 'Token', jwt);
622
+ if (this.restFulEnabled) this.emit('restFul', 'token', jwt);
623
+ if (this.mqttEnabled) this.emit('mqtt', 'Token', jwt);
620
624
 
621
625
  if (tokenExist && tokenValid) {
622
626
  if (this.logDebug) this.emit('debug', 'Token check complete, state: Valid');
@@ -885,8 +889,8 @@ class EnvoyData extends EventEmitter {
885
889
  }
886
890
 
887
891
  // RESTFul and MQTT update
888
- this.emit('restFul', 'productionstate', productionState);
889
- this.emit('mqtt', 'Production State', productionState);
892
+ if (this.restFulEnabled) this.emit('restFul', 'productionstate', productionState);
893
+ if (this.mqttEnabled) this.emit('mqtt', 'Production State', productionState);
890
894
 
891
895
  return true;
892
896
  } catch (error) {
@@ -936,8 +940,8 @@ class EnvoyData extends EventEmitter {
936
940
  this.feature.home.supported = true;
937
941
 
938
942
  // RESTful + MQTT
939
- this.emit('restFul', 'home', home);
940
- this.emit('mqtt', 'Home', home);
943
+ if (this.restFulEnabled) this.emit('restFul', 'home', home);
944
+ if (this.mqttEnabled) this.emit('mqtt', 'Home', home);
941
945
 
942
946
  return true;
943
947
  } catch (error) {
@@ -1050,8 +1054,8 @@ class EnvoyData extends EventEmitter {
1050
1054
  this.feature.inventory.supported = true;
1051
1055
 
1052
1056
  // RESTful & MQTT publishing
1053
- this.emit('restFul', 'inventory', inventory);
1054
- this.emit('mqtt', 'Inventory', inventory);
1057
+ if (this.restFulEnabled) this.emit('restFul', 'inventory', inventory);
1058
+ if (this.mqttEnabled) this.emit('mqtt', 'Inventory', inventory);
1055
1059
 
1056
1060
  return true;
1057
1061
  } catch (error) {
@@ -1095,8 +1099,8 @@ class EnvoyData extends EventEmitter {
1095
1099
  this.feature.inventory.pcus.status.supported = true;
1096
1100
 
1097
1101
  // RESTFul and MQTT update
1098
- this.emit('restFul', 'microinvertersstatus', pcus)
1099
- this.emit('mqtt', 'Microinverters Status', pcus);
1102
+ if (this.restFulEnabled) this.emit('restFul', 'microinvertersstatus', pcus)
1103
+ if (this.mqttEnabled) this.emit('mqtt', 'Microinverters Status', pcus);
1100
1104
 
1101
1105
  return true;
1102
1106
  } catch (error) {
@@ -1155,8 +1159,8 @@ class EnvoyData extends EventEmitter {
1155
1159
  this.feature.meters.supported = true;
1156
1160
 
1157
1161
  // RESTFul and MQTT update
1158
- this.emit('restFul', 'meters', responseData);
1159
- this.emit('mqtt', 'Meters', responseData);
1162
+ if (this.restFulEnabled) this.emit('restFul', 'meters', responseData);
1163
+ if (this.mqttEnabled) this.emit('mqtt', 'Meters', responseData);
1160
1164
 
1161
1165
  return true;
1162
1166
  } catch (error) {
@@ -1202,8 +1206,8 @@ class EnvoyData extends EventEmitter {
1202
1206
  this.feature.metersReading.supported = true;
1203
1207
 
1204
1208
  // RESTFul and MQTT update
1205
- this.emit('restFul', 'metersreading', responseData);
1206
- this.emit('mqtt', 'Meters Reading', responseData);
1209
+ if (this.restFulEnabled) this.emit('restFul', 'metersreading', responseData);
1210
+ if (this.mqttEnabled) this.emit('mqtt', 'Meters Reading', responseData);
1207
1211
 
1208
1212
  return true;
1209
1213
  } catch (error) {
@@ -1285,8 +1289,8 @@ class EnvoyData extends EventEmitter {
1285
1289
  this.feature.metersReports.supported = true;
1286
1290
 
1287
1291
  // RESTFul and MQTT update
1288
- this.emit('restFul', 'metersreports', responseData);
1289
- this.emit('mqtt', 'Meters Reports', responseData);
1292
+ if (this.restFulEnabled) this.emit('restFul', 'metersreports', responseData);
1293
+ if (this.mqttEnabled) this.emit('mqtt', 'Meters Reports', responseData);
1290
1294
 
1291
1295
  return true;
1292
1296
  } catch (error) {
@@ -1401,8 +1405,8 @@ class EnvoyData extends EventEmitter {
1401
1405
  this.feature.detailedDevicesData.supported = true;
1402
1406
 
1403
1407
  // RESTFul and MQTT update
1404
- this.emit('restFul', 'detaileddevicesdata', devicesData);
1405
- this.emit('mqtt', 'Detailed Devices Data', devicesData);
1408
+ if (this.restFulEnabled) this.emit('restFul', 'detaileddevicesdata', devicesData);
1409
+ if (this.mqttEnabled) this.emit('mqtt', 'Detailed Devices Data', devicesData);
1406
1410
 
1407
1411
  return true;
1408
1412
  } catch (error) {
@@ -1440,8 +1444,8 @@ class EnvoyData extends EventEmitter {
1440
1444
  this.feature.production.supported = true;
1441
1445
  }
1442
1446
 
1443
- this.emit('restFul', 'production', production);
1444
- this.emit('mqtt', 'Production', production);
1447
+ if (this.restFulEnabled) this.emit('restFul', 'production', production);
1448
+ if (this.mqttEnabled) this.emit('mqtt', 'Production', production);
1445
1449
 
1446
1450
  return true;
1447
1451
  } catch (error) {
@@ -1525,8 +1529,8 @@ class EnvoyData extends EventEmitter {
1525
1529
  this.feature.productionPdm.supported = true;
1526
1530
 
1527
1531
  // External integrations
1528
- this.emit('restFul', 'productionpdm', data);
1529
- this.emit('mqtt', 'Production Pdm', data);
1532
+ if (this.restFulEnabled) this.emit('restFul', 'productionpdm', data);
1533
+ if (this.mqttEnabled) this.emit('mqtt', 'Production Pdm', data);
1530
1534
 
1531
1535
  return true;
1532
1536
  } catch (error) {
@@ -1584,8 +1588,8 @@ class EnvoyData extends EventEmitter {
1584
1588
 
1585
1589
  this.feature.energyPdm.supported = true;
1586
1590
 
1587
- this.emit('restFul', 'energypdm', energyPdm);
1588
- this.emit('mqtt', 'Energy Pdm', energyPdm);
1591
+ if (this.restFulEnabled) this.emit('restFul', 'energypdm', energyPdm);
1592
+ if (this.mqttEnabled) this.emit('mqtt', 'Energy Pdm', energyPdm);
1589
1593
 
1590
1594
  return true;
1591
1595
  } catch (error) {
@@ -1686,8 +1690,8 @@ class EnvoyData extends EventEmitter {
1686
1690
  // --- Finalize ---
1687
1691
  this.feature.productionCt.supported = true;
1688
1692
 
1689
- this.emit('restFul', 'productionct', data);
1690
- this.emit('mqtt', 'Production CT', data);
1693
+ if (this.restFulEnabled) this.emit('restFul', 'productionct', data);
1694
+ if (this.mqttEnabled) this.emit('mqtt', 'Production CT', data);
1691
1695
 
1692
1696
  return true;
1693
1697
  } catch (error) {
@@ -1867,8 +1871,8 @@ class EnvoyData extends EventEmitter {
1867
1871
  this.feature.ensemble.inventory.supported = true;
1868
1872
 
1869
1873
  // RESTFul and MQTT update
1870
- this.emit('restFul', 'ensembleinventory', ensembleInventory);
1871
- this.emit('mqtt', 'Ensemble Inventory', ensembleInventory);
1874
+ if (this.restFulEnabled) this.emit('restFul', 'ensembleinventory', ensembleInventory);
1875
+ if (this.mqttEnabled) this.emit('mqtt', 'Ensemble Inventory', ensembleInventory);
1872
1876
 
1873
1877
  return true;
1874
1878
  } catch (error) {
@@ -2024,8 +2028,8 @@ class EnvoyData extends EventEmitter {
2024
2028
  this.feature.ensemble.status.supported = true;
2025
2029
 
2026
2030
  // RESTFul and MQTT update
2027
- this.emit('restFul', 'ensemblestatus', ensembleStatus);
2028
- this.emit('mqtt', 'Ensemble Status', ensembleStatus);
2031
+ if (this.restFulEnabled) this.emit('restFul', 'ensemblestatus', ensembleStatus);
2032
+ if (this.mqttEnabled) this.emit('mqtt', 'Ensemble Status', ensembleStatus);
2029
2033
 
2030
2034
  return true;
2031
2035
  } catch (error) {
@@ -2071,8 +2075,8 @@ class EnvoyData extends EventEmitter {
2071
2075
  this.feature.ensemble.power.supported = true;
2072
2076
 
2073
2077
  // RESTFul and MQTT update
2074
- this.emit('restFul', 'ensemblepower', devices);
2075
- this.emit('mqtt', 'Ensemble Power', devices);
2078
+ if (this.restFulEnabled) this.emit('restFul', 'ensemblepower', devices);
2079
+ if (this.mqttEnabled) this.emit('mqtt', 'Ensemble Power', devices);
2076
2080
 
2077
2081
  return true;
2078
2082
  } catch (error) {
@@ -2103,8 +2107,8 @@ class EnvoyData extends EventEmitter {
2103
2107
  this.feature.inventory.esubs.encharges.settings.supported = true;
2104
2108
 
2105
2109
  // RESTFul and MQTT update
2106
- this.emit('restFul', 'enchargesettings', enchargesSettings);
2107
- this.emit('mqtt', 'Encharge Settings', enchargesSettings);
2110
+ if (this.restFulEnabled) this.emit('restFul', 'enchargesettings', enchargesSettings);
2111
+ if (this.mqttEnabled) this.emit('mqtt', 'Encharge Settings', enchargesSettings);
2108
2112
 
2109
2113
  return true;
2110
2114
  } catch (error) {
@@ -2127,8 +2131,8 @@ class EnvoyData extends EventEmitter {
2127
2131
  this.pv.inventory.esubs.encharges.tariff = tariffSettings;
2128
2132
  this.feature.inventory.esubs.encharges.tariff.supported = true;
2129
2133
 
2130
- this.emit('restFul', 'tariff', tariffSettings);
2131
- this.emit('mqtt', 'Tariff', tariffSettings);
2134
+ if (this.restFulEnabled) this.emit('restFul', 'tariff', tariffSettings);
2135
+ if (this.mqttEnabled) this.emit('mqtt', 'Tariff', tariffSettings);
2132
2136
 
2133
2137
  return true;
2134
2138
  } catch (error) {
@@ -2165,8 +2169,8 @@ class EnvoyData extends EventEmitter {
2165
2169
 
2166
2170
 
2167
2171
  // RESTFul and MQTT update
2168
- this.emit('restFul', 'drycontacts', ensembleDryContacts);
2169
- this.emit('mqtt', 'Dry Contacts', ensembleDryContacts);
2172
+ if (this.restFulEnabled) this.emit('restFul', 'drycontacts', ensembleDryContacts);
2173
+ if (this.mqttEnabled) this.emit('mqtt', 'Dry Contacts', ensembleDryContacts);
2170
2174
 
2171
2175
  return true;
2172
2176
  } catch (error) {
@@ -2221,8 +2225,8 @@ class EnvoyData extends EventEmitter {
2221
2225
  });
2222
2226
 
2223
2227
  // RESTFul and MQTT update
2224
- this.emit('restFul', 'drycontactssettings', ensembleDryContactsSettings);
2225
- this.emit('mqtt', 'Dry Contacts Settings', ensembleDryContactsSettings);
2228
+ if (this.restFulEnabled) this.emit('restFul', 'drycontactssettings', ensembleDryContactsSettings);
2229
+ if (this.mqttEnabled) this.emit('mqtt', 'Dry Contacts Settings', ensembleDryContactsSettings);
2226
2230
 
2227
2231
  return true;
2228
2232
  } catch (error) {
@@ -2265,8 +2269,8 @@ class EnvoyData extends EventEmitter {
2265
2269
  }
2266
2270
 
2267
2271
  // RESTFul and MQTT update
2268
- this.emit('restFul', 'generator', generator);
2269
- this.emit('mqtt', 'Generator', generator);
2272
+ if (this.restFulEnabled) this.emit('restFul', 'generator', generator);
2273
+ if (this.mqttEnabled) this.emit('mqtt', 'Generator', generator);
2270
2274
 
2271
2275
  return true;
2272
2276
  } catch (error) {
@@ -2311,8 +2315,8 @@ class EnvoyData extends EventEmitter {
2311
2315
  }
2312
2316
 
2313
2317
  // RESTFul and MQTT update
2314
- this.emit('restFul', 'generatorsettings', generatorSettings);
2315
- this.emit('mqtt', 'Generator Settings', generatorSettings);
2318
+ if (this.restFulEnabled) this.emit('restFul', 'generatorsettings', generatorSettings);
2319
+ if (this.mqttEnabled) this.emit('mqtt', 'Generator Settings', generatorSettings);
2316
2320
 
2317
2321
  return true;
2318
2322
  } catch (error) {
@@ -2364,8 +2368,8 @@ class EnvoyData extends EventEmitter {
2364
2368
  this.feature.gridProfile.supported = true;
2365
2369
 
2366
2370
  // RESTFul and MQTT update
2367
- this.emit('restFul', 'gridprofile', profile);
2368
- this.emit('mqtt', 'Grid Profile', profile);
2371
+ if (this.restFulEnabled) this.emit('restFul', 'gridprofile', profile);
2372
+ if (this.mqttEnabled) this.emit('mqtt', 'Grid Profile', profile);
2369
2373
 
2370
2374
  return true;
2371
2375
  } catch (error) {
@@ -2423,8 +2427,8 @@ class EnvoyData extends EventEmitter {
2423
2427
  this.emit('updatePlcLevelCheck', false);
2424
2428
 
2425
2429
  // RESTFul and MQTT update
2426
- this.emit('restFul', 'plclevel', plcLevel);
2427
- this.emit('mqtt', 'PLC Level', plcLevel);
2430
+ if (this.restFulEnabled) this.emit('restFul', 'plclevel', plcLevel);
2431
+ if (this.mqttEnabled) this.emit('mqtt', 'PLC Level', plcLevel);
2428
2432
 
2429
2433
  return true;
2430
2434
  } catch (error) {
@@ -2507,8 +2511,8 @@ class EnvoyData extends EventEmitter {
2507
2511
  this.feature.liveData.supported = true;
2508
2512
 
2509
2513
  // RESTFul and MQTT update
2510
- this.emit('restFul', 'livedata', liveData);
2511
- this.emit('mqtt', 'Live Data', liveData);
2514
+ if (this.restFulEnabled) this.emit('restFul', 'livedata', liveData);
2515
+ if (this.mqttEnabled) this.emit('mqtt', 'Live Data', liveData);
2512
2516
 
2513
2517
  return true;
2514
2518
  } catch (error) {
@@ -3013,7 +3013,6 @@ class EnvoyDevice extends EventEmitter {
3013
3013
  const measurementType = source.measurementType;
3014
3014
  const envoySerialNumber = `${this.pv.info.serialNumber}${measurementType}`;
3015
3015
  const accessoryName = `${this.name} Energy Meter ${measurementType}`;
3016
- const power = source.power > 0 ? source.power : 0;
3017
3016
 
3018
3017
  //accessory
3019
3018
  if (this.logDebug) this.emit('debug', `Prepare ${accessoryName} accessory`);
@@ -3029,7 +3028,10 @@ class EnvoyDevice extends EventEmitter {
3029
3028
  .setCharacteristic(Characteristic.SerialNumber, envoySerialNumber ?? 'Serial Number')
3030
3029
  .setCharacteristic(Characteristic.FirmwareRevision, this.pv.info.software.replace(/[a-zA-Z]/g, '') ?? '0');
3031
3030
 
3031
+ // Energy Meter Fakegato
3032
3032
  if (this.logDebug) this.emit('debug', `Prepare Fakegato ${measurementType} Service`);
3033
+
3034
+ const power = source.power > 0 ? source.power : 0;
3033
3035
  const fakegatoHistoryService = new this.fakegatoHistory(`energy`, accessory, {
3034
3036
  storage: 'fs',
3035
3037
  disableRepeatLastData: true,
@@ -3039,7 +3041,7 @@ class EnvoyDevice extends EventEmitter {
3039
3041
  })
3040
3042
  fakegatoHistoryService.addEntry({
3041
3043
  time: Math.floor(Date.now() / 1000),
3042
- power: power ?? 0
3044
+ power: power
3043
3045
  });
3044
3046
 
3045
3047
  this.fakegatoHistoryServices.push(fakegatoHistoryService);
@@ -3051,7 +3053,7 @@ class EnvoyDevice extends EventEmitter {
3051
3053
 
3052
3054
  // Create characteristics
3053
3055
  const characteristics = [
3054
- { type: Characteristic.EvePower, label: 'power', value: power, unit: 'W' },
3056
+ { type: Characteristic.EvePower, label: 'power', value: source.power, unit: 'W' },
3055
3057
  { type: Characteristic.EveEnergyLifetime, label: 'energy lifetime', value: source.energyLifetimeWithOffset, unit: 'kWh' },
3056
3058
  ];
3057
3059
 
@@ -3105,8 +3107,12 @@ class EnvoyDevice extends EventEmitter {
3105
3107
  if (this.logDebug) this.emit('debug', `Start`);
3106
3108
 
3107
3109
  try {
3110
+
3111
+ // External integrations
3112
+ if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
3113
+
3108
3114
  // Envoy Data
3109
- this.envoyData = new EnvoyData(this.url, this.device, this.envoyIdFile, this.envoyTokenFile)
3115
+ this.envoyData = new EnvoyData(this.url, this.device, this.envoyIdFile, this.envoyTokenFile, this.restFul.enable, this.mqtt.enable)
3110
3116
  .on('deviceInfo', (feature, info, timeZone) => {
3111
3117
  this.feature = Object.assign(this.feature, feature);
3112
3118
  this.pv.info = info;
@@ -4138,7 +4144,7 @@ class EnvoyDevice extends EventEmitter {
4138
4144
  // Add to fakegato history
4139
4145
  this.fakegatoHistoryServices?.[index]?.addEntry({
4140
4146
  time: Math.floor(Date.now() / 1000),
4141
- power: power ?? 0
4147
+ power: power
4142
4148
  });
4143
4149
 
4144
4150
  // Create characteristics energy meter
@@ -5785,9 +5791,6 @@ class EnvoyDevice extends EventEmitter {
5785
5791
  const connect = await this.envoyData.connect();
5786
5792
  if (!connect) return null;
5787
5793
 
5788
- // External integrations
5789
- if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
5790
-
5791
5794
  // Prepare HomeKit accessory
5792
5795
  const accessories = await this.prepareAccessory();
5793
5796
  return accessories;