iobroker.zendure-solarflow 1.1.14 → 1.1.16

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.
@@ -18,14 +18,59 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var adapterService_exports = {};
20
20
  __export(adapterService_exports, {
21
+ checkVoltage: () => checkVoltage,
21
22
  updateSolarFlowState: () => updateSolarFlowState
22
23
  });
23
24
  module.exports = __toCommonJS(adapterService_exports);
24
25
  const updateSolarFlowState = async (adapter, productKey, deviceKey, state, val) => {
25
- adapter == null ? void 0 : adapter.setStateAsync(productKey + "." + deviceKey + "." + state, val, true);
26
+ adapter == null ? void 0 : adapter.setStateAsync(`${productKey}.${deviceKey}.${state}`, val, true);
27
+ };
28
+ const checkVoltage = async (adapter, productKey, deviceKey, voltage) => {
29
+ if (voltage < 46.1) {
30
+ if (adapter.config.useCalculation) {
31
+ adapter == null ? void 0 : adapter.setStateAsync(
32
+ `${productKey}.${deviceKey}.calculations.soc`,
33
+ 0,
34
+ true
35
+ );
36
+ const energyWhState = await adapter.getStateAsync(
37
+ `${productKey}.${deviceKey}.calculations.energyWh`
38
+ );
39
+ const energyWhMaxState = await adapter.getStateAsync(
40
+ `${productKey}.${deviceKey}.calculations.energyWhMax`
41
+ );
42
+ const newMax = Number(energyWhMaxState == null ? void 0 : energyWhMaxState.val) - Number(energyWhState == null ? void 0 : energyWhState.val);
43
+ adapter == null ? void 0 : adapter.setStateAsync(
44
+ `${productKey}.${deviceKey}.calculations.energyWhMax`,
45
+ newMax,
46
+ true
47
+ );
48
+ adapter == null ? void 0 : adapter.setStateAsync(
49
+ `${productKey}.${deviceKey}.calculations.energyWh`,
50
+ 0,
51
+ true
52
+ );
53
+ }
54
+ if (adapter.config.useLowVoltageBlock) {
55
+ adapter == null ? void 0 : adapter.setStateAsync(
56
+ `${productKey}.${deviceKey}.control.lowVoltageBlock`,
57
+ true,
58
+ true
59
+ );
60
+ }
61
+ } else if (voltage >= 48) {
62
+ if (adapter.config.useLowVoltageBlock) {
63
+ adapter == null ? void 0 : adapter.setStateAsync(
64
+ `${productKey}.${deviceKey}.control.lowVoltageBlock`,
65
+ false,
66
+ true
67
+ );
68
+ }
69
+ }
26
70
  };
27
71
  // Annotate the CommonJS export names for ESM import in node:
28
72
  0 && (module.exports = {
73
+ checkVoltage,
29
74
  updateSolarFlowState
30
75
  });
31
76
  //# sourceMappingURL=adapterService.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/adapterService.ts"],
4
- "sourcesContent": ["import { ZendureSolarflow } from \"../main\";\r\n\r\n/* eslint-disable @typescript-eslint/indent */\r\n\r\nexport const updateSolarFlowState = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string,\r\n state: string,\r\n val: number | string,\r\n): Promise<void> => {\r\n adapter?.setStateAsync(productKey + \".\" + deviceKey + \".\" + state, val, true);\r\n};\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,MAAM,uBAAuB,OAClC,SACA,YACA,WACA,OACA,QACkB;AAClB,qCAAS,cAAc,aAAa,MAAM,YAAY,MAAM,OAAO,KAAK;AAC1E;",
4
+ "sourcesContent": ["import { ZendureSolarflow } from \"../main\";\r\n\r\n/* eslint-disable @typescript-eslint/indent */\r\n\r\nexport const updateSolarFlowState = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string,\r\n state: string,\r\n val: number | string,\r\n): Promise<void> => {\r\n adapter?.setStateAsync(`${productKey}.${deviceKey}.${state}`, val, true);\r\n};\r\n\r\nexport const checkVoltage = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string,\r\n voltage: number,\r\n): Promise<void> => {\r\n if (voltage < 46.1) {\r\n if (adapter.config.useCalculation) {\r\n // Set SOC to 0\r\n adapter?.setStateAsync(\r\n `${productKey}.${deviceKey}.calculations.soc`,\r\n 0,\r\n true,\r\n );\r\n\r\n // Calculate new Wh Max Value\r\n const energyWhState = await adapter.getStateAsync(\r\n `${productKey}.${deviceKey}.calculations.energyWh`,\r\n );\r\n const energyWhMaxState = await adapter.getStateAsync(\r\n `${productKey}.${deviceKey}.calculations.energyWhMax`,\r\n );\r\n\r\n const newMax = Number(energyWhMaxState?.val) - Number(energyWhState?.val);\r\n\r\n // Set Max Energy to value minus current energy\r\n adapter?.setStateAsync(\r\n `${productKey}.${deviceKey}.calculations.energyWhMax`,\r\n newMax,\r\n true,\r\n );\r\n\r\n // Set Energy in Battery to 0\r\n adapter?.setStateAsync(\r\n `${productKey}.${deviceKey}.calculations.energyWh`,\r\n 0,\r\n true,\r\n );\r\n }\r\n\r\n if (adapter.config.useLowVoltageBlock) {\r\n // Activate Low Voltage Block\r\n adapter?.setStateAsync(\r\n `${productKey}.${deviceKey}.control.lowVoltageBlock`,\r\n true,\r\n true,\r\n );\r\n }\r\n } else if (voltage >= 48.0) {\r\n if (adapter.config.useLowVoltageBlock) {\r\n // Deactivate Low Voltage Block\r\n adapter?.setStateAsync(\r\n `${productKey}.${deviceKey}.control.lowVoltageBlock`,\r\n false,\r\n true,\r\n );\r\n }\r\n }\r\n};\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,MAAM,uBAAuB,OAClC,SACA,YACA,WACA,OACA,QACkB;AAClB,qCAAS,cAAc,GAAG,UAAU,IAAI,SAAS,IAAI,KAAK,IAAI,KAAK;AACrE;AAEO,MAAM,eAAe,OAC1B,SACA,YACA,WACA,YACkB;AAClB,MAAI,UAAU,MAAM;AAClB,QAAI,QAAQ,OAAO,gBAAgB;AAEjC,yCAAS;AAAA,QACP,GAAG,UAAU,IAAI,SAAS;AAAA,QAC1B;AAAA,QACA;AAAA;AAIF,YAAM,gBAAgB,MAAM,QAAQ;AAAA,QAClC,GAAG,UAAU,IAAI,SAAS;AAAA,MAC5B;AACA,YAAM,mBAAmB,MAAM,QAAQ;AAAA,QACrC,GAAG,UAAU,IAAI,SAAS;AAAA,MAC5B;AAEA,YAAM,SAAS,OAAO,qDAAkB,GAAG,IAAI,OAAO,+CAAe,GAAG;AAGxE,yCAAS;AAAA,QACP,GAAG,UAAU,IAAI,SAAS;AAAA,QAC1B;AAAA,QACA;AAAA;AAIF,yCAAS;AAAA,QACP,GAAG,UAAU,IAAI,SAAS;AAAA,QAC1B;AAAA,QACA;AAAA;AAAA,IAEJ;AAEA,QAAI,QAAQ,OAAO,oBAAoB;AAErC,yCAAS;AAAA,QACP,GAAG,UAAU,IAAI,SAAS;AAAA,QAC1B;AAAA,QACA;AAAA;AAAA,IAEJ;AAAA,EACF,WAAW,WAAW,IAAM;AAC1B,QAAI,QAAQ,OAAO,oBAAoB;AAErC,yCAAS;AAAA,QACP,GAAG,UAAU,IAAI,SAAS;AAAA,QAC1B;AAAA,QACA;AAAA;AAAA,IAEJ;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -23,6 +23,12 @@ __export(calculationService_exports, {
23
23
  resetTodaysValues: () => resetTodaysValues
24
24
  });
