homebridge-enphase-envoy 10.3.0-beta.3 → 10.3.0-beta.5

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 CHANGED
@@ -13,9 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
 
14
14
  ## Changes
15
15
 
16
- - added support for Eve Energy Meter (Production, Consumption Net, Consumption Total)
16
+ - extend Eve Energy Meter to support (Production, Consumption Net, Consumption Total)
17
+ - fix [#218](https://github.com/grzegorz914/homebridge-enphase-envoy/issues/218)
17
18
  - stability and performance improvements
18
- - config chema updated
19
+ - config schema updated
19
20
  - readme updated
20
21
  - cleanup
21
22
 
package/index.js CHANGED
@@ -103,9 +103,9 @@ class EnvoyPlatform {
103
103
  .on('warn', (msg) => logLevel.warn && log.warn(`Device: ${host} ${deviceName}, ${msg}`))
104
104
  .on('error', (msg) => logLevel.error && log.error(`Device: ${host} ${deviceName}, ${msg}`));
105
105
 
106
- const accessory = await envoyDevice.start();
107
- if (accessory) {
108
- api.publishExternalAccessories(PluginName, accessory);
106
+ const accessories = await envoyDevice.start();
107
+ if (accessories) {
108
+ api.publishExternalAccessories(PluginName, accessories);
109
109
  if (logLevel.success) log.success(`Device: ${host} ${deviceName}, Published as external accessory.`);
110
110
 
111
111
  await impulseGenerator.state(false);
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.0-beta.3",
5
+ "version": "10.3.0-beta.5",
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
@@ -338,7 +338,6 @@ class EnvoyData extends EventEmitter {
338
338
  devices: [],
339
339
  settings: {},
340
340
  tariff: {},
341
- tariffRaw: {},
342
341
  ratedPowerSumKw: null,
343
342
  realPowerSumKw: null,
344
343
  phaseA: false,
@@ -450,7 +449,7 @@ class EnvoyData extends EventEmitter {
450
449
  const tokenNotValid = errorString.includes('status code 401');
451
450
  if (tokenNotValid) {
452
451
  if (this.checkTokenRunning) return;
453
-
452
+
454
453
  this.feature.info.jwtToken.token = '';
455
454
  this.feature.info.tokenValid = false;
456
455
  return;
@@ -1963,7 +1962,7 @@ class EnvoyData extends EventEmitter {
1963
1962
  };
1964
1963
 
1965
1964
  // Calculate encharges rated power summary in kW
1966
- this.pv.inventory.esubs.encharges.ratedPowerSumKw = enchargesRatedPowerSummary.length > 0 ? (enchargesRatedPowerSummary.reduce((total, num) => total + num, 0) / enchargesRatedPowerSummary.length) / 1000 : null;
1965
+ this.pv.inventory.esubs.encharges.ratedPowerSumKw = enchargesRatedPowerSummary.length > 0 ? enchargesRatedPowerSummary.reduce((total, num) => total + num, 0) / 1000 : null;
1967
1966
  }
1968
1967
 
1969
1968
  // Update enpowers statuses if installed
@@ -2043,7 +2042,7 @@ class EnvoyData extends EventEmitter {
2043
2042
  if (this.logDebug) this.emit('debug', `Ensemble power response:`, responseData);
2044
2043
 
2045
2044
  const devices = responseData.devices ?? [];
2046
- if (!devices.length === 0) return false;
2045
+ if (devices.length === 0) return false;
2047
2046
 
2048
2047
  // update encharges
2049
2048
  const enchargesRealPowerSummary = [];
@@ -2052,7 +2051,7 @@ class EnvoyData extends EventEmitter {
2052
2051
  const serialNumber = device.serial_num;
2053
2052
  const encharge = encharges.find(device => device.serialNumber === serialNumber);
2054
2053
  if (this.logDebug) this.emit('debug', `Ensemble device power:`, device);
2055
- if (!device) continue;
2054
+ if (!encharge) continue;
2056
2055
 
2057
2056
  encharge.power = {
2058
2057
  serialNumber: device.serial_num,
@@ -2066,7 +2065,7 @@ class EnvoyData extends EventEmitter {
2066
2065
  }
2067
2066
 
2068
2067
  // Calculate encharges real power summary in kW
2069
- this.pv.inventory.esubs.encharges.realPowerSumKw = enchargesRealPowerSummary.length > 0 ? (enchargesRealPowerSummary.reduce((total, num) => total + num, 0) / enchargesRealPowerSummary.length) / 1000 : null;
2068
+ this.pv.inventory.esubs.encharges.realPowerSumKw = enchargesRealPowerSummary.length > 0 ? enchargesRealPowerSummary.reduce((total, num) => total + num, 0) / 1000000 : null;
2070
2069
 
2071
2070
  // ensemble power supported
2072
2071
  this.feature.ensemble.power.supported = true;
@@ -2092,15 +2091,14 @@ class EnvoyData extends EventEmitter {
2092
2091
  const enchargesSettingsSupported = 'enc_settings' in enchargesSettings;
2093
2092
  if (!enchargesSettingsSupported) return false;
2094
2093
 
2095
- const settings = enchargesSettings.enc_settings;
2096
- const encharges = this.pv.inventory.esubs.encharges;
2097
- encharges.settings = {
2098
- enable: settings.enable, // boolean
2099
- country: settings.country, // string
2100
- currentLimit: settings.current_limit, // float
2101
- perPhase: settings.per_phase // boolean
2094
+ const settings = {
2095
+ enable: enchargesSettings.enc_settings.enable, // boolean
2096
+ country: enchargesSettings.enc_settings.country, // string
2097
+ currentLimit: enchargesSettings.enc_settings.current_limit, // float
2098
+ perPhase: enchargesSettings.enc_settings.per_phase // boolean
2102
2099
  };
2103
2100
 
2101
+ this.pv.inventory.esubs.encharges.settings = settings;
2104
2102
  this.feature.inventory.esubs.encharges.settings.supported = true;
2105
2103
 
2106
2104
  // RESTFul and MQTT update
@@ -2119,12 +2117,11 @@ class EnvoyData extends EventEmitter {
2119
2117
  try {
2120
2118
  const response = await this.axiosInstance.get(ApiUrls.TariffSettingsGetPut);
2121
2119
  const tariffSettings = response.data;
2122
-
2123
2120
  if (this.logDebug) this.emit('debug', 'Tariff:', tariffSettings);
2124
2121
 
2125
2122
  const enchargesTariffSupported = 'tariff' in tariffSettings;
2126
2123
  if (!enchargesTariffSupported) return false;
2127
- this.pv.inventory.esubs.encharges.tariffRaw = tariffSettings;
2124
+
2128
2125
  this.pv.inventory.esubs.encharges.tariff = tariffSettings;
2129
2126
  this.feature.inventory.esubs.encharges.tariff.supported = true;
2130
2127
 
@@ -2549,7 +2546,7 @@ class EnvoyData extends EventEmitter {
2549
2546
  if (this.logDebug) this.emit('debug', `Requesting set encharge settings`);
2550
2547
 
2551
2548
  try {
2552
- const tariff = this.pv.inventory.esubs.encharges.tariffRaw.tariff;
2549
+ const tariff = this.pv.inventory.esubs.encharges.tariff.tariff;
2553
2550
  tariff.storage_settings.mode = profile;
2554
2551
  tariff.storage_settings.reserved_soc = reservedSoc;
2555
2552
  tariff.storage_settings.charge_from_grid = chargeFromGrid;
@@ -786,7 +786,7 @@ class EnvoyDevice extends EventEmitter {
786
786
  const devices = this.energyMeter ? 2 : 1;
787
787
  for (let i = 0; i < devices; i++) {
788
788
  switch (i) {
789
- case 0://PV
789
+ case 0: //PV System
790
790
  const envoySerialNumber = this.pv.info.serialNumber;
791
791
  const accessoryName = this.name;
792
792
 
@@ -1988,8 +1988,8 @@ class EnvoyDevice extends EventEmitter {
1988
1988
  }
1989
1989
 
1990
1990
  if (ensemblesCountersSupported) characteristics.push({ type: Characteristic.RestPower, label: 'rest power', value: counters.restPowerKw, unit: 'kW' });
1991
- if (enchargesStatusSupported) characteristics.push({ type: Characteristic.RatedPower, label: 'rated power', value: this.pv.inventoryData.esubs.ratedPowerSumKw, unit: 'kW' });
1992
- if (enchargesPowerSupported) characteristics.push({ type: Characteristic.RealPower, label: 'real power', value: this.pv.inventoryData.esubs.realPowerSumKw, unit: 'kW' });
1991
+ if (enchargesStatusSupported) characteristics.push({ type: Characteristic.RatedPower, label: 'rated power', value: this.pv.inventoryData.esubs.encharges.ratedPowerSumKw, unit: 'kW' });
1992
+ if (enchargesPowerSupported) characteristics.push({ type: Characteristic.RealPower, label: 'real power', value: this.pv.inventoryData.esubs.encharges.realPowerSumKw, unit: 'kW' });
1993
1993
 
1994
1994
  for (const { type, label, value, unit = '', postfix = '' } of characteristics) {
1995
1995
  if (!this.functions.isValidValue(value)) continue;
@@ -2158,7 +2158,7 @@ class EnvoyDevice extends EventEmitter {
2158
2158
  if (this.enchargeBackupLevelSummarySensors.length > 0) {
2159
2159
  if (this.logDebug) this.emit('debug', `Prepare ${enchargeName} Backup Level Sensor Services`);
2160
2160
 
2161
- this.enchargeBackupLevelSummarySensorServices = [];
2161
+ this.enchargeBackupLevelSummarySensorsServices = [];
2162
2162
  for (let i = 0; i < this.enchargeBackupLevelSummarySensors.length; i++) {
2163
2163
  const sensor = this.enchargeBackupLevelSummarySensors[i];
2164
2164
  const { namePrefix, name, serviceType, characteristicType } = sensor;
@@ -2174,13 +2174,13 @@ class EnvoyDevice extends EventEmitter {
2174
2174
  return currentState;
2175
2175
  });
2176
2176
 
2177
- this.enchargeBackupLevelSummarySensorServices.push(sensorService);
2177
+ this.enchargeBackupLevelSummarySensorsServices.push(sensorService);
2178
2178
  }
2179
2179
  }
2180
2180
 
2181
2181
  //devices
2182
2182
  this.enchargeServices = [];
2183
- this.enchargeBackupLevelServices = [];
2183
+ this.enchargeBackupLevelControlServices = [];
2184
2184
 
2185
2185
  for (const encharge of this.pv.inventoryData.esubs.encharges.devices) {
2186
2186
  const serialNumber = encharge.serialNumber;
@@ -2231,7 +2231,7 @@ class EnvoyDevice extends EventEmitter {
2231
2231
  return currentChargeState;
2232
2232
  });
2233
2233
 
2234
- this.enchargeBackupLevelServices.push(controlService);
2234
+ this.enchargeBackupLevelControlServices.push(controlService);
2235
2235
  }
2236
2236
 
2237
2237
  if (this.logDebug) this.emit('debug', `Prepare ${enchargeName} ${serialNumber} Service`);
@@ -2399,24 +2399,23 @@ class EnvoyDevice extends EventEmitter {
2399
2399
  if (this.logDebug) this.emit('debug', `Prepare ${enchargeName} Profile Sensor Services`);
2400
2400
 
2401
2401
  this.enchargeProfileSensorsServices = [];
2402
-
2403
2402
  for (let i = 0; i < this.enchargeProfileSensors.length; i++) {
2404
2403
  const sensor = this.enchargeProfileSensors[i];
2405
2404
  const { namePrefix, name, serviceType, characteristicType } = sensor;
2406
2405
  const serviceName = namePrefix ? `${accessoryName} ${name}` : name;
2407
2406
 
2408
- const service = accessory.addService(serviceType, serviceName, `enchargeProfileSensorService${i}`);
2409
- service.addOptionalCharacteristic(Characteristic.ConfiguredName);
2410
- service.setCharacteristic(Characteristic.ConfiguredName, serviceName);
2407
+ const sensorService = accessory.addService(serviceType, serviceName, `enchargeProfileSensorService${i}`);
2408
+ sensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
2409
+ sensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
2411
2410
 
2412
- service.getCharacteristic(characteristicType)
2411
+ sensorService.getCharacteristic(characteristicType)
2413
2412
  .onGet(async () => {
2414
2413
  const currentState = sensor.state;
2415
2414
  if (this.logInfo) this.emit('info', `${enchargeName} profile: ${name}, state: ${currentState ? 'Active' : 'Not Active'}`);
2416
2415
  return currentState;
2417
2416
  });
2418
2417
 
2419
- this.enchargeProfileSensorsServices.push(service);
2418
+ this.enchargeProfileSensorsServices.push(sensorService);
2420
2419
  }
2421
2420
  }
2422
2421
  }
@@ -3002,7 +3001,7 @@ class EnvoyDevice extends EventEmitter {
3002
3001
 
3003
3002
  accessories.push(accessory);
3004
3003
  break;
3005
- case 1: //Energy Meter Production
3004
+ case 1: //EVE Energy Meter
3006
3005
  this.fakegatoHistoryServices = [];
3007
3006
  this.energyMeterServices = [];
3008
3007
  for (const source of this.pv.powerAndEnergyData.data) {
@@ -4435,7 +4434,7 @@ class EnvoyDevice extends EventEmitter {
4435
4434
  for (const { type, value, valueKey } of characteristics) {
4436
4435
  if (!this.functions.isValidValue(value)) continue;
4437
4436
  sensor[valueKey] = value;
4438
- this.enchargeBackupLevelSummarySensorServices?.[i]?.updateCharacteristic(type, value);
4437
+ this.enchargeBackupLevelSummarySensorsServices?.[i]?.updateCharacteristic(type, value);
4439
4438
  };
4440
4439
  }
4441
4440
  }
@@ -4784,7 +4783,7 @@ class EnvoyDevice extends EventEmitter {
4784
4783
  for (const { type, value, valueKey } of characteristics1) {
4785
4784
  if (!this.functions.isValidValue(value)) continue;
4786
4785
  control[valueKey] = value;
4787
- this.enchargeBackupLevelServices?.[index]?.updateCharacteristic(type, value);
4786
+ this.enchargeBackupLevelControlServices?.[index]?.updateCharacteristic(type, value);
4788
4787
  }
4789
4788
  }
4790
4789
 
@@ -5168,8 +5167,8 @@ class EnvoyDevice extends EventEmitter {
5168
5167
  // Update enpower grid mode sensors
5169
5168
  for (let i = 0; i < (this.enpowerGridModeSensors?.length ?? 0); i++) {
5170
5169
  const sensor = this.enpowerGridModeSensors[i];
5171
- const { characteristicType } = sensor;
5172
- const state = sensor.gridMode === enpowerData.enpwrGridMode;
5170
+ const { characteristicType, gridMode } = sensor;
5171
+ const state = gridMode === enpowerData.enpwrGridMode;
5173
5172
 
5174
5173
  // Create characteristics
5175
5174
  const characteristics = [
@@ -5711,7 +5710,7 @@ class EnvoyDevice extends EventEmitter {
5711
5710
  for (const { type, value, valueKey } of characteristics) {
5712
5711
  if (!this.functions.isValidValue(value)) continue;
5713
5712
  sensor[valueKey] = value;
5714
- this.enchargeBackupLevelSummarySensorServices?.[i]?.updateCharacteristic(type, value);
5713
+ this.enchargeBackupLevelSummarySensorsServices?.[i]?.updateCharacteristic(type, value);
5715
5714
  };
5716
5715
  }
5717
5716
  }
@@ -5785,8 +5784,8 @@ class EnvoyDevice extends EventEmitter {
5785
5784
  if (this.restFul.enable || this.mqtt.enable) await this.externalIntegrations();
5786
5785
 
5787
5786
  // Prepare HomeKit accessory
5788
- const accessory = await this.prepareAccessory();
5789
- return accessory;
5787
+ const accessories = await this.prepareAccessory();
5788
+ return accessories;
5790
5789
  } catch (error) {
5791
5790
  throw new Error(`Start error: ${error}`);
5792
5791
  }