homebridge-enphase-envoy 9.13.2 → 9.13.3

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 +346 -350
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.13.2",
5
+ "version": "9.13.3",
6
6
  "description": "Homebridge plugin for Photovoltaic Energy System manufactured by Enphase.",
7
7
  "license": "MIT",
8
8
  "author": "grzegorz914",
@@ -982,7 +982,6 @@ class EnvoyDevice extends EventEmitter {
982
982
  try {
983
983
  const response = await this.axiosInstance(ApiUrls.GetInfo);
984
984
  const infoData = response.data;
985
- const debug = this.enableDebugMode ? this.emit('debug', `Info:`, infoData) : false;
986
985
 
987
986
  //parse info
988
987
  const options = {
@@ -1002,7 +1001,7 @@ class EnvoyDevice extends EventEmitter {
1002
1001
  }
1003
1002
  }
1004
1003
  };
1005
- const debug1 = this.enableDebugMode ? this.emit('debug', `Parsed info:`, updatedInfoData) : false;
1004
+ const debug = this.enableDebugMode ? this.emit('debug', `Parsed info:`, updatedInfoData) : false;
1006
1005
 
1007
1006
  //envoy
1008
1007
  const envoyInfo = parseInfoData.envoy_info;
@@ -1802,7 +1801,7 @@ class EnvoyDevice extends EventEmitter {
1802
1801
 
1803
1802
  const response = this.pv.envoy.firmware7xx ? await this.axiosInstance(ApiUrls.InverterProduction) : await this.digestAuthEnvoy.request(ApiUrls.InverterProduction, options);
1804
1803
  const pcus = response.data;
1805
- const debug = this.enableDebugMode ? this.emit('debug', `Pcu status:`, pcu) : false;
1804
+ const debug = this.enableDebugMode ? this.emit('debug', `Pcu status:`, pcus) : false;
1806
1805
 
1807
1806
  //pcu devices count
1808
1807
  const pcuStatusSupported = pcus.length > 0;
@@ -1834,10 +1833,10 @@ class EnvoyDevice extends EventEmitter {
1834
1833
  this.feature.pcu.status.supported = pcuStatusSupported;
1835
1834
 
1836
1835
  //restFul
1837
- const restFul = this.restFulConnected ? this.restFul1.update('microinverters', pcu) : false;
1836
+ const restFul = this.restFulConnected ? this.restFul1.update('microinverters', pcus) : false;
1838
1837
 
1839
1838
  //mqtt
1840
- const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', 'Microinverters', pcu) : false;
1839
+ const mqtt = this.mqttConnected ? this.mqtt1.emit('publish', 'Microinverters', pcus) : false;
1841
1840
  return true;
1842
1841
  } catch (error) {
1843
1842
  throw new Error(`Update pcu status error: ${error}`);
@@ -4565,7 +4564,7 @@ class EnvoyDevice extends EventEmitter {
4565
4564
  }
4566
4565
  }
4567
4566
  };
4568
- const debug20 = this.enableDebugMode && this.feature.envoy.installed ? this.emit('debug', `Pv object:`, pv) : false;
4567
+ const debug1 = this.enableDebugMode ? this.emit('debug', `Pv object:`, pv) : false;
4569
4568
 
4570
4569
  //display info
4571
4570
  this.emit('devInfo', `-------- ${this.name} --------`);
@@ -4701,6 +4700,11 @@ class EnvoyDevice extends EventEmitter {
4701
4700
  };
4702
4701
  };
4703
4702
 