25
25
  module.exports = __toCommonJS(calculationService_exports);
26
+ const calculationStateKeys = [
27
+ "packInput",
28
+ "outputHome",
29
+ "outputPack",
30
+ "solarInput"
31
+ ];
26
32
  const calculateSocAndEnergy = async (adapter, productKey, deviceKey, stateKey, value) => {
27
33
  const currentEnergyState = await (adapter == null ? void 0 : adapter.getStateAsync(
28
34
  productKey + "." + deviceKey + ".calculations.energyWh"
@@ -30,23 +36,24 @@ const calculateSocAndEnergy = async (adapter, productKey, deviceKey, stateKey, v
30
36
  const currentEnergyMaxState = await (adapter == null ? void 0 : adapter.getStateAsync(
31
37
  productKey + "." + deviceKey + ".calculations.energyWhMax"
32
38
  ));
33
- const newValue = stateKey == "outputPack" ? Number(currentEnergyState == null ? void 0 : currentEnergyState.val) + value : Number(currentEnergyState == null ? void 0 : currentEnergyState.val) - value;
39
+ const currentValue = (currentEnergyState == null ? void 0 : currentEnergyState.val) ? Number(currentEnergyState == null ? void 0 : currentEnergyState.val) : 0;
40
+ const newValue = stateKey == "outputPack" ? currentValue + value : currentValue - value;
34
41
  if (newValue > 0) {
35
42
  adapter == null ? void 0 : adapter.setStateAsync(
36
- productKey + "." + deviceKey + ".calculations.energyWh",
43
+ `${productKey}.${deviceKey}.calculations.energyWh`,
37
44
  newValue,
38
45
  true
39
46
  );
40
47
  if (currentEnergyMaxState) {
41
48
  const soc = newValue / Number(currentEnergyMaxState.val) * 100;
42
49
  adapter == null ? void 0 : adapter.setStateAsync(
43
- productKey + "." + deviceKey + ".calculations.soc",
50
+ `${productKey}.${deviceKey}.calculations.soc`,
44
51
  soc,
45
52
  true
46
53
  );
47
54
  if (newValue > Number(currentEnergyMaxState.val)) {
48
55
  adapter == null ? void 0 : adapter.setStateAsync(
49
- productKey + "." + deviceKey + ".calculations.energyWhMax",
56
+ `${productKey}.${deviceKey}.calculations.energyWhMax`,
50
57
  newValue,
51
58
  true
52
59
  );
@@ -54,38 +61,47 @@ const calculateSocAndEnergy = async (adapter, productKey, deviceKey, stateKey, v
54
61
  }
55
62
  }
56
63
  };
57
- const calculateEnergy = async (adapter, productKey, deviceKey, stateKey, state) => {
58
- const stateNameWh = productKey + "." + deviceKey + ".calculations." + stateKey + "EnergyTodayWh";
59
- const stateNamekWh = productKey + "." + deviceKey + ".calculations." + stateKey + "EnergyTodaykWh";
60
- const currentState = await (adapter == null ? void 0 : adapter.getStateAsync(stateNameWh));
61
- if ((currentState == null ? void 0 : currentState.val) == 0) {
62
- adapter == null ? void 0 : adapter.setStateAsync(stateNameWh, 1e-6, true);
63
- } else if (currentState && currentState.lc && state.val != void 0 && state.val != null) {
64
- const timeFrame = state.lc - (currentState == null ? void 0 : currentState.lc);
65
- const addValue = Number(state.val) * timeFrame / 36e5;
66
- const newValue = Number(currentState.val) + addValue;
67
- adapter == null ? void 0 : adapter.setStateAsync(stateNameWh, newValue, true);
68
- adapter == null ? void 0 : adapter.setStateAsync(
69
- stateNamekWh,
70
- Number((newValue / 1e3).toFixed(2)),
71
- true
72
- );
73
- if (stateKey == "outputPack" || stateKey == "packInput") {
74
- calculateSocAndEnergy(adapter, productKey, deviceKey, stateKey, addValue);
64
+ const calculateEnergy = async (adapter, productKey, deviceKey) => {
65
+ calculationStateKeys.forEach(async (stateKey) => {
66
+ const stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodayWh`;
67
+ const stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodaykWh`;
68
+ const stateNamePower = `${productKey}.${deviceKey}.${stateKey}Power`;
69
+ const currentPowerState = await (adapter == null ? void 0 : adapter.getStateAsync(stateNamePower));
70
+ const currentEnergyState = await (adapter == null ? void 0 : adapter.getStateAsync(stateNameEnergyWh));
71
+ if ((currentEnergyState == null ? void 0 : currentEnergyState.val) == 0) {
72
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameEnergyWh, 1e-6, true);
73
+ } else if (currentEnergyState && currentEnergyState.lc && currentPowerState && currentPowerState.val != void 0 && currentPowerState.val != null) {
74
+ const timeFrame = currentPowerState.lc - (currentEnergyState == null ? void 0 : currentEnergyState.lc);
75
+ const addValue = Number(currentPowerState.val) * timeFrame / 36e5;
76
+ const newValue = Number(currentEnergyState.val) + addValue;
77
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameEnergyWh, newValue, true);
78
+ adapter == null ? void 0 : adapter.setStateAsync(
79
+ stateNameEnergykWh,
80
+ Number((newValue / 1e3).toFixed(2)),
81
+ true
82
+ );
83
+ if (stateKey == "outputPack" || stateKey == "packInput") {
84
+ calculateSocAndEnergy(
85
+ adapter,
86
+ productKey,
87
+ deviceKey,
88
+ stateKey,
89
+ addValue
90
+ );
91
+ }
92
+ } else {
93
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameEnergyWh, 0, true);
94
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameEnergykWh, 0, true);
75
95
  }
76
- } else {
77
- adapter == null ? void 0 : adapter.setStateAsync(stateNameWh, 0, true);
78
- adapter == null ? void 0 : adapter.setStateAsync(stateNamekWh, 0, true);
79
- }
96
+ });
80
97
  };
81
98
  const resetTodaysValues = async (adapter) => {
82
99
  adapter.deviceList.forEach((device) => {
83
- const names = ["packInput", "outputHome", "outputPack", "solarInput"];
84
- names.forEach((name) => {
85
- const stateNameWh = device.productKey + "." + device.deviceKey + ".calculations." + name + "EnergyTodayWh";
86
- const stateNamekWh = device.productKey + "." + device.deviceKey + ".calculations." + name + "EnergyTodaykWh";
87
- adapter == null ? void 0 : adapter.setStateAsync(stateNameWh, 0, true);
88
- adapter == null ? void 0 : adapter.setStateAsync(stateNamekWh, 0, true);
100
+ calculationStateKeys.forEach((stateKey) => {
101
+ const stateNameEnergyWh = `${device.productKey}.${device.deviceKey}.calculations.${stateKey}EnergyTodayWh`;
102
+ const stateNameEnergykWh = `${device.productKey}.${device.deviceKey}.calculations.${stateKey}EnergyTodaykWh`;
103
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameEnergyWh, 0, true);
104
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameEnergykWh, 0, true);
89
105
  });
90
106
  });
91
107
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/calculationService.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/indent */\r\n\r\nimport { ZendureSolarflow } from \"../main\";\r\nimport { ISolarFlowDeviceDetails } from \"../models/ISolarFlowDeviceDetails\";\r\n\r\nexport const calculateSocAndEnergy = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string,\r\n stateKey: string,\r\n value: number,\r\n): Promise<void> => {\r\n const currentEnergyState = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.energyWh\",\r\n );\r\n\r\n const currentEnergyMaxState = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.energyWhMax\",\r\n );\r\n\r\n const newValue =\r\n stateKey == \"outputPack\"\r\n ? Number(currentEnergyState?.val) + value\r\n : Number(currentEnergyState?.val) - value;\r\n\r\n if (newValue > 0) {\r\n adapter?.setStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.energyWh\",\r\n newValue,\r\n true,\r\n );\r\n\r\n if (currentEnergyMaxState) {\r\n const soc = (newValue / Number(currentEnergyMaxState.val)) * 100;\r\n adapter?.setStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.soc\",\r\n soc,\r\n true,\r\n );\r\n\r\n if (newValue > Number(currentEnergyMaxState.val)) {\r\n // Extend maxVal\r\n adapter?.setStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.energyWhMax\",\r\n newValue,\r\n true,\r\n );\r\n }\r\n }\r\n }\r\n};\r\n\r\nexport const calculateEnergy = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string,\r\n stateKey: string, // e.g. packInput, outputHome, outputPack, solarInput\r\n state: ioBroker.State,\r\n): Promise<void> => {\r\n const stateNameWh =\r\n productKey +\r\n \".\" +\r\n deviceKey +\r\n \".calculations.\" +\r\n stateKey +\r\n \"EnergyTodayWh\";\r\n\r\n const stateNamekWh =\r\n productKey +\r\n \".\" +\r\n deviceKey +\r\n \".calculations.\" +\r\n stateKey +\r\n \"EnergyTodaykWh\";\r\n const currentState = await adapter?.getStateAsync(stateNameWh);\r\n\r\n if (currentState?.val == 0) {\r\n // Workaround, set Val to very low value to avoid Jump in data...\r\n adapter?.setStateAsync(stateNameWh, 0.000001, true);\r\n } else if (\r\n currentState &&\r\n currentState.lc &&\r\n state.val != undefined &&\r\n state.val != null\r\n ) {\r\n const timeFrame = state.lc - currentState?.lc;\r\n\r\n const addValue = (Number(state.val) * timeFrame) / 3600000; // Wh\r\n const newValue = Number(currentState.val) + addValue;\r\n\r\n adapter?.setStateAsync(stateNameWh, newValue, true);\r\n adapter?.setStateAsync(\r\n stateNamekWh,\r\n Number((newValue / 1000).toFixed(2)),\r\n true,\r\n );\r\n\r\n // SOC and energy in batteries\r\n if (stateKey == \"outputPack\" || stateKey == \"packInput\") {\r\n calculateSocAndEnergy(adapter, productKey, deviceKey, stateKey, addValue);\r\n }\r\n } else {\r\n adapter?.setStateAsync(stateNameWh, 0, true);\r\n adapter?.setStateAsync(stateNamekWh, 0, true);\r\n }\r\n};\r\n\r\nexport const resetTodaysValues = async (\r\n adapter: ZendureSolarflow,\r\n): Promise<void> => {\r\n adapter.deviceList.forEach((device: ISolarFlowDeviceDetails) => {\r\n const names = [\"packInput\", \"outputHome\", \"outputPack\", \"solarInput\"];\r\n\r\n names.forEach((name: string) => {\r\n const stateNameWh =\r\n device.productKey +\r\n \".\" +\r\n device.deviceKey +\r\n \".calculations.\" +\r\n name +\r\n \"EnergyTodayWh\";\r\n const stateNamekWh =\r\n device.productKey +\r\n \".\" +\r\n device.deviceKey +\r\n \".calculations.\" +\r\n name +\r\n \"EnergyTodaykWh\";\r\n\r\n adapter?.setStateAsync(stateNameWh, 0, true);\r\n adapter?.setStateAsync(stateNamekWh, 0, true);\r\n });\r\n });\r\n};\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,wBAAwB,OACnC,SACA,YACA,WACA,UACA,UACkB;AAClB,QAAM,qBAAqB,OAAM,mCAAS;AAAA,IACxC,aAAa,MAAM,YAAY;AAAA;AAGjC,QAAM,wBAAwB,OAAM,mCAAS;AAAA,IAC3C,aAAa,MAAM,YAAY;AAAA;AAGjC,QAAM,WACJ,YAAY,eACR,OAAO,yDAAoB,GAAG,IAAI,QAClC,OAAO,yDAAoB,GAAG,IAAI;AAExC,MAAI,WAAW,GAAG;AAChB,uCAAS;AAAA,MACP,aAAa,MAAM,YAAY;AAAA,MAC/B;AAAA,MACA;AAAA;AAGF,QAAI,uBAAuB;AACzB,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mBACA,OACA;AACF,YAAM,eACJ,OAAO,aACP,MACA,OAAO,YACP,mBACA,OACA;AAEF,yCAAS,cAAc,aAAa,GAAG;AACvC,yCAAS,cAAc,cAAc,GAAG;AAAA,IAC1C,CAAC;AAAA,EACH,CAAC;AACH;",
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/indent */\r\n\r\nimport { ZendureSolarflow } from \"../main\";\r\nimport { ISolarFlowDeviceDetails } from \"../models/ISolarFlowDeviceDetails\";\r\n\r\nconst calculationStateKeys = [\r\n \"packInput\",\r\n \"outputHome\",\r\n \"outputPack\",\r\n \"solarInput\",\r\n];\r\n\r\nexport const calculateSocAndEnergy = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string,\r\n stateKey: string,\r\n value: number,\r\n): Promise<void> => {\r\n const currentEnergyState = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.energyWh\",\r\n );\r\n\r\n const currentEnergyMaxState = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.energyWhMax\",\r\n );\r\n\r\n const currentValue = currentEnergyState?.val\r\n ? Number(currentEnergyState?.val)\r\n : 0;\r\n\r\n const newValue =\r\n stateKey == \"outputPack\" ? currentValue + value : currentValue - value;\r\n\r\n if (newValue > 0) {\r\n adapter?.setStateAsync(\r\n `${productKey}.${deviceKey}.calculations.energyWh`,\r\n newValue,\r\n true,\r\n );\r\n\r\n if (currentEnergyMaxState) {\r\n const soc = (newValue / Number(currentEnergyMaxState.val)) * 100;\r\n adapter?.setStateAsync(\r\n `${productKey}.${deviceKey}.calculations.soc`,\r\n soc,\r\n true,\r\n );\r\n\r\n if (newValue > Number(currentEnergyMaxState.val)) {\r\n // Extend maxVal\r\n adapter?.setStateAsync(\r\n `${productKey}.${deviceKey}.calculations.energyWhMax`,\r\n newValue,\r\n true,\r\n );\r\n }\r\n }\r\n }\r\n};\r\n\r\nexport const calculateEnergy = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string,\r\n): Promise<void> => {\r\n calculationStateKeys.forEach(async (stateKey) => {\r\n const stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodayWh`;\r\n const stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodaykWh`;\r\n const stateNamePower = `${productKey}.${deviceKey}.${stateKey}Power`;\r\n\r\n const currentPowerState = await adapter?.getStateAsync(stateNamePower);\r\n const currentEnergyState = await adapter?.getStateAsync(stateNameEnergyWh);\r\n\r\n if (currentEnergyState?.val == 0) {\r\n // Workaround, set Val to very low value to avoid Jump in data...\r\n adapter?.setStateAsync(stateNameEnergyWh, 0.000001, true);\r\n } else if (\r\n currentEnergyState &&\r\n currentEnergyState.lc &&\r\n currentPowerState &&\r\n currentPowerState.val != undefined &&\r\n currentPowerState.val != null\r\n ) {\r\n const timeFrame = currentPowerState.lc - currentEnergyState?.lc;\r\n\r\n const addValue = (Number(currentPowerState.val) * timeFrame) / 3600000; // Wh\r\n const newValue = Number(currentEnergyState.val) + addValue;\r\n\r\n adapter?.setStateAsync(stateNameEnergyWh, newValue, true);\r\n adapter?.setStateAsync(\r\n stateNameEnergykWh,\r\n Number((newValue / 1000).toFixed(2)),\r\n true,\r\n );\r\n\r\n // SOC and energy in batteries\r\n if (stateKey == \"outputPack\" || stateKey == \"packInput\") {\r\n calculateSocAndEnergy(\r\n adapter,\r\n productKey,\r\n deviceKey,\r\n stateKey,\r\n addValue,\r\n );\r\n }\r\n } else {\r\n adapter?.setStateAsync(stateNameEnergyWh, 0, true);\r\n adapter?.setStateAsync(stateNameEnergykWh, 0, true);\r\n }\r\n });\r\n};\r\n\r\nexport const resetTodaysValues = async (\r\n adapter: ZendureSolarflow,\r\n): Promise<void> => {\r\n adapter.deviceList.forEach((device: ISolarFlowDeviceDetails) => {\r\n calculationStateKeys.forEach((stateKey: string) => {\r\n const stateNameEnergyWh = `${device.productKey}.${device.deviceKey}.calculations.${stateKey}EnergyTodayWh`;\r\n const stateNameEnergykWh = `${device.productKey}.${device.deviceKey}.calculations.${stateKey}EnergyTodaykWh`;\r\n\r\n adapter?.setStateAsync(stateNameEnergyWh, 0, true);\r\n adapter?.setStateAsync(stateNameEnergykWh, 0, true);\r\n });\r\n });\r\n};\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,MAAM,uBAAuB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,wBAAwB,OACnC,SACA,YACA,WACA,UACA,UACkB;AAClB,QAAM,qBAAqB,OAAM,mCAAS;AAAA,IACxC,aAAa,MAAM,YAAY;AAAA;AAGjC,QAAM,wBAAwB,OAAM,mCAAS;AAAA,IAC3C,aAAa,MAAM,YAAY;AAAA;AAGjC,QAAM,gBAAe,yDAAoB,OACrC,OAAO,yDAAoB,GAAG,IAC9B;AAEJ,QAAM,WACJ,YAAY,eAAe,eAAe,QAAQ,eAAe;AAEnE,MAAI,WAAW,GAAG;AAChB,uCAAS;AAAA,MACP,GAAG,UAAU,IAAI,SAAS;AAAA,MAC1B;AAAA,MACA;AAAA;AAGF,QAAI,uBAAuB;AACzB,YAAM,MAAO,WAAW,OAAO,sBAAsB,GAAG,IAAK;AAC7D,yCAAS;AAAA,QACP,GAAG,UAAU,IAAI,SAAS;AAAA,QAC1B;AAAA,QACA;AAAA;AAGF,UAAI,WAAW,OAAO,sBAAsB,GAAG,GAAG;AAEhD,2CAAS;AAAA,UACP,GAAG,UAAU,IAAI,SAAS;AAAA,UAC1B;AAAA,UACA;AAAA;AAAA,MAEJ;AAAA,IACF;AAAA,EACF;AACF;AAEO,MAAM,kBAAkB,OAC7B,SACA,YACA,cACkB;AAClB,uBAAqB,QAAQ,OAAO,aAAa;AAC/C,UAAM,oBAAoB,GAAG,UAAU,IAAI,SAAS,iBAAiB,QAAQ;AAC7E,UAAM,qBAAqB,GAAG,UAAU,IAAI,SAA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, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var jobSchedule_exports = {};
20
20
  __export(jobSchedule_exports, {
21
+ startCalculationJob: () => startCalculationJob,
21
22
  startCheckStatesJob: () => startCheckStatesJob,
22
23
  startReloginAndResetValuesJob: () => startReloginAndResetValuesJob
23
24
  });
@@ -29,7 +30,11 @@ var import_calculationService = require("./calculationService");
29
30
  const startReloginAndResetValuesJob = async (adapter) => {
30
31
  adapter.resetValuesJob = (0, import_node_schedule.scheduleJob)("0 0 * * *", () => {
31
32
  var _a;
32
- adapter.log.debug(`Refreshing accessToken!`);
33
+ adapter.log.info(`[startReloginAndResetValuesJob] Refreshing accessToken!`);
34
+ if (adapter.mqttClient) {
35
+ adapter.mqttClient.end();
36
+ adapter.mqttClient = void 0;
37
+ }
33
38
  if (adapter.config.userName && adapter.config.password) {
34
39
  (_a = (0, import_webService.login)(adapter)) == null ? void 0 : _a.then((_accessToken) => {
35
40
  adapter.accessToken = _accessToken;
@@ -41,6 +46,13 @@ const startReloginAndResetValuesJob = async (adapter) => {
41
46
  (0, import_calculationService.resetTodaysValues)(adapter);
42
47
  });
43
48
  };
49
+ const startCalculationJob = async (adapter) => {
50
+ adapter.calculationJob = (0, import_node_schedule.scheduleJob)("*/10 * * * * *", () => {
51
+ adapter.deviceList.forEach((device) => {
52
+ (0, import_calculationService.calculateEnergy)(adapter, device.productKey, device.deviceKey);
53
+ });
54
+ });
55
+ };
44
56
  const startCheckStatesJob = async (adapter) => {
45
57
  const statesToReset = [
46
58
  "outputHomePower",
@@ -57,7 +69,7 @@ const startCheckStatesJob = async (adapter) => {
57
69
  const tenMinutesAgo = Date.now() / 1e3 - 10 * 60;
58
70
  if (lastUpdate && lastUpdate.val && Number(lastUpdate.val) < tenMinutesAgo) {
59
71
  adapter.log.debug(
60
- `Last update for deviceKey ${device.deviceKey} was at ${new Date(
72
+ `[checkStatesJob] Last update for deviceKey ${device.deviceKey} was at ${new Date(
61
73
  Number(lastUpdate)
62
74
  )}, checking for pseudo power values!`
63
75
  );
@@ -68,22 +80,26 @@ const startCheckStatesJob = async (adapter) => {
68
80
  true
69
81
  ));
70
82
  });
71
- await (adapter == null ? void 0 : adapter.setStateAsync(
72
- device.productKey + "." + device.deviceKey + ".electricLevel",
73
- device.electricity,
74
- true
75
- ));
83
+ if (device.electricity) {
84
+ await (adapter == null ? void 0 : adapter.setStateAsync(
85
+ device.productKey + "." + device.deviceKey + ".electricLevel",
86
+ device.electricity,
87
+ true
88
+ ));
89
+ }
76
90
  }
77
91
  });
78
92
  }).catch(() => {
79
93
  var _a;
80
- (_a = adapter.log) == null ? void 0 : _a.error("Retrieving device failed!");
81
- return null;
94
+ (_a = adapter.log) == null ? void 0 : _a.error(
95
+ "[checkStatesJob] Retrieving device failedRetrieving device failed!"
96
+ );
82
97
  });
83
98
  });
84
99
  };
85
100
  // Annotate the CommonJS export names for ESM import in node:
86
101
  0 && (module.exports = {
102
+ startCalculationJob,
87
103
  startCheckStatesJob,
88
104
  startReloginAndResetValuesJob
89
105
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/services/jobSchedule.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/indent */\r\nimport { scheduleJob } from \"node-schedule\";\r\nimport { ZendureSolarflow } from \"../main\";\r\nimport { connectMqttClient } from \"./mqttService\";\r\nimport { getDeviceList, login } from \"./webService\";\r\nimport { ISolarFlowDeviceDetails } from \"../models/ISolarFlowDeviceDetails\";\r\nimport { resetTodaysValues } from \"./calculationService\";\r\n\r\nexport const startReloginAndResetValuesJob = async (\r\n adapter: ZendureSolarflow,\r\n): Promise<void> => {\r\n adapter.resetValuesJob = scheduleJob(\"0 0 * * *\", () => {\r\n // Relogin at night to get a fresh accessToken!\r\n adapter.log.debug(`Refreshing accessToken!`);\r\n\r\n if (adapter.config.userName && adapter.config.password) {\r\n login(adapter)?.then((_accessToken: string) => {\r\n adapter.accessToken = _accessToken;\r\n adapter.lastLogin = new Date();\r\n adapter.connected = true;\r\n\r\n connectMqttClient(adapter);\r\n });\r\n }\r\n\r\n // Reset Values\r\n resetTodaysValues(adapter);\r\n });\r\n};\r\n\r\nexport const startCheckStatesJob = async (\r\n adapter: ZendureSolarflow,\r\n): Promise<void> => {\r\n // Check for states that has no updates in the last 5 minutes and set them to 0\r\n const statesToReset: string[] = [\r\n \"outputHomePower\",\r\n \"outputPackPower\",\r\n \"packInputPower\",\r\n \"solarInputPower\",\r\n ];\r\n\r\n adapter.checkStatesJob = scheduleJob(\"*/10 * * * *\", async () => {\r\n getDeviceList(adapter)\r\n .then((deviceList: ISolarFlowDeviceDetails[]) => {\r\n deviceList.forEach(async (device: ISolarFlowDeviceDetails) => {\r\n const lastUpdate = await adapter?.getStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".lastUpdate\",\r\n );\r\n\r\n const tenMinutesAgo = Date.now() / 1000 - 10 * 60; // Ten minutes ago\r\n\r\n if (\r\n lastUpdate &&\r\n lastUpdate.val &&\r\n Number(lastUpdate.val) < tenMinutesAgo\r\n ) {\r\n adapter.log.debug(\r\n `Last update for deviceKey ${device.deviceKey} was at ${new Date(\r\n Number(lastUpdate),\r\n )}, checking for pseudo power values!`,\r\n );\r\n // State was not updated in the last 10 minutes... set states to 0\r\n await statesToReset.forEach(async (stateName: string) => {\r\n await adapter?.setStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".\" + stateName,\r\n 0,\r\n true,\r\n );\r\n });\r\n\r\n // set electricLevel from deviceList\r\n await adapter?.setStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".electricLevel\",\r\n device.electricity,\r\n true,\r\n );\r\n }\r\n });\r\n })\r\n .catch(() => {\r\n adapter.log?.error(\"Retrieving device failed!\");\r\n return null;\r\n });\r\n });\r\n};\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAA4B;AAE5B,y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AAAA,MACF,CAAC;AAAA,IACH,CAAC,EACA,MAAM,MAAM;AA/EnB;AAgFQ,oBAAQ,QAAR,mBAAa,MAAM;AACnB,aAAO;AAAA,IACT,CAAC;AAAA,EACL,CAAC;AACH;",
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/indent */\r\nimport { scheduleJob } from \"node-schedule\";\r\nimport { ZendureSolarflow } from \"../main\";\r\nimport { connectMqttClient } from \"./mqttService\";\r\nimport { getDeviceList, login } from \"./webService\";\r\nimport { ISolarFlowDeviceDetails } from \"../models/ISolarFlowDeviceDetails\";\r\nimport { calculateEnergy, resetTodaysValues } from \"./calculationService\";\r\n\r\nexport const startReloginAndResetValuesJob = async (\r\n adapter: ZendureSolarflow,\r\n): Promise<void> => {\r\n adapter.resetValuesJob = scheduleJob(\"0 0 * * *\", () => {\r\n // Relogin at night to get a fresh accessToken!\r\n adapter.log.info(`[startReloginAndResetValuesJob] Refreshing accessToken!`);\r\n\r\n if (adapter.mqttClient) {\r\n adapter.mqttClient.end();\r\n adapter.mqttClient = undefined;\r\n }\r\n\r\n if (adapter.config.userName && adapter.config.password) {\r\n login(adapter)?.then((_accessToken: string) => {\r\n adapter.accessToken = _accessToken;\r\n adapter.lastLogin = new Date();\r\n adapter.connected = true;\r\n\r\n connectMqttClient(adapter);\r\n });\r\n }\r\n\r\n // Reset Values\r\n resetTodaysValues(adapter);\r\n });\r\n};\r\n\r\nexport const startCalculationJob = async (\r\n adapter: ZendureSolarflow,\r\n): Promise<void> => {\r\n adapter.calculationJob = scheduleJob(\"*/10 * * * * *\", () => {\r\n adapter.deviceList.forEach((device) => {\r\n calculateEnergy(adapter, device.productKey, device.deviceKey);\r\n });\r\n });\r\n};\r\n\r\nexport const startCheckStatesJob = async (\r\n adapter: ZendureSolarflow,\r\n): Promise<void> => {\r\n // Check for states that has no updates in the last 5 minutes and set them to 0\r\n const statesToReset: string[] = [\r\n \"outputHomePower\",\r\n \"outputPackPower\",\r\n \"packInputPower\",\r\n \"solarInputPower\",\r\n ];\r\n\r\n adapter.checkStatesJob = scheduleJob(\"*/10 * * * *\", async () => {\r\n getDeviceList(adapter)\r\n .then((deviceList: ISolarFlowDeviceDetails[]) => {\r\n deviceList.forEach(async (device: ISolarFlowDeviceDetails) => {\r\n const lastUpdate = await adapter?.getStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".lastUpdate\",\r\n );\r\n\r\n const tenMinutesAgo = Date.now() / 1000 - 10 * 60; // Ten minutes ago\r\n\r\n if (\r\n lastUpdate &&\r\n lastUpdate.val &&\r\n Number(lastUpdate.val) < tenMinutesAgo\r\n ) {\r\n adapter.log.debug(\r\n `[checkStatesJob] Last update for deviceKey ${\r\n device.deviceKey\r\n } was at ${new Date(\r\n Number(lastUpdate),\r\n )}, checking for pseudo power values!`,\r\n );\r\n // State was not updated in the last 10 minutes... set states to 0\r\n await statesToReset.forEach(async (stateName: string) => {\r\n await adapter?.setStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".\" + stateName,\r\n 0,\r\n true,\r\n );\r\n });\r\n\r\n // set electricLevel from deviceList\r\n if (device.electricity) {\r\n await adapter?.setStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".electricLevel\",\r\n device.electricity,\r\n true,\r\n );\r\n }\r\n }\r\n });\r\n })\r\n .catch(() => {\r\n adapter.log?.error(\r\n \"[checkStatesJob] Retrieving device failedRetrieving device failed!\",\r\n );\r\n });\r\n });\r\n};\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAA4B;AAE5B,yBAAkC;AAClC,wBAAqC;AAErC,gCAAmD;AAE5C,MAAM,gCAAgC,OAC3C,YACkB;AAClB,UAAQ,qBAAiB,kCAAY,aAAa,MAAM;AAX1D;AAaI,YAAQ,IAAI,KAAK,yDAAyD;AAE1E,QAAI,QAAQ,YAAY;AACtB,cAAQ,WAAW,IAAI;AACvB,cAAQ,aAAa;AAAA,IACvB;AAE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OAAO,YAAY;AAAA,cAC7C,OAAO;AAAA,cACP;AAAA;AAAA,UAEJ;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,CAAC,EACA,MAAM,MAAM;AAlGnB;AAmGQ,oBAAQ,QAAR,mBAAa;AAAA,QACX;AAAA;AAAA,IAEJ,CAAC;AAAA,EACL,CAAC;AACH;",
6
6
  "names": []
7
7
  }
@@ -39,10 +39,9 @@ var mqtt = __toESM(require("mqtt"));
39
39
  var import_adapterService = require("./adapterService");
40
40
  var import_timeHelper = require("../helpers/timeHelper");
41
41
  var import_createSolarFlowStates = require("../helpers/createSolarFlowStates");
42
- let client = void 0;
43
42
  let adapter = void 0;
44
43
  const onConnected = () => {
45
- adapter == null ? void 0 : adapter.log.info("Connected with MQTT!");
44
+ adapter == null ? void 0 : adapter.log.info("[onConnected] Connected with MQTT!");
46
45
  };
47
46
  const onError = (error) => {
48
47
  adapter == null ? void 0 : adapter.log.error("Connection to MQTT failed! Error: " + error);
@@ -160,7 +159,9 @@ const addOrUpdatePackData = async (adapter2, productKey, deviceKey, packData) =>
160
159
  },
161
160
  native: {}
162
161
  }));
163
- await (adapter2 == null ? void 0 : adapter2.setStateAsync(key + ".totalVol", x.totalVol / 100, true));
162
+ const totalVol = x.totalVol / 100;
163
+ await (adapter2 == null ? void 0 : adapter2.setStateAsync(key + ".totalVol", totalVol, true));
164
+ (0, import_adapterService.checkVoltage)(adapter2, productKey, deviceKey, totalVol);
164
165
  }
165
166
  }
166
167
  });
@@ -353,40 +354,54 @@ const onMessage = async (topic, message) => {
353
354
  addOrUpdatePackData(adapter, productKey, deviceKey, obj.packData);
354
355
  }
355
356
  }
356
- if (client) {
357
+ if (adapter == null ? void 0 : adapter.mqttClient) {
357
358
  }
358
359
  };
359
360
  const setChargeLimit = async (adapter2, productKey, deviceKey, socSet) => {
360
- if (client && productKey && deviceKey) {
361
+ var _a;
362
+ if (adapter2.mqttClient && productKey && deviceKey) {
361
363
  if (socSet > 40 && socSet <= 100) {
362
364
  const topic = `iot/${productKey}/${deviceKey}/properties/write`;
363
365
  const socSetLimit = { properties: { socSet: socSet * 10 } };
364
366
  adapter2.log.debug(
365
- `Setting ChargeLimit for device key ${deviceKey} to ${socSet}!`
367
+ `[setChargeLimit] Setting ChargeLimit for device key ${deviceKey} to ${socSet}!`
366
368
  );
367
- client == null ? void 0 : client.publish(topic, JSON.stringify(socSetLimit));
369
+ (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(socSetLimit));
368
370
  } else {
369
- adapter2.log.debug(`Charge limit is not in range 40<>100!`);
371
+ adapter2.log.debug(
372
+ `[setChargeLimit] Charge limit is not in range 40<>100!`
373
+ );
370
374
  }
371
375
  }
372
376
  };
373
377
  const setDischargeLimit = async (adapter2, productKey, deviceKey, minSoc) => {
374
- if (client && productKey && deviceKey) {
378
+ var _a;
379
+ if (adapter2.mqttClient && productKey && deviceKey) {
375
380
  if (minSoc > 0 && minSoc < 90) {
376
381
  const topic = `iot/${productKey}/${deviceKey}/properties/write`;
377
382
  const socSetLimit = { properties: { minSoc: minSoc * 10 } };
378
383
  adapter2.log.debug(
379
- `Setting Discharge Limit for device key ${deviceKey} to ${minSoc}!`
384
+ `[setDischargeLimit] Setting Discharge Limit for device key ${deviceKey} to ${minSoc}!`
380
385
  );
381
- client == null ? void 0 : client.publish(topic, JSON.stringify(socSetLimit));
386
+ (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(socSetLimit));
382
387
  } else {
383
- adapter2.log.debug(`Discharge limit is not in range 0<>90!`);
388
+ adapter2.log.debug(
389
+ `[setDischargeLimit] Discharge limit is not in range 0<>90!`
390
+ );
384
391
  }
385
392
  }
386
393
  };
387
394
  const setOutputLimit = async (adapter2, productKey, deviceKey, limit) => {
388
- var _a;
389
- if (client && productKey && deviceKey) {
395
+ var _a, _b;
396
+ if (adapter2.mqttClient && productKey && deviceKey) {
397
+ if (adapter2.config.useLowVoltageBlock) {
398
+ const lowVoltageBlockState = await adapter2.getStateAsync(
399
+ productKey + "." + deviceKey + ".control.lowVoltageBlock"
400
+ );
401
+ if (lowVoltageBlockState && lowVoltageBlockState.val && lowVoltageBlockState.val == true) {
402
+ limit = 0;
403
+ }
404
+ }
390
405
  const currentLimit = (_a = await adapter2.getStateAsync(productKey + "." + deviceKey + ".outputLimit")) == null ? void 0 : _a.val;
391
406
  if (currentLimit != null && currentLimit != void 0) {
392
407
  if (currentLimit != limit) {
@@ -404,12 +419,12 @@ const setOutputLimit = async (adapter2, productKey, deviceKey, limit) => {
404
419
  const topic = `iot/${productKey}/${deviceKey}/properties/write`;
405
420
  const outputlimit = { properties: { outputLimit: limit } };
406
421
  adapter2.log.debug(
407
- `Setting Output Limit for device key ${deviceKey} to ${limit}!`
422
+ `[setOutputLimit] Setting Output Limit for device key ${deviceKey} to ${limit}!`
408
423
  );
409
- client == null ? void 0 : client.publish(topic, JSON.stringify(outputlimit));
424
+ (_b = adapter2.mqttClient) == null ? void 0 : _b.publish(topic, JSON.stringify(outputlimit));
410
425
  } else {
411
426
  adapter2.log.debug(
412
- `Output Limit for device key ${deviceKey} is already at ${limit}!`
427
+ `[setOutputLimit] Output Limit for device key ${deviceKey} is already at ${limit}!`
413
428
  );
414
429
  }
415
430
  }
@@ -420,19 +435,21 @@ const connectMqttClient = (_adapter) => {
420
435
  const options = {
421
436
  clientId: adapter.accessToken,
422
437
  username: "zenApp",
423
- password: "oK#PCgy6OZxd",
438
+ password: adapter.config.server && adapter.config.server == "eu" ? "H6s$j9CtNa0N" : "oK#PCgy6OZxd",
424
439
  clean: true,
425
440
  protocolVersion: 5
426
441
  };
427
442
  if (mqtt && adapter && adapter.paths) {
428
- client = mqtt.connect(
443
+ adapter.log.debug("[connectMqttClient] Connecting to MQTT client...");
444
+ adapter.mqttClient = mqtt.connect(
429
445
  "mqtt://" + adapter.paths.mqttUrl + ":" + adapter.paths.mqttPort,
430
446
  options
431
447
  );
432
- if (client && adapter) {
433
- client.on("connect", onConnected);
434
- client.on("error", onError);
448
+ if (adapter && adapter.mqttClient) {
449
+ adapter.mqttClient.on("connect", onConnected);
450
+ adapter.mqttClient.on("error", onError);
435
451
  adapter.deviceList.forEach((device) => {
452
+ var _a, _b;
436
453
  if (adapter) {
437
454
  (0, import_createSolarFlowStates.createSolarFlowStates)(adapter, device.productKey, device.deviceKey);
438
455
  (0, import_adapterService.updateSolarFlowState)(
@@ -444,13 +461,17 @@ const connectMqttClient = (_adapter) => {
444
461
  );
445
462
  const reportTopic = `/${device.productKey}/${device.deviceKey}/properties/report`;
446
463
  const iotTopic = `iot/${device.productKey}/${device.deviceKey}/#`;
447
- adapter.log.debug(`Subscribing to MQTT Topic: ${reportTopic}`);
448
- client == null ? void 0 : client.subscribe(reportTopic, onSubscribe);
449
- adapter.log.debug(`Subscribing to MQTT Topic: ${iotTopic}`);
450
- client == null ? void 0 : client.subscribe(iotTopic, onSubscribe);
464
+ adapter.log.debug(
465
+ `[connectMqttClient] Subscribing to MQTT Topic: ${reportTopic}`
466
+ );
467
+ (_a = adapter.mqttClient) == null ? void 0 : _a.subscribe(reportTopic, onSubscribe);
468
+ adapter.log.debug(
469
+ `[connectMqttClient] Subscribing to MQTT Topic: ${iotTopic}`
470
+ );
471
+ (_b = adapter.mqttClient) == null ? void 0 : _b.subscribe(iotTopic, onSubscribe);
451
472
  }
452
473
  });
453
- client.on("message", onMessage);
474
+ adapter.mqttClient.on("message", onMessage);
454
475
  }
455
476
  }
456
477
  };