homebridge-enphase-envoy 10.2.5-beta.1 → 10.2.5-beta.10

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.2.5-beta.1",
5
+ "version": "10.2.5-beta.10",
6
6
  "description": "Homebridge p7ugin for Photovoltaic Energy System manufactured by Enphase.",
7
7
  "license": "MIT",
8
8
  "author": "grzegorz914",
@@ -25,8 +25,6 @@ class EnergyMeter extends EventEmitter {
25
25
  this.envoyFirmware7xxTokenGenerationMode = device.envoyFirmware7xxTokenGenerationMode;
26
26
  this.enlightenUser = device.enlightenUser;
27
27
  this.enlightenPasswd = device.enlightenPasswd;
28
- this.envoyToken = device.envoyToken;
29
- this.envoyTokenInstaller = device.envoyTokenInstaller;
30
28
  this.energyProductionLifetimeOffset = device.energyProductionLifetimeOffset || 0;
31
29
  this.energyConsumptionTotalLifetimeOffset = device.energyConsumptionTotalLifetimeOffset || 0;
32
30
  this.energyConsumptionNetLifetimeOffset = device.energyConsumptionNetLifetimeOffset || 0;
@@ -50,7 +48,7 @@ class EnergyMeter extends EventEmitter {
50
48
  this.lastReset = 0;
51
49
 
52
50
  //url
53
- this.url = envoyFirmware7xxTokenGenerationMode > 0 ? `https://${this.host}` : `http://${this.host}`;
51
+ this.url = device.envoyFirmware7xxTokenGenerationMode > 0 ? `https://${this.host}` : `http://${this.host}`;
54
52
 
55
53
  //supported functions
56
54
  this.feature = {
@@ -64,9 +62,9 @@ class EnergyMeter extends EventEmitter {
64
62
  cookie: '',
65
63
  jwtToken: {
66
64
  generation_time: 0,
67
- token: envoyToken,
65
+ token: device.envoyToken,
68
66
  expires_at: 0,
69
- installer: this.envoyFirmware7xxTokenGenerationMode === 2 ? this.envoyTokenInstaller : false
67
+ installer: this.envoyFirmware7xxTokenGenerationMode === 2 ? device.envoyTokenInstaller : false
70
68
  }
71
69
  },
72
70
  meters: {
@@ -484,7 +482,7 @@ class EnergyMeter extends EventEmitter {
484
482
  const jwt = this.feature.info.jwtToken;
485
483
 
486
484
  // Create a token-authenticated Axios instance
487
- const axiosInstance = this.functions.createAxiosInstance(`Bearer ${jwt.token}`, null);
485
+ const axiosInstance = this.functions.createAxiosInstance(this.url, `Bearer ${jwt.token}`, null);
488
486
 
489
487
  // Send validation request
490
488
  const response = await axiosInstance.get(ApiUrls.CheckJwt);
@@ -505,7 +503,7 @@ class EnergyMeter extends EventEmitter {
505
503
  }
506
504
 
507
505
  // Replace axios instance with cookie-authenticated one
508
- this.axiosInstance = this.functions.createAxiosInstance(null, cookie);
506
+ this.axiosInstance = this.functions.createAxiosInstance(this.url, null, cookie);
509
507
 
510
508
  // Update internal state
511
509
  this.feature.info.tokenValid = true;
@@ -715,7 +713,7 @@ class EnergyMeter extends EventEmitter {
715
713
  const obj = {
716
714
  type: 'pcu',
717
715
  activeCount: this.feature.inventory.pcus.count,
718
- measurementType: 'Production',
716
+ measurementType: 'production',
719
717
  readingTime,
720
718
  power: production.wattsNow,
721
719
  energyToday: production.wattHoursToday,
@@ -746,7 +744,7 @@ class EnergyMeter extends EventEmitter {
746
744
  // PCU
747
745
  const pcu = {
748
746
  type: 'pcu',
749
- measurementType: 'Production',
747
+ measurementType: 'production',
750
748
  activeCount: this.feature.inventory?.pcus?.count,
751
749
  readingTime,
752
750
  power: data.watts_now_pcu,
@@ -761,7 +759,7 @@ class EnergyMeter extends EventEmitter {
761
759
  const eimActive = !!data.there_is_an_active_eim;
762
760
  const eim = {
763
761
  type: 'eim',
764
- measurementType: 'Production',
762
+ measurementType: 'production',
765
763
  activeCount: 1,
766
764
  readingTime,
767
765
  active: eimActive,
@@ -777,7 +775,7 @@ class EnergyMeter extends EventEmitter {
777
775
  const rgmActive = !!data.there_is_an_active_rgm;
778
776
  const rgm = {
779
777
  type: 'rgm',
780
- measurementType: 'Production',
778
+ measurementType: 'production',
781
779
  activeCount: 1,
782
780
  readingTime,
783
781
  active: rgmActive,
@@ -793,7 +791,7 @@ class EnergyMeter extends EventEmitter {
793
791
  const pmuActive = !!data.there_is_an_active_pmu;
794
792
  const pmu = {
795
793
  type: 'pmu',
796
- measurementType: 'Production',
794
+ measurementType: 'production',
797
795
  activeCount: 1,
798
796
  readingTime,
799
797
  active: pmuActive,
@@ -831,7 +829,7 @@ class EnergyMeter extends EventEmitter {
831
829
  const obj = {
832
830
  type,
833
831
  activeCount: 1,
834
- measurementType: 'Production',
832
+ measurementType: 'production',
835
833
  readingTime,
836
834
  power: data.wattsNow,
837
835
  energyToday: data.wattHoursToday,
@@ -851,7 +849,7 @@ class EnergyMeter extends EventEmitter {
851
849
  const obj = {
852
850
  type: 'eim',
853
851
  activeCount: 1,
854
- measurementType: 'Consumption Net',
852
+ measurementType: 'net-consumption',
855
853
  readingTime,
856
854
  power: data.wattsNow,
857
855
  energyToday: data.wattHoursToday,
@@ -895,7 +893,7 @@ class EnergyMeter extends EventEmitter {
895
893
  const obj = {
896
894
  type: 'eim',
897
895
  activeCount: 1,
898
- measurementType: ApiCodes[productionEim.measurementType],
896
+ measurementType: productionEim.measurementType,
899
897
  readingTime: productionEim.readingTime,
900
898
  power: productionEim.wNow,
901
899
  energyToday,
@@ -915,14 +913,13 @@ class EnergyMeter extends EventEmitter {
915
913
  // --- Consumption: EIM ---
916
914
  if (keys.includes('consumption') && Array.isArray(data.consumption) && this.feature.meters.consumptionNet.enabled) {
917
915
  for (const item of data.consumption) {
918
- const type = ApiCodes[item.measurementType];
919
- const key = MetersKeyMap[type];
916
+ const key = MetersKeyMap[item.measurementType];
920
917
  const energyToday = (item.lines[0]?.whToday || 0) + (item.lines[1]?.whToday || 0) + (item.lines[2]?.whToday || 0);
921
918
  const energyLastSevenDays = (item.lines[0]?.whLastSevenDays || 0) + (item.lines[1]?.whLastSevenDays || 0) + (item.lines[2]?.whLastSevenDays || 0);
922
919
  const energyLifetime = (item.lines[0]?.whLifetime || 0) + (item.lines[1]?.whLifetime || 0) + (item.lines[2]?.whLifetime || 0);
923
920
  const obj = {
924
921
  type: 'eim',
925
- measurementType: type,
922
+ measurementType: item.measurementType,
926
923
  activeCount: 1,
927
924
  readingTime: item.readingTime,
928
925
  power: item.wNow,
@@ -1168,7 +1165,7 @@ class EnergyMeter extends EventEmitter {
1168
1165
 
1169
1166
  try {
1170
1167
  // Create axios instance
1171
- this.axiosInstance = this.functions.createAxiosInstance();
1168
+ this.axiosInstance = this.functions.createAxiosInstance(this.url);
1172
1169
 
1173
1170
  // Get basic PV info
1174
1171
  const getInfo = await this.getInfo();
package/src/envoydata.js CHANGED
@@ -12,13 +12,11 @@ class EnvoyData extends EventEmitter {
12
12
  super();
13
13
 
14
14
  //device configuration
15
- this.host = host;
15
+ this.host = device.host;
16
16
  this.envoyFirmware7xxTokenGenerationMode = device.envoyFirmware7xxTokenGenerationMode;
17
17
  this.envoyPasswd = device.envoyPasswd;
18
18
  this.enlightenUser = device.enlightenUser;
19
19
  this.enlightenPasswd = device.enlightenPasswd;
20
- this.envoyToken = device.envoyToken;
21
- this.envoyTokenInstaller = device.envoyTokenInstaller;
22
20
  this.envoyIdFile = envoyIdFile;
23
21
  this.envoyTokenFile = envoyTokenFile;
24
22
 
@@ -39,7 +37,7 @@ class EnvoyData extends EventEmitter {
39
37
  this.checkTokenRunning = false;
40
38
 
41
39
  //url
42
- this.url = envoyFirmware7xxTokenGenerationMode > 0 ? `https://${this.host}` : `http://${this.host}`;
40
+ this.url = device.envoyFirmware7xxTokenGenerationMode > 0 ? `https://${this.host}` : `http://${this.host}`;
43
41
 
44
42
  //supported functions
45
43
  this.feature = {
@@ -53,9 +51,9 @@ class EnvoyData extends EventEmitter {
53
51
  cookie: '',
54
52
  jwtToken: {
55
53
  generation_time: 0,
56
- token: envoyToken,
54
+ token: device.envoyToken,
57
55
  expires_at: 0,
58
- installer: this.envoyFirmware7xxTokenGenerationMode === 2 ? this.envoyTokenInstaller : false
56
+ installer: device.envoyFirmware7xxTokenGenerationMode === 2 ? device.envoyTokenInstaller : false
59
57
  }
60
58
  },
61
59
  backboneApp: {
@@ -713,7 +711,7 @@ class EnvoyData extends EventEmitter {
713
711
  const jwt = this.feature.info.jwtToken;
714
712
 
715
713
  // Create a token-authenticated Axios instance
716
- const axiosInstance = this.functions.createAxiosInstance(`Bearer ${jwt.token}`, null);
714
+ const axiosInstance = this.functions.createAxiosInstance(this.url, `Bearer ${jwt.token}`, null);
717
715
 
718
716
  // Send validation request
719
717
  const response = await axiosInstance.get(ApiUrls.CheckJwt);
@@ -734,7 +732,7 @@ class EnvoyData extends EventEmitter {
734
732
  }
735
733
 
736
734
  // Replace axios instance with cookie-authenticated one
737
- this.axiosInstance = this.functions.createAxiosInstance(null, cookie);
735
+ this.axiosInstance = this.functions.createAxiosInstance(this.url, null, cookie);
738
736
 
739
737
  // Update internal state
740
738
  this.feature.info.tokenValid = true;
@@ -2732,7 +2730,7 @@ class EnvoyData extends EventEmitter {
2732
2730
 
2733
2731
  try {
2734
2732
  // Create axios instance
2735
- this.axiosInstance = this.functions.createAxiosInstance();
2733
+ this.axiosInstance = this.functions.createAxiosInstance(this.url);
2736
2734
 
2737
2735
  // Get basic PV info
2738
2736
  const getInfo = await this.getInfo();
@@ -103,9 +103,9 @@ class EnvoyDevice extends EventEmitter {
103
103
 
104
104
  //system accessoty
105
105
  this.systemAccessory = {
106
- serviceType: ['', Service.Lightbulb, Service.Fan, Service.HumiditySensor, Service.CarbonMonoxideSensor][displayType],
107
- characteristicType: ['', Characteristic.On, Characteristic.On, Characteristic.StatusActive, Characteristic.CarbonMonoxideDetected][displayType],
108
- characteristicType1: ['', Characteristic.Brightness, Characteristic.RotationSpeed, Characteristic.CurrentRelativeHumidity, Characteristic.CarbonMonoxideLevel][displayType],
106
+ serviceType: ['', Service.Lightbulb, Service.Fan, Service.HumiditySensor, Service.CarbonMonoxideSensor][device.displayType],
107
+ characteristicType: ['', Characteristic.On, Characteristic.On, Characteristic.StatusActive, Characteristic.CarbonMonoxideDetected][device.displayType],
108
+ characteristicType1: ['', Characteristic.Brightness, Characteristic.RotationSpeed, Characteristic.CurrentRelativeHumidity, Characteristic.CarbonMonoxideLevel][device.displayType],
109
109
  state: false,
110
110
  level: 0
111
111
  }
@@ -361,9 +361,6 @@ class EnvoyDevice extends EventEmitter {
361
361
  this.envoyIdFile = envoyIdFile;
362
362
  this.envoyTokenFile = envoyTokenFile;
363
363
 
364
- //url
365
- this.url = envoyFirmware7xxTokenGenerationMode > 0 ? `https://${this.host}` : `http://${this.host}`;
366
-
367
364
  //supported functions
368
365
  this.feature = {
369
366
  productionState: {
package/src/functions.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { promises as fsPromises } from 'fs';
2
+ import axios from 'axios';
3
+ import { Agent } from 'https';
2
4
  import { ApiCodes, TimezoneLocaleMap } from './constants.js';
3
5
 
4
6
  class Functions {
@@ -112,9 +114,9 @@ class Functions {
112
114
  return powerPeakStored;
113
115
  }
114
116
 
115
- createAxiosInstance(authHeader = null, cookie = null) {
117
+ createAxiosInstance(url, authHeader = null, cookie = null) {
116
118
  return axios.create({
117
- baseURL: this.url,
119
+ baseURL: url,
118
120
  headers: {
119
121
  Accept: 'application/json',
120
122
  ...(authHeader ? { Authorization: authHeader } : {}),
@@ -122,7 +124,7 @@ class Functions {
122
124
  },
123
125
  withCredentials: true,
124
126
  httpsAgent: new Agent({
125
- keepAlive: false,
127
+ keepAlive: true,
126
128
  rejectUnauthorized: false
127
129
  }),
128
130
  timeout: 60000