4703
+ async scaleValue(value, inMin, inMax, outMin, outMax) {
4704
+ const scaledValue = parseFloat((((Math.max(inMin, Math.min(inMax, value)) - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin).toFixed(0));
4705
+ return scaledValue;
4706
+ };
4707
+
4704
4708
  async startImpulseGenerator() {
4705
4709
  try {
4706
4710
  //start impulse generator
@@ -4711,16 +4715,10 @@ class EnvoyDevice extends EventEmitter {
4711
4715
  };
4712
4716
  };
4713
4717
 
4714
- async scaleValue(value, inMin, inMax, outMin, outMax) {
4715
- const scaledValue = parseFloat((((Math.max(inMin, Math.min(inMax, value)) - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin).toFixed(0));
4716
- return scaledValue;
4717
- };
4718
-
4719
4718
  //prepare accessory
4720
4719
  async prepareAccessory() {
4721
4720
  try {
4722
4721
  //suppored feature
4723
- const envoyInstalled = this.feature.envoy.installed;
4724
4722
  const envoySerialNumber = this.pv.envoy.info.serialNumber;
4725
4723
  const productionStateSupported = this.feature.productionState.supported;
4726
4724
  const plcLevelSupported = this.feature.plcLevel.supported;
@@ -4765,398 +4763,396 @@ class EnvoyDevice extends EventEmitter {
4765
4763
  .setCharacteristic(Characteristic.FirmwareRevision, this.pv.envoy.info.software.replace(/[a-zA-Z]/g, '') ?? '0');
4766
4764
 
4767
4765
  //system and envoy
4768
- if (envoyInstalled) {
4769
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare System Service`) : false;
4770
- const serviceType = this.systemAccessoryActive.serviceType;
4771
- const characteristicType = this.systemAccessoryActive.characteristicType;
4772
- const characteristicType1 = this.systemAccessoryActive.characteristicType1;
4773
- const systemService = accessory.addService(serviceType, accessoryName, `systemService`);
4774
- systemService.setPrimaryService(true);
4775
- systemService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4776
- systemService.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
4777
- systemService.getCharacteristic(characteristicType)
4766
+ const debug2 = this.enableDebugMode ? this.emit('debug', `Prepare System Service`) : false;
4767
+ const serviceType = this.systemAccessoryActive.serviceType;
4768
+ const characteristicType = this.systemAccessoryActive.characteristicType;
4769
+ const characteristicType1 = this.systemAccessoryActive.characteristicType1;
4770
+ const systemService = accessory.addService(serviceType, accessoryName, `systemService`);
4771
+ systemService.setPrimaryService(true);
4772
+ systemService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4773
+ systemService.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
4774
+ systemService.getCharacteristic(characteristicType)
4775
+ .onGet(async () => {
4776
+ const state = this.systemAccessoryActive.state;
4777
+ const info = this.disableLogInfo ? false : this.emit('info', `Production power state: ${state ? 'Enabled' : 'Disabled'}`);
4778
+ return state;
4779
+ })
4780
+ .onSet(async (state) => {
4781
+ systemService.updateCharacteristic(Characteristic.On, this.pv.powerState);
4782
+ });
4783
+ systemService.getCharacteristic(characteristicType1)
4784
+ .onGet(async () => {
4785
+ const value = this.systemAccessoryActive.level;
4786
+ const info = this.disableLogInfo ? false : this.emit('info', `Production power level: ${value} %`);
4787
+ return value;
4788
+ })
4789
+ .onSet(async (value) => {
4790
+ systemService.updateCharacteristic(Characteristic.Brightness, this.pv.powerLevel);
4791
+ });
4792
+ this.systemService = systemService;
4793
+
4794
+ //data refresh control service
4795
+ if (this.dataRefreshActiveControl) {
4796
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Data Refresh Control Service`) : false;
4797
+ const serviceName = this.dataRefreshActiveControl.namePrefix ? `${accessoryName} ${this.dataRefreshActiveControl.name}` : this.dataRefreshActiveControl.name;
4798
+ const serviceType = this.dataRefreshActiveControl.serviceType;
4799
+ const characteristicType = this.dataRefreshActiveControl.characteristicType;
4800
+ const dataRefreshControlService = accessory.addService(serviceType, serviceName, `dataRefreshControlService`);
4801
+ dataRefreshControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4802
+ dataRefreshControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4803
+ dataRefreshControlService.getCharacteristic(characteristicType)
4778
4804
  .onGet(async () => {
4779
- const state = this.systemAccessoryActive.state;
4780
- const info = this.disableLogInfo ? false : this.emit('info', `Production power state: ${state ? 'Enabled' : 'Disabled'}`);
4805
+ const state = this.dataRefreshActiveControl.state;
4806
+ const info = this.disableLogInfo ? false : this.emit('info', `Data refresh control: ${state ? 'Enabled' : 'Disabled'}`);
4781
4807
  return state;
4782
4808
  })
4783
4809
  .onSet(async (state) => {
4784
- systemService.updateCharacteristic(Characteristic.On, this.pv.powerState);
4785
- });
4786
- systemService.getCharacteristic(characteristicType1)
4787
- .onGet(async () => {
4788
- const value = this.systemAccessoryActive.level;
4789
- const info = this.disableLogInfo ? false : this.emit('info', `Production power level: ${value} %`);
4790
- return value;
4810
+ try {
4811
+ const setState = state ? await this.impulseGenerator.start(this.timers) : await this.impulseGenerator.stop();
4812
+ const info = this.disableLogInfo ? false : this.emit('info', `Set data refresh control to: ${state ? `Enable` : `Disable`}`);
4813
+ } catch (error) {
4814
+ this.emit('warn', `Set data refresh contol error: ${error}`);
4815
+ };
4791
4816
  })
4792
- .onSet(async (value) => {
4793
- systemService.updateCharacteristic(Characteristic.Brightness, this.pv.powerLevel);
4794
- });
4795
- this.systemService = systemService;
4796
-
4797
- //data refresh control service
4798
- if (this.dataRefreshActiveControl) {
4799
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Data Refresh Control Service`) : false;
4800
- const serviceName = this.dataRefreshActiveControl.namePrefix ? `${accessoryName} ${this.dataRefreshActiveControl.name}` : this.dataRefreshActiveControl.name;
4801
- const serviceType = this.dataRefreshActiveControl.serviceType;
4802
- const characteristicType = this.dataRefreshActiveControl.characteristicType;
4803
- const dataRefreshControlService = accessory.addService(serviceType, serviceName, `dataRefreshControlService`);
4804
- dataRefreshControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4805
- dataRefreshControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4806
- dataRefreshControlService.getCharacteristic(characteristicType)
4807
- .onGet(async () => {
4808
- const state = this.dataRefreshActiveControl.state;
4809
- const info = this.disableLogInfo ? false : this.emit('info', `Data refresh control: ${state ? 'Enabled' : 'Disabled'}`);
4810
- return state;
4811
- })
4812
- .onSet(async (state) => {
4813
- try {
4814
- const setState = state ? await this.impulseGenerator.start(this.timers) : await this.impulseGenerator.stop();
4815
- const info = this.disableLogInfo ? false : this.emit('info', `Set data refresh control to: ${state ? `Enable` : `Disable`}`);
4816
- } catch (error) {
4817
- this.emit('warn', `Set data refresh contol error: ${error}`);
4818
- };
4819
- })
4820
- this.dataRefreshControlService = dataRefreshControlService;
4821
- };
4822
-
4823
- //data refresh sensor service
4824
- if (this.dataRefreshActiveSensor) {
4825
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Data Refresh Sensor Service`) : false;
4826
- const serviceName = this.dataRefreshActiveSensor.namePrefix ? `${accessoryName} ${this.dataRefreshActiveSensor.name}` : this.dataRefreshActiveSensor.name;
4827
- const serviceType = this.dataRefreshActiveSensor.serviceType;
4828
- const characteristicType = this.dataRefreshActiveSensor.characteristicType;
4829
- const dataRefreshSensorService = accessory.addService(serviceType, serviceName, `dataRefreshSensorService`);
4830
- dataRefreshSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4831
- dataRefreshSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4832
- dataRefreshSensorService.getCharacteristic(characteristicType)
4833
- .onGet(async () => {
4834
- const state = this.dataRefreshActiveSensor.state;
4835
- const info = this.disableLogInfo ? false : this.emit('info', `Data refresh sensor: ${state ? 'Active' : 'Not active'}`);
4836
- return state;
4837
- });
4838
- this.dataRefreshSensorService = dataRefreshSensorService;
4839
- };
4840
-
4841
- //production state control service
4842
- if (this.productionStateActiveControl && productionStateSupported) {
4843
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production State Control Service`) : false;
4844
- const serviceName = this.productionStateActiveControl.namePrefix ? `${accessoryName} ${this.productionStateActiveControl.name}` : this.productionStateActiveControl.name;
4845
- const serviceType = this.productionStateActiveControl.serviceType;
4846
- const characteristicType = this.productionStateActiveControl.characteristicType;
4847
- const productionStateControlService = accessory.addService(serviceType, serviceName, `productionStateControlService`);
4848
- productionStateControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4849
- productionStateControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4850
- productionStateControlService.getCharacteristic(characteristicType)
4851
- .onGet(async () => {
4852
- const state = this.productionStateActiveControl.state;
4853
- const info = this.disableLogInfo ? false : this.emit('info', `Production state: ${state ? 'ON' : 'OFF'}`);
4854
- return state;
4855
- })
4856
- .onSet(async (state) => {
4857
- try {
4858
- const tokenValid = await this.checkJwtToken();
4859
- const setState = tokenValid && (state !== this.pv.productionState) ? await this.setProductionState(state) : false;
4860
- const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Set production state to: ${setState ? `ON` : `OFF`}`);
4861
- } catch (error) {
4862
- this.emit('warn', `Set production state error: ${error}`);
4863
- };
4864
- })
4865
- this.productionStateControlService = productionStateControlService;
4866
- };
4867
-
4868
- //production state sensor service
4869
- if (this.productionStateActiveSensor && productionStateSupported) {
4870
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production State Sensor Service`) : false;
4871
- const serviceName = this.productionStateActiveSensor.namePrefix ? `${accessoryName} ${this.productionStateActiveSensor.name}` : this.productionStateActiveSensor.name;
4872
- const serviceType = this.productionStateActiveSensor.serviceType;
4873
- const characteristicType = this.productionStateActiveSensor.characteristicType;
4874
- const productionStateSensorService = accessory.addService(serviceType, serviceName, `productionStateSensorService`);
4875
- productionStateSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4876
- productionStateSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4877
- productionStateSensorService.getCharacteristic(characteristicType)
4878
- .onGet(async () => {
4879
- const state = this.productionStateActiveSensor.state;
4880
- const info = this.disableLogInfo ? false : this.emit('info', `Production state sensor: ${state ? 'Active' : 'Not active'}`);
4881
- return state;
4882
- });
4883
- this.productionStateSensorService = productionStateSensorService;
4884
- };
4817
+ this.dataRefreshControlService = dataRefreshControlService;
4818
+ };
4885
4819
 
4886
- //plc level control service
4887
- if (this.plcLevelActiveControl && plcLevelSupported) {
4888
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Plc Level Control Service`) : false;
4889
- const serviceName = this.plcLevelActiveControl.namePrefix ? `${accessoryName} ${this.plcLevelActiveControl.name}` : this.plcLevelActiveControl.name;
4890
- const serviceType = this.plcLevelActiveControl.serviceType;
4891
- const characteristicType = this.plcLevelActiveControl.characteristicType;
4892
- const plcLevelContolService = accessory.addService(serviceType, serviceName, `plcLevelContolService`);
4893
- plcLevelContolService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4894
- plcLevelContolService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4895
- plcLevelContolService.getCharacteristic(characteristicType)
4896
- .onGet(async () => {
4897
- const state = this.plcLevelActiveControl.state;
4898
- const info = this.disableLogInfo ? false : this.emit('info', `Plc level control state: ${state ? 'ON' : 'OFF'}`);
4899
- return state;
4900
- })
4901
- .onSet(async (state) => {
4902
- try {
4903
- const tokenValid = await this.checkJwtToken();
4904
- const setState = tokenValid && state ? await this.updatePlcLevel() : false;
4905
- const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Set plc level control state to: ${setState ? `ON` : `OFF`}`);
4906
- } catch (error) {
4907
- this.emit('warn', `Set plc level control state error: ${error}`);
4908
- };
4909
- })
4910
- this.plcLevelControlService = plcLevelContolService;
4911
- };
4820
+ //data refresh sensor service
4821
+ if (this.dataRefreshActiveSensor) {
4822
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Data Refresh Sensor Service`) : false;
4823
+ const serviceName = this.dataRefreshActiveSensor.namePrefix ? `${accessoryName} ${this.dataRefreshActiveSensor.name}` : this.dataRefreshActiveSensor.name;
4824
+ const serviceType = this.dataRefreshActiveSensor.serviceType;
4825
+ const characteristicType = this.dataRefreshActiveSensor.characteristicType;
4826
+ const dataRefreshSensorService = accessory.addService(serviceType, serviceName, `dataRefreshSensorService`);
4827
+ dataRefreshSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4828
+ dataRefreshSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4829
+ dataRefreshSensorService.getCharacteristic(characteristicType)
4830
+ .onGet(async () => {
4831
+ const state = this.dataRefreshActiveSensor.state;
4832
+ const info = this.disableLogInfo ? false : this.emit('info', `Data refresh sensor: ${state ? 'Active' : 'Not active'}`);
4833
+ return state;
4834
+ });
4835
+ this.dataRefreshSensorService = dataRefreshSensorService;
4836
+ };
4912
4837
 
4913
- //envoy
4914
- const debug1 = this.enableDebugMode ? this.emit('debug', `Prepare Envoy ${envoySerialNumber} Service`) : false;
4915
- const envoyService = accessory.addService(Service.EnphaseEnvoyService, `Envoy ${envoySerialNumber}`, `envoyService`);
4916
- envoyService.setCharacteristic(Characteristic.ConfiguredName, `Envoy ${envoySerialNumber}`);
4917
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyDataRefresh)
4838
+ //production state control service
4839
+ if (this.productionStateActiveControl && productionStateSupported) {
4840
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production State Control Service`) : false;
4841
+ const serviceName = this.productionStateActiveControl.namePrefix ? `${accessoryName} ${this.productionStateActiveControl.name}` : this.productionStateActiveControl.name;
4842
+ const serviceType = this.productionStateActiveControl.serviceType;
4843
+ const characteristicType = this.productionStateActiveControl.characteristicType;
4844
+ const productionStateControlService = accessory.addService(serviceType, serviceName, `productionStateControlService`);
4845
+ productionStateControlService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4846
+ productionStateControlService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4847
+ productionStateControlService.getCharacteristic(characteristicType)
4918
4848
  .onGet(async () => {
4919
- const state = this.feature.dataSampling;
4920
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, data refresh control: ${state ? 'Enabled' : 'Disabled'}`);
4849
+ const state = this.productionStateActiveControl.state;
4850
+ const info = this.disableLogInfo ? false : this.emit('info', `Production state: ${state ? 'ON' : 'OFF'}`);
4921
4851
  return state;
4922
4852
  })
4923
4853
  .onSet(async (state) => {
4924
4854
  try {
4925
- const setStatet = state ? await this.impulseGenerator.start(this.timers) : await this.impulseGenerator.stop();
4926
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, set data refresh control to: ${state ? `Enable` : `Disable`}`);
4855
+ const tokenValid = await this.checkJwtToken();
4856
+ const setState = tokenValid && (state !== this.pv.productionState) ? await this.setProductionState(state) : false;
4857
+ const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Set production state to: ${setState ? `ON` : `OFF`}`);
4927
4858
  } catch (error) {
4928
- this.emit('warn', `Envoy: ${envoySerialNumber}, set data refresh control error: ${error}`);
4859
+ this.emit('warn', `Set production state error: ${error}`);
4929
4860
  };
4930
- });
4931
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyAlerts)
4861
+ })
4862
+ this.productionStateControlService = productionStateControlService;
4863
+ };
4864
+
4865
+ //production state sensor service
4866
+ if (this.productionStateActiveSensor && productionStateSupported) {
4867
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Production State Sensor Service`) : false;
4868
+ const serviceName = this.productionStateActiveSensor.namePrefix ? `${accessoryName} ${this.productionStateActiveSensor.name}` : this.productionStateActiveSensor.name;
4869
+ const serviceType = this.productionStateActiveSensor.serviceType;
4870
+ const characteristicType = this.productionStateActiveSensor.characteristicType;
4871
+ const productionStateSensorService = accessory.addService(serviceType, serviceName, `productionStateSensorService`);
4872
+ productionStateSensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4873
+ productionStateSensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4874
+ productionStateSensorService.getCharacteristic(characteristicType)
4932
4875
  .onGet(async () => {
4933
- const value = this.pv.envoy.home.alerts;
4934
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, alerts: ${value}`);
4935
- return value;
4876
+ const state = this.productionStateActiveSensor.state;
4877
+ const info = this.disableLogInfo ? false : this.emit('info', `Production state sensor: ${state ? 'Active' : 'Not active'}`);
4878
+ return state;
4936
4879
  });
