homebridge-enphase-envoy 9.4.2 → 9.4.3-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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/envoydevice.js +29 -11
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": "9.4.2",
5
+ "version": "9.4.3-beta.0",
6
6
  "description": "Homebridge plugin for Photovoltaic Energy System manufactured by Enphase.",
7
7
  "license": "MIT",
8
8
  "author": "grzegorz914",
@@ -608,6 +608,17 @@ class EnvoyDevice extends EventEmitter {
608
608
  //url
609
609
  this.url = this.envoyFirmware7xx ? `https://${this.host}` : `http://${this.host}`;
610
610
 
611
+ //create axios instance
612
+ this.axiosInstance = axios.create({
613
+ method: 'GET',
614
+ baseURL: this.url,
615
+ withCredentials: true,
616
+ headers: {
617
+ Accept: 'application/json'
618
+ },
619
+ timeout: 25000
620
+ });
621
+
611
622
  //envoy dev id
612
623
  this.envoyDevId = '';
613
624
 
@@ -864,6 +875,9 @@ class EnvoyDevice extends EventEmitter {
864
875
  const updateInventory = updateHome ? await this.updateInventory() : false;
865
876
  } catch (error) {
866
877
  this.emit('error', `Impulse generator: ${error}`);
878
+ const errorString = error.toString();
879
+ const tokenNotValid = errorString.includes('status code 401');
880
+ this.validateToken = tokenNotValid;
867
881
  };
868
882
  }).on('updateMeters', async () => {
869
883
  try {
@@ -872,6 +886,9 @@ class EnvoyDevice extends EventEmitter {
872
886
  const updateMetersReading = updateMeters ? await this.updateMetersReading() : false;
873
887
  } catch (error) {
874
888
  this.emit('error', `Impulse generator: ${error}`);
889
+ const errorString = error.toString();
890
+ const tokenNotValid = errorString.includes('status code 401');
891
+ this.validateToken = tokenNotValid;
875
892
  };
876
893
  }).on('updateMicroinvertersStatus', async () => {
877
894
  try {
@@ -879,6 +896,9 @@ class EnvoyDevice extends EventEmitter {
879
896
  const updateMicroinvertersStatus = !tokenValid ? false : await this.updateMicroinvertersStatus();
880
897
  } catch (error) {
881
898
  this.emit('error', `Impulse generator: ${error}`);
899
+ const errorString = error.toString();
900
+ const tokenNotValid = errorString.includes('status code 401');
901
+ this.validateToken = tokenNotValid;
882
902
  };
883
903
  }).on('updateProduction', async () => {
884
904
  try {
@@ -887,6 +907,9 @@ class EnvoyDevice extends EventEmitter {
887
907
  const updateProductionCt = updateProduction ? await this.updateProductionCt() : false;
888
908
  } catch (error) {
889
909
  this.emit('error', `Impulse generator: ${error}`);
910
+ const errorString = error.toString();
911
+ const tokenNotValid = errorString.includes('status code 401');
912
+ this.validateToken = tokenNotValid;
890
913
  };
891
914
  }).on('updateEnsemble', async () => {
892
915
  try {
@@ -901,6 +924,9 @@ class EnvoyDevice extends EventEmitter {
901
924
  const updateGeneratorSettings = updateGenerator ? await this.updateGeneratorSettings() : false;
902
925
  } catch (error) {
903
926
  this.emit('error', `Impulse generator: ${error}`);
927
+ const errorString = error.toString();
928
+ const tokenNotValid = errorString.includes('status code 401');
929
+ this.validateToken = tokenNotValid;
904
930
  };
905
931
  }).on('updateLiveData', async () => {
906
932
  try {
@@ -908,6 +934,9 @@ class EnvoyDevice extends EventEmitter {
908
934
  const updateLiveData = !tokenValid ? false : await this.updateLiveData();
909
935
  } catch (error) {
910
936
  this.emit('error', `Impulse generator: ${error}`);
937
+ const errorString = error.toString();
938
+ const tokenNotValid = errorString.includes('status code 401');
939
+ this.validateToken = tokenNotValid;
911
940
  };
912
941
  }).on('state', (state) => {
913
942
  const emitState = state ? this.emit('success', `Impulse generator started.`) : this.emit('warn', `Impulse generator stopped.`);
@@ -962,17 +991,6 @@ class EnvoyDevice extends EventEmitter {
962
991
  this.refreshEnsemble = false;
963
992
  this.refreshLiveData = false;
964
993
 
965
- //create axios instance
966
- this.axiosInstance = axios.create({
967
- method: 'GET',
968
- baseURL: this.url,
969
- withCredentials: true,
970
- headers: {
971
- Accept: 'application/json'
972
- },
973
- timeout: 25000
974
- });
975
-
976
994
  //get and validate jwt token
977
995
  this.validateToken = true;
978
996
  const getJwtToken = this.envoyFirmware7xx ? this.envoyFirmware7xxTokenGenerationMode === 0 ? await this.getJwtToken() : true : false;