4937
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyPrimaryInterface)
4880
+ this.productionStateSensorService = productionStateSensorService;
4881
+ };
4882
+
4883
+ //plc level control service
4884
+ if (this.plcLevelActiveControl && plcLevelSupported) {
4885
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Plc Level Control Service`) : false;
4886
+ const serviceName = this.plcLevelActiveControl.namePrefix ? `${accessoryName} ${this.plcLevelActiveControl.name}` : this.plcLevelActiveControl.name;
4887
+ const serviceType = this.plcLevelActiveControl.serviceType;
4888
+ const characteristicType = this.plcLevelActiveControl.characteristicType;
4889
+ const plcLevelContolService = accessory.addService(serviceType, serviceName, `plcLevelContolService`);
4890
+ plcLevelContolService.addOptionalCharacteristic(Characteristic.ConfiguredName);
4891
+ plcLevelContolService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
4892
+ plcLevelContolService.getCharacteristic(characteristicType)
4938
4893
  .onGet(async () => {
4939
- const value = this.pv.envoy.home.network.primaryInterface;
4940
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, network interface: ${value}`);
4941
- return value;
4942
- });
4943
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyNetworkWebComm)
4894
+ const state = this.plcLevelActiveControl.state;
4895
+ const info = this.disableLogInfo ? false : this.emit('info', `Plc level control state: ${state ? 'ON' : 'OFF'}`);
4896
+ return state;
4897
+ })
4898
+ .onSet(async (state) => {
4899
+ try {
4900
+ const tokenValid = await this.checkJwtToken();
4901
+ const setState = tokenValid && state ? await this.updatePlcLevel() : false;
4902
+ const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Set plc level control state to: ${setState ? `ON` : `OFF`}`);
4903
+ } catch (error) {
4904
+ this.emit('warn', `Set plc level control state error: ${error}`);
4905
+ };
4906
+ })
4907
+ this.plcLevelControlService = plcLevelContolService;
4908
+ };
4909
+
4910
+ //envoy
4911
+ const debug3 = this.enableDebugMode ? this.emit('debug', `Prepare Envoy ${envoySerialNumber} Service`) : false;
4912
+ const envoyService = accessory.addService(Service.EnphaseEnvoyService, `Envoy ${envoySerialNumber}`, `envoyService`);
4913
+ envoyService.setCharacteristic(Characteristic.ConfiguredName, `Envoy ${envoySerialNumber}`);
4914
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyDataRefresh)
4915
+ .onGet(async () => {
4916
+ const state = this.feature.dataSampling;
4917
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, data refresh control: ${state ? 'Enabled' : 'Disabled'}`);
4918
+ return state;
4919
+ })
4920
+ .onSet(async (state) => {
4921
+ try {
4922
+ const setStatet = state ? await this.impulseGenerator.start(this.timers) : await this.impulseGenerator.stop();
4923
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, set data refresh control to: ${state ? `Enable` : `Disable`}`);
4924
+ } catch (error) {
4925
+ this.emit('warn', `Envoy: ${envoySerialNumber}, set data refresh control error: ${error}`);
4926
+ };
4927
+ });
4928
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyAlerts)
4929
+ .onGet(async () => {
4930
+ const value = this.pv.envoy.home.alerts;
4931
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, alerts: ${value}`);
4932
+ return value;
4933
+ });
4934
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyPrimaryInterface)
4935
+ .onGet(async () => {
4936
+ const value = this.pv.envoy.home.network.primaryInterface;
4937
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, network interface: ${value}`);
4938
+ return value;
4939
+ });
4940
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyNetworkWebComm)
4941
+ .onGet(async () => {
4942
+ const value = this.pv.envoy.home.network.webComm;
4943
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, web communication: ${value ? 'Yes' : 'No'}`);
4944
+ return value;
4945
+ });
4946
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyEverReportedToEnlighten)
4947
+ .onGet(async () => {
4948
+ const value = this.pv.envoy.home.network.everReportedToEnlighten;
4949
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, report to enlighten: ${value ? 'Yes' : 'No'}`);
4950
+ return value;
4951
+ });
4952
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumAndLevel)
4953
+ .onGet(async () => {
4954
+ const value = (`${this.pv.envoy.home.comm.num} / ${this.pv.envoy.home.comm.level} %`);
4955
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication devices and level: ${value}`);
4956
+ return value;
4957
+ });
4958
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumNsrbAndLevel)
4959
+ .onGet(async () => {
4960
+ const value = (`${this.pv.envoy.home.comm.nsrbNum} / ${this.pv.envoy.home.comm.nsrbLevel} %`);
4961
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication qRelays and level: ${value}`);
4962
+ return value;
4963
+ });
4964
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumPcuAndLevel)
4965
+ .onGet(async () => {
4966
+ const value = (`${this.pv.envoy.home.comm.pcuNum} / ${this.pv.envoy.home.comm.pcuLevel} %`);
4967
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication Microinverters and level: ${value}`);
4968
+ return value;
4969
+ });
4970
+ if (acBatteriesInstalled) {
4971
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumAcbAndLevel)
4944
4972
  .onGet(async () => {
4945
- const value = this.pv.envoy.home.network.webComm;
4946
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, web communication: ${value ? 'Yes' : 'No'}`);
4973
+ const value = (`${this.pv.envoy.home.comm.acbNum} / ${this.pv.envoy.home.comm.acbLevel} %`);
4974
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication ${acBatterieName} and level ${value}`);
4947
4975
  return value;
4948
4976
  });
4949
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyEverReportedToEnlighten)
4977
+ }
4978
+ if (enchargesInstalled) {
4979
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumEnchgAndLevel)
4950
4980
  .onGet(async () => {
4951
- const value = this.pv.envoy.home.network.everReportedToEnlighten;
4952
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, report to enlighten: ${value ? 'Yes' : 'No'}`);
4981
+ const value = (`${this.pv.envoy.home.comm.encharges[0].num} / ${this.pv.envoy.home.comm.encharges[0].level} %`);
4982
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication ${enchargeName} and level ${value}`);
4953
4983
  return value;
4954
4984
  });
4955
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumAndLevel)
4985
+ }
4986
+ if (this.pv.envoy.home.dbSize !== -1 && this.pv.envoy.home.dbPercentFull !== -1) {
4987
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyDbSize)
4956
4988
  .onGet(async () => {
4957
- const value = (`${this.pv.envoy.home.comm.num} / ${this.pv.envoy.home.comm.level} %`);
4958
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication devices and level: ${value}`);
4989
+ const value = `${this.pv.envoy.home.dbSize} / ${this.pv.envoy.home.dbPercentFull} %`;
4990
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, data base size: ${value}`);
4959
4991
  return value;
4960
4992
  });
4961
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumNsrbAndLevel)
4993
+ }
4994
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyTariff)
4995
+ .onGet(async () => {
4996
+ const value = this.pv.envoy.home.tariff;
4997
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, tariff: ${value}`);
4998
+ return value;
4999
+ });
5000
+ if (this.pv.envoy.home.updateStatus) {
5001
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyUpdateStatus)
4962
5002
  .onGet(async () => {
4963
- const value = (`${this.pv.envoy.home.comm.nsrbNum} / ${this.pv.envoy.home.comm.nsrbLevel} %`);
4964
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication qRelays and level: ${value}`);
5003
+ const value = this.pv.envoy.home.updateStatus;
5004
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, update status: ${value}`);
4965
5005
  return value;
4966
5006
  });
4967
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumPcuAndLevel)
5007
+ }
5008
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyFirmware)
5009
+ .onGet(async () => {
5010
+ const value = this.pv.envoy.info.software;
5011
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, firmware: ${value}`);
5012
+ return value;
5013
+ });
5014
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyTimeZone)
5015
+ .onGet(async () => {
5016
+ const value = this.pv.envoy.home.timeZone;
5017
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, time zone: ${value}`);
5018
+ return value;
5019
+ });
5020
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCurrentDateTime)
5021
+ .onGet(async () => {
5022
+ const value = `${this.pv.envoy.home.currentDate} ${this.pv.envoy.home.currentTime}`;
5023
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, current date and time: ${value}`);
5024
+ return value;
5025
+ });
5026
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyLastEnlightenReporDate)
5027
+ .onGet(async () => {
5028
+ const value = this.pv.envoy.home.network.lastEnlightenReporDate;
5029
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, last report to enlighten: ${value}`);
5030
+ return value;
5031
+ });
5032
+ if (productionStateSupported) {
5033
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyProductionPowerMode)
4968
5034
  .onGet(async () => {
4969
- const value = (`${this.pv.envoy.home.comm.pcuNum} / ${this.pv.envoy.home.comm.pcuLevel} %`);
4970
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication Microinverters and level: ${value}`);
4971
- return value;
5035
+ const state = this.pv.productionState;
5036
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, production state: ${state ? 'Enabled' : 'Disabled'}`);
5037
+ return state;
5038
+ })
5039
+ .onSet(async (state) => {
5040
+ try {
5041
+ const tokenValid = await this.checkJwtToken();
5042
+ const setState = tokenValid && (state !== this.pv.productionState) ? await this.setProductionState(state) : false;
5043
+ const debug = this.enableDebugMode || !tokenValid ? this.emit('debug', `Envoy: ${envoySerialNumber}, set production state: ${setState ? 'Enabled' : 'Disabled'}`) : false;
5044
+ } catch (error) {
5045
+ this.emit('warn', `Envoy: ${envoySerialNumber}, set production state error: ${error}`);
5046
+ };
4972
5047
  });
4973
- if (acBatteriesInstalled) {
4974
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumAcbAndLevel)
4975
- .onGet(async () => {
4976
- const value = (`${this.pv.envoy.home.comm.acbNum} / ${this.pv.envoy.home.comm.acbLevel} %`);
4977
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication ${acBatterieName} and level ${value}`);
4978
- return value;
4979
- });
4980
- }
4981
- if (enchargesInstalled) {
4982
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCommNumEnchgAndLevel)
4983
- .onGet(async () => {
4984
- const value = (`${this.pv.envoy.home.comm.encharges[0].num} / ${this.pv.envoy.home.comm.encharges[0].level} %`);
4985
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, communication ${enchargeName} and level ${value}`);
4986
- return value;
4987
- });
4988
- }
4989
- if (this.pv.envoy.home.dbSize !== -1 && this.pv.envoy.home.dbPercentFull !== -1) {
4990
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyDbSize)
4991
- .onGet(async () => {
4992
- const value = `${this.pv.envoy.home.dbSize} / ${this.pv.envoy.home.dbPercentFull} %`;
4993
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, data base size: ${value}`);
4994
- return value;
4995
- });
4996
- }
4997
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyTariff)
5048
+ }
5049
+ if (plcLevelSupported) {
5050
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCheckCommLevel)
4998
5051
  .onGet(async () => {
4999
- const value = this.pv.envoy.home.tariff;
5000
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, tariff: ${value}`);
5001
- return value;
5052
+ const state = this.pv.plcLevelState;
5053
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, checking plc level: ${state ? `Yes` : `No`}`);
5054
+ return state;
5055
+ })
5056
+ .onSet(async (state) => {
5057
+ try {
5058
+ const tokenValid = await this.checkJwtToken();
5059
+ const setStatet = tokenValid && state ? await this.updatePlcLevel() : false;
5060
+ const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Envoy: ${envoySerialNumber}, set check plc level: ${setStatet ? `Yes` : `No`}`);
5061
+ } catch (error) {
5062
+ this.emit('warn', `Envoy: ${envoySerialNumber}, set check plc level error: ${error}`);
5063
+ };
5002
5064
  });
5003
- if (this.pv.envoy.home.updateStatus) {
5004
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyUpdateStatus)
5005
- .onGet(async () => {
5006
- const value = this.pv.envoy.home.updateStatus;
5007
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, update status: ${value}`);
5008
- return value;
5009
- });
5010
- }
5011
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyFirmware)
5065
+ }
5066
+ if (gridProfileSupported) {
5067
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyGridProfile)
5012
5068
  .onGet(async () => {
5013
- const value = this.pv.envoy.info.software;
5014
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, firmware: ${value}`);
5069
+ const value = this.pv.gridProfile.name;
5070
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, grid profile: ${value}`);
5015
5071
  return value;
5016
5072
  });
5017
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyTimeZone)
5073
+ }
5074
+ if (enpowersInstalled) {
5075
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyEnpowerGridMode)
5018
5076
  .onGet(async () => {
5019
- const value = this.pv.envoy.home.timeZone;
5020
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, time zone: ${value}`);
5077
+ const value = this.pv.ensemble.enpowers.devices[0].enpwrGridModeTranslated;
5078
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, enpower grid mode: ${value}`);
5021
5079
  return value;
5022
5080
  });
5023
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCurrentDateTime)
5081
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyEnpowerGridState)
5024
5082
  .onGet(async () => {
5025
- const value = `${this.pv.envoy.home.currentDate} ${this.pv.envoy.home.currentTime}`;
5026
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, current date and time: ${value}`);
5027
- return value;
5028
- });
5029
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyLastEnlightenReporDate)
5083
+ const state = this.pv.ensemble.enpowers.devices[0].mainsAdminStateBool;
5084
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, enpower grid state: ${state ? 'Grid ON' : 'Grid OFF'}`);
5085
+ return state;
5086
+ })
5087
+ .onSet(async (state) => {
5088
+ try {
5089
+ const tokenValid = await this.checkJwtToken();
5090
+ const setState = tokenValid ? await this.setEnpowerGridState(state) : false;
5091
+ const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Envoy: ${envoySerialNumber}, set enpower grid state to: ${setState ? `Grid ON` : `Grid OFF`}`);
5092
+ } catch (error) {
5093
+ this.emit('warn', `Set enpower grid state error: ${error}`);
5094
+ };
5095
+ })
5096
+ }
5097
+ if (generatorsInstalled) {
5098
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyGeneratorMode)
5030
5099
  .onGet(async () => {
5031
- const value = this.pv.envoy.home.network.lastEnlightenReporDate;
5032
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, last report to enlighten: ${value}`);
5100
+ const value = this.pv.ensemble.generator.adminMode;
5101
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, generator mode: ${value}`);
5033
5102
  return value;
5034
5103
  });
5035
- if (productionStateSupported) {
5036
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyProductionPowerMode)
5037
- .onGet(async () => {
5038
- const state = this.pv.productionState;
5039
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, production state: ${state ? 'Enabled' : 'Disabled'}`);
5040
- return state;
5041
- })
5042
- .onSet(async (state) => {
5043
- try {
5044
- const tokenValid = await this.checkJwtToken();
5045
- const setState = tokenValid && (state !== this.pv.productionState) ? await this.setProductionState(state) : false;
5046
- const debug = this.enableDebugMode || !tokenValid ? this.emit('debug', `Envoy: ${envoySerialNumber}, set production state: ${setState ? 'Enabled' : 'Disabled'}`) : false;
5047
- } catch (error) {
5048
- this.emit('warn', `Envoy: ${envoySerialNumber}, set production state error: ${error}`);
5049
- };
5050
- });
5051
- }
5052
- if (plcLevelSupported) {
5053
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyCheckCommLevel)
5104
+ envoyService.getCharacteristic(Characteristic.EnphaseEnvoyGeneratorState)
5105
+ .onGet(async () => {
5106
+ const state = this.pv.ensemble.generator.adminModeOnBool || this.pv.ensemble.generator.adminModeAutoBool;
5107
+ const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, generator state: ${state ? 'ON' : 'OFF'}`);
5108
+ return state;
5109
+ })
5110
+ .onSet(async (state) => {
5111
+ try {
5112
+ const genMode = state ? 'on' : 'off';
5113
+ const tokenValid = await this.checkJwtToken();
5114
+ const setState = tokenValid ? await this.setGeneratorMode(genMode) : false;
5115
+ const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Envoy: ${envoySerialNumber}, set generator state to: ${setState ? `ON` : `OFF`}`);
5116
+ } catch (error) {
5117
+ this.emit('warn', `Set generator state error: ${error}`);
5118
+ };
5119
+ })
5120
+ }
5121
+ this.envoyService = envoyService;
5122
+
5123
+ //wireless connektion kit
5124
+ if (wirelessConnectionsInstalled) {
5125
+ this.wirelessConnektionsKitServices = [];
5126
+ for (const wirelessConnection of this.pv.envoy.home.wirelessConnections) {
5127
+ const connectionType = wirelessConnection.type;
5128
+ const debug = this.enableDebugMode ? this.emit('debug', `Prepare Wireless Connection ${connectionType} Service`) : false;
5129
+ const wirelessConnectionKitService = accessory.addService(Service.EnphaseWirelessConnectionKitService, `Wireless connection ${connectionType}`, `wirelessConnectionKitService${connectionType}`);
5130
+ wirelessConnectionKitService.setCharacteristic(Characteristic.ConfiguredName, `Wireless connection ${connectionType}`);
5131
+ wirelessConnectionKitService.getCharacteristic(Characteristic.EnphaseWirelessConnectionKitType)
5054
5132
  .onGet(async () => {
5055
- const state = this.pv.plcLevelState;
5056
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, checking plc level: ${state ? `Yes` : `No`}`);
5057
- return state;
5058
- })
5059
- .onSet(async (state) => {
5060
- try {
5061
- const tokenValid = await this.checkJwtToken();
5062
- const setStatet = tokenValid && state ? await this.updatePlcLevel() : false;
5063
- const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Envoy: ${envoySerialNumber}, set check plc level: ${setStatet ? `Yes` : `No`}`);
5064
- } catch (error) {
5065
- this.emit('warn', `Envoy: ${envoySerialNumber}, set check plc level error: ${error}`);
5066
- };
5133
+ const value = wirelessConnection.type;
5134
+ const info = this.disableLogInfo ? false : this.emit('info', `Wireless connection: ${connectionType}`);
5135
+ return value;
5067
5136
  });
5068
- }
5069
- if (gridProfileSupported) {
5070
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyGridProfile)
5137
+ wirelessConnectionKitService.getCharacteristic(Characteristic.EnphaseWirelessConnectionKitConnected)
5071
5138
  .onGet(async () => {
5072
- const value = this.pv.gridProfile.name;
5073
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, grid profile: ${value}`);
5139
+ const value = wirelessConnection.connected;
5140
+ const info = this.disableLogInfo ? false : this.emit('info', `Wireless connection: ${connectionType}, state: ${value ? 'Connected' : 'Disconnected'}`);
5074
5141
  return value;
5075
5142
  });
5076
- }
5077
- if (enpowersInstalled) {
5078
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyEnpowerGridMode)
5143
+ wirelessConnectionKitService.getCharacteristic(Characteristic.EnphaseWirelessConnectionKitSignalStrength)
5079
5144
  .onGet(async () => {
5080
- const value = this.pv.ensemble.enpowers.devices[0].enpwrGridModeTranslated;
5081
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, enpower grid mode: ${value}`);
5145
+ const value = wirelessConnection.signalStrength;
5146
+ const info = this.disableLogInfo ? false : this.emit('info', `Wireless connection: ${connectionType}, signal strength: ${value} %`);
5082
5147
  return value;
5083
5148
  });
5084
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyEnpowerGridState)
5085
- .onGet(async () => {
5086
- const state = this.pv.ensemble.enpowers.devices[0].mainsAdminStateBool;
5087
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, enpower grid state: ${state ? 'Grid ON' : 'Grid OFF'}`);
5088
- return state;
5089
- })
5090
- .onSet(async (state) => {
5091
- try {
5092
- const tokenValid = await this.checkJwtToken();
5093
- const setState = tokenValid ? await this.setEnpowerGridState(state) : false;
5094
- const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Envoy: ${envoySerialNumber}, set enpower grid state to: ${setState ? `Grid ON` : `Grid OFF`}`);
5095
- } catch (error) {
5096
- this.emit('warn', `Set enpower grid state error: ${error}`);
5097
- };
5098
- })
5099
- }
5100
- if (generatorsInstalled) {
5101
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyGeneratorMode)
5149
+ wirelessConnectionKitService.getCharacteristic(Characteristic.EnphaseWirelessConnectionKitSignalStrengthMax)
5102
5150
  .onGet(async () => {
5103
- const value = this.pv.ensemble.generator.adminMode;
5104
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, generator mode: ${value}`);
5151
+ const value = wirelessConnection.signalStrengthMax;
5152
+ const info = this.disableLogInfo ? false : this.emit('info', `Wireless connection: ${connectionType}, signal strength max: ${value} %`);
5105
5153
  return value;
5106
5154
  });
5107
- envoyService.getCharacteristic(Characteristic.EnphaseEnvoyGeneratorState)
5108
- .onGet(async () => {
5109
- const state = this.pv.ensemble.generator.adminModeOnBool || this.pv.ensemble.generator.adminModeAutoBool;
5110
- const info = this.disableLogInfo ? false : this.emit('info', `Envoy: ${envoySerialNumber}, generator state: ${state ? 'ON' : 'OFF'}`);
5111
- return state;
5112
- })
5113
- .onSet(async (state) => {
5114
- try {
5115
- const genMode = state ? 'on' : 'off';
5116
- const tokenValid = await this.checkJwtToken();
5117
- const setState = tokenValid ? await this.setGeneratorMode(genMode) : false;
5118
- const info = this.disableLogInfo || !tokenValid ? false : this.emit('info', `Envoy: ${envoySerialNumber}, set generator state to: ${setState ? `ON` : `OFF`}`);
5119
- } catch (error) {
5120
- this.emit('warn', `Set generator state error: ${error}`);
5121
- };
5122
- })
5123
- }
5124
- this.envoyService = envoyService;
5125
-
5126
- //wireless connektion kit
5127
- if (wirelessConnectionsInstalled) {
5128
- this.wirelessConnektionsKitServices = [];
5129
- for (const wirelessConnection of this.pv.envoy.home.wirelessConnections) {
5130
- const connectionType = wirelessConnection.type;
5131
- const debug = this.enableDebugMode ? this.emit('debug', `Prepare Wireless Connection ${connectionType} Service`) : false;
5132
- const wirelessConnectionKitService = accessory.addService(Service.EnphaseWirelessConnectionKitService, `Wireless connection ${connectionType}`, `wirelessConnectionKitService${connectionType}`);
5133
- wirelessConnectionKitService.setCharacteristic(Characteristic.ConfiguredName, `Wireless connection ${connectionType}`);
5134
- wirelessConnectionKitService.getCharacteristic(Characteristic.EnphaseWirelessConnectionKitType)
5135
- .onGet(async () => {
5136
- const value = wirelessConnection.type;
5137
- const info = this.disableLogInfo ? false : this.emit('info', `Wireless connection: ${connectionType}`);
5138
- return value;
5139
- });
5140
- wirelessConnectionKitService.getCharacteristic(Characteristic.EnphaseWirelessConnectionKitConnected)
5141
- .onGet(async () => {
5142
- const value = wirelessConnection.connected;
5143
- const info = this.disableLogInfo ? false : this.emit('info', `Wireless connection: ${connectionType}, state: ${value ? 'Connected' : 'Disconnected'}`);
5144
- return value;
5145
- });
5146
- wirelessConnectionKitService.getCharacteristic(Characteristic.EnphaseWirelessConnectionKitSignalStrength)
5147
- .onGet(async () => {
5148
- const value = wirelessConnection.signalStrength;
5149
- const info = this.disableLogInfo ? false : this.emit('info', `Wireless connection: ${connectionType}, signal strength: ${value} %`);
5150
- return value;
5151
- });
5152
- wirelessConnectionKitService.getCharacteristic(Characteristic.EnphaseWirelessConnectionKitSignalStrengthMax)
5153
- .onGet(async () => {
5154
- const value = wirelessConnection.signalStrengthMax;
5155
- const info = this.disableLogInfo ? false : this.emit('info', `Wireless connection: ${connectionType}, signal strength max: ${value} %`);
5156
- return value;
5157
- });
5158
- this.wirelessConnektionsKitServices.push(wirelessConnectionKitService);
5159
- }
5155
+ this.wirelessConnektionsKitServices.push(wirelessConnectionKitService);
5160
5156
  }
5161
5157
  };
5162
5158