iobroker.zendure-solarflow 1.10.0 → 1.10.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.
@@ -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 { toHoursAndMinutes } from \"../helpers/timeHelper\";\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 \"outputPack\",\r\n \"solarInput\",\r\n \"gridInput\",\r\n \"pvPower1\",\r\n \"pvPower2\",\r\n];\r\n\r\nexport const setEnergyWhMax = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string\r\n): Promise<void> => {\r\n const currentEnergyState = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.energyWh\"\r\n );\r\n\r\n if (currentEnergyState) {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.energyWhMax`,\r\n currentEnergyState?.val,\r\n true\r\n );\r\n }\r\n};\r\n\r\nexport const setSocToZero = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string\r\n): Promise<void> => {\r\n // Set SOC to 0\r\n await adapter?.setState(\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 await adapter?.setState(\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 await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.energyWh`,\r\n 0,\r\n true\r\n );\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 let energyWhMax = 0;\r\n\r\n const minSoc = (\r\n await adapter.getStateAsync(`${productKey}.${deviceKey}.minSoc`)\r\n )?.val;\r\n const currentSoc = (\r\n await adapter.getStateAsync(`${productKey}.${deviceKey}.electricLevel`)\r\n )?.val;\r\n\r\n if (currentSoc && minSoc && Number(currentSoc) < Number(minSoc)) {\r\n // Don't calculate if current SOC is lower then minimum\r\n return;\r\n }\r\n\r\n const productName = (\r\n await adapter.getStateAsync(`${productKey}.${deviceKey}.productName`)\r\n )?.val;\r\n\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 currentMaxValue = Number(\r\n currentEnergyMaxState ? currentEnergyMaxState.val : 0\r\n );\r\n\r\n const currentValue = currentEnergyState?.val\r\n ? Number(currentEnergyState?.val)\r\n : 0;\r\n\r\n const batteries = adapter.pack2Devices.filter(\r\n (x) => x.deviceKey == deviceKey\r\n );\r\n\r\n let isAio = false;\r\n // Check if device is an solarflow or hyper device. Don't use LowVoltageBlock on an ACE device?\r\n if (productName?.toString().toLowerCase().includes(\"aio\")) {\r\n isAio = true;\r\n }\r\n\r\n if (isAio) {\r\n energyWhMax = 2400;\r\n } else {\r\n for (let i = 0; i < batteries.length; i++) {\r\n if (batteries[i].type == \"AB1000\") {\r\n energyWhMax = energyWhMax + 960;\r\n } else if (batteries[i].type == \"AB2000\") {\r\n energyWhMax = energyWhMax + 1920;\r\n }\r\n }\r\n }\r\n\r\n let newValue =\r\n stateKey == \"outputPack\" ? currentValue + value : currentValue - value;\r\n\r\n // If greater than Max of batteries, set it to this value.\r\n if (stateKey == \"outputPack\" && newValue > energyWhMax) {\r\n newValue = energyWhMax;\r\n }\r\n\r\n if (newValue > 0) {\r\n adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.energyWh`,\r\n newValue,\r\n true\r\n );\r\n\r\n if (currentEnergyMaxState) {\r\n const soc = Number(((newValue / currentMaxValue) * 100).toFixed(1));\r\n\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.soc`,\r\n soc > 100.0 ? 100 : soc,\r\n true\r\n );\r\n\r\n if (newValue > currentMaxValue) {\r\n // Extend maxVal\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.energyWhMax`,\r\n newValue,\r\n true\r\n );\r\n }\r\n\r\n const currentOutputPackPower = await adapter?.getStateAsync(\r\n `${productKey}.${deviceKey}.outputPackPower`\r\n );\r\n\r\n const currentPackInputPower = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".packInputPower\"\r\n );\r\n\r\n if (\r\n stateKey == \"outputPack\" &&\r\n currentOutputPackPower?.val != null &&\r\n currentOutputPackPower != undefined\r\n ) {\r\n // Charging, calculate remaining charging time\r\n const toCharge = currentMaxValue - newValue;\r\n\r\n const remainHoursAsDecimal =\r\n toCharge / Number(currentOutputPackPower.val);\r\n\r\n if (remainHoursAsDecimal < 48.0) {\r\n const remainFormatted = toHoursAndMinutes(\r\n Math.round(remainHoursAsDecimal * 60)\r\n );\r\n\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainInputTime`,\r\n remainFormatted,\r\n true\r\n );\r\n } else {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainInputTime`,\r\n \"\",\r\n true\r\n );\r\n }\r\n } else if (\r\n stateKey == \"packInput\" &&\r\n currentPackInputPower != null &&\r\n currentPackInputPower != undefined\r\n ) {\r\n // Discharging, calculate remaining discharge time\r\n const remainHoursAsDecimal =\r\n newValue / Number(currentPackInputPower.val);\r\n const remainFormatted = toHoursAndMinutes(\r\n Math.round(remainHoursAsDecimal * 60)\r\n );\r\n\r\n if (remainHoursAsDecimal < 48.0) {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainOutTime`,\r\n remainFormatted,\r\n true\r\n );\r\n } else {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainOutTime`,\r\n \"\",\r\n true\r\n );\r\n }\r\n }\r\n }\r\n } else if (newValue <= 0 && stateKey == \"outputPack\") {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainInputTime`,\r\n \"\",\r\n true\r\n );\r\n } else if (newValue <= 0 && stateKey == \"packInput\") {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainOutTime`,\r\n \"\",\r\n true\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 let stateNameEnergyWh = \"\";\r\n let stateNameEnergykWh = \"\";\r\n let stateNamePower = \"\";\r\n\r\n if (stateKey == \"pvPower1\") {\r\n stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.solarInputPv1EnergyTodayWh`;\r\n stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.solarInputPv1EnergyTodaykWh`;\r\n stateNamePower = `${productKey}.${deviceKey}.pvPower1`;\r\n } else if (stateKey == \"pvPower2\") {\r\n stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.solarInputPv2EnergyTodayWh`;\r\n stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.solarInputPv2EnergyTodaykWh`;\r\n stateNamePower = `${productKey}.${deviceKey}.pvPower2`;\r\n } else {\r\n stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodayWh`;\r\n stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodaykWh`;\r\n stateNamePower = `${productKey}.${deviceKey}.${stateKey}Power`;\r\n }\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 await adapter?.setState(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 // Timeframe = 30000ms, Job runs every 30 seconds...\r\n const timeFrame = 30000;\r\n\r\n // Calculate Energy value (Wh) from current power in the timeframe from last run...\r\n let addEnergyValue =\r\n (Number(currentPowerState.val) * timeFrame) / 3600000; // Wh\r\n\r\n // Use efficiency factor (used the one from Youtube Channel VoltAmpereLux - thanks!)\r\n const chargingFactor = 0.96; // Efficiency 96%\r\n const dischargingFactor = 1.08 - addEnergyValue / 10000; // Efficiency 92% - 98% (92% + Energy / 10000 = 600W -> +6%)\r\n\r\n // Calculate energy from efficiency factor if value for charging or discharging\r\n addEnergyValue =\r\n stateKey == \"outputPack\" && addEnergyValue > 0\r\n ? addEnergyValue * chargingFactor\r\n : addEnergyValue;\r\n addEnergyValue =\r\n stateKey == \"packInput\" && addEnergyValue > 0\r\n ? addEnergyValue * dischargingFactor\r\n : addEnergyValue;\r\n\r\n let newEnergyValue = Number(currentEnergyState.val) + addEnergyValue;\r\n\r\n // Fix negative value\r\n if (newEnergyValue < 0) {\r\n newEnergyValue = 0;\r\n }\r\n\r\n await adapter?.setState(stateNameEnergyWh, newEnergyValue, true);\r\n await adapter?.setState(\r\n stateNameEnergykWh,\r\n Number((newEnergyValue / 1000).toFixed(2)),\r\n true\r\n );\r\n\r\n // SOC and energy in batteries\r\n if (\r\n (stateKey == \"outputPack\" || stateKey == \"packInput\") &&\r\n addEnergyValue > 0\r\n ) {\r\n await calculateSocAndEnergy(\r\n adapter,\r\n productKey,\r\n deviceKey,\r\n stateKey,\r\n addEnergyValue\r\n );\r\n } else {\r\n if (stateKey == \"outputPack\") {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainInputTime`,\r\n \"\",\r\n true\r\n );\r\n } else if (stateKey == \"packInput\") {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainOutTime`,\r\n \"\",\r\n true\r\n );\r\n }\r\n }\r\n } else {\r\n await adapter?.setState(stateNameEnergyWh, 0, true);\r\n await adapter?.setState(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(async (stateKey: string) => {\r\n let stateNameEnergyWh = \"\";\r\n let stateNameEnergykWh = \"\";\r\n\r\n if (stateKey == \"pvPower1\") {\r\n stateNameEnergyWh = `${device.productKey}.${device.deviceKey}.calculations.solarInputPv1EnergyTodayWh`;\r\n stateNameEnergykWh = `${device.productKey}.${device.deviceKey}.calculations.solarInputPv1EnergyTodaykWh`;\r\n } else if (stateKey == \"pvPower2\") {\r\n stateNameEnergyWh = `${device.productKey}.${device.deviceKey}.calculations.solarInputPv2EnergyTodayWh`;\r\n stateNameEnergykWh = `${device.productKey}.${device.deviceKey}.calculations.solarInputPv2EnergyTodaykWh`;\r\n } else {\r\n stateNameEnergyWh = `${device.productKey}.${device.deviceKey}.calculations.${stateKey}EnergyTodayWh`;\r\n stateNameEnergykWh = `${device.productKey}.${device.deviceKey}.calculations.${stateKey}EnergyTodaykWh`;\r\n }\r\n\r\n await adapter?.setState(stateNameEnergyWh, 0, true);\r\n await adapter?.setState(stateNameEnergykWh, 0, true);\r\n });\r\n });\r\n};\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;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S;AAAA,MAC/D,OAAO;AACL,4BAAoB,GAAG,OAAO,UAAU,IAAI,OAAO,SAAS,iBAAiB,QAAQ;AACrF,6BAAqB,GAAG,OAAO,UAAU,IAAI,OAAO,SAAS,iBAAiB,QAAQ;AAAA,MACxF;AAEA,aAAM,mCAAS,SAAS,mBAAmB,GAAG;AAC9C,aAAM,mCAAS,SAAS,oBAAoB,GAAG;AAAA,IACjD,CAAC;AAAA,EACH,CAAC;AACH;",
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/indent */\r\n\r\nimport { toHoursAndMinutes } from \"../helpers/timeHelper\";\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 \"outputPack\",\r\n \"solarInput\",\r\n \"gridInputPower\",\r\n \"pvPower1\",\r\n \"pvPower2\",\r\n];\r\n\r\nexport const setEnergyWhMax = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string\r\n): Promise<void> => {\r\n const currentEnergyState = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".calculations.energyWh\"\r\n );\r\n\r\n if (currentEnergyState) {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.energyWhMax`,\r\n currentEnergyState?.val,\r\n true\r\n );\r\n }\r\n};\r\n\r\nexport const setSocToZero = async (\r\n adapter: ZendureSolarflow,\r\n productKey: string,\r\n deviceKey: string\r\n): Promise<void> => {\r\n // Set SOC to 0\r\n await adapter?.setState(\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 await adapter?.setState(\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 await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.energyWh`,\r\n 0,\r\n true\r\n );\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 let energyWhMax = 0;\r\n\r\n const minSoc = (\r\n await adapter.getStateAsync(`${productKey}.${deviceKey}.minSoc`)\r\n )?.val;\r\n const currentSoc = (\r\n await adapter.getStateAsync(`${productKey}.${deviceKey}.electricLevel`)\r\n )?.val;\r\n\r\n if (currentSoc && minSoc && Number(currentSoc) < Number(minSoc)) {\r\n // Don't calculate if current SOC is lower then minimum\r\n return;\r\n }\r\n\r\n const productName = (\r\n await adapter.getStateAsync(`${productKey}.${deviceKey}.productName`)\r\n )?.val;\r\n\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 lowVoltageBlock = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".control.lowVoltageBlock\"\r\n );\r\n\r\n const currentMaxValue = Number(\r\n currentEnergyMaxState ? currentEnergyMaxState.val : 0\r\n );\r\n\r\n const currentValue = currentEnergyState?.val\r\n ? Number(currentEnergyState?.val)\r\n : 0;\r\n\r\n const batteries = adapter.pack2Devices.filter(\r\n (x) => x.deviceKey == deviceKey\r\n );\r\n\r\n let isAio = false;\r\n // Check if device is an solarflow or hyper device. Don't use LowVoltageBlock on an ACE device?\r\n if (productName?.toString().toLowerCase().includes(\"aio\")) {\r\n isAio = true;\r\n }\r\n\r\n if (isAio) {\r\n energyWhMax = 2400;\r\n } else {\r\n for (let i = 0; i < batteries.length; i++) {\r\n if (batteries[i].type == \"AB1000\") {\r\n energyWhMax = energyWhMax + 960;\r\n } else if (batteries[i].type == \"AB2000\") {\r\n energyWhMax = energyWhMax + 1920;\r\n }\r\n }\r\n }\r\n\r\n let newValue =\r\n stateKey == \"outputPack\" ? currentValue + value : currentValue - value;\r\n\r\n // If greater than Max of batteries, set it to this value.\r\n if (stateKey == \"outputPack\" && newValue > energyWhMax) {\r\n newValue = energyWhMax;\r\n }\r\n\r\n if (newValue > 0) {\r\n adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.energyWh`,\r\n newValue,\r\n true\r\n );\r\n\r\n if (currentEnergyMaxState) {\r\n const soc = Number(((newValue / currentMaxValue) * 100).toFixed(1));\r\n\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.soc`,\r\n soc > 100.0 ? 100 : soc,\r\n true\r\n );\r\n\r\n if (newValue > currentMaxValue && !lowVoltageBlock?.val) {\r\n // Extend maxVal\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.energyWhMax`,\r\n newValue,\r\n true\r\n );\r\n }\r\n\r\n const currentOutputPackPower = await adapter?.getStateAsync(\r\n `${productKey}.${deviceKey}.outputPackPower`\r\n );\r\n\r\n const currentPackInputPower = await adapter?.getStateAsync(\r\n productKey + \".\" + deviceKey + \".packInputPower\"\r\n );\r\n\r\n if (\r\n stateKey == \"outputPack\" &&\r\n currentOutputPackPower?.val != null &&\r\n currentOutputPackPower != undefined\r\n ) {\r\n // Charging, calculate remaining charging time\r\n const toCharge = currentMaxValue - newValue;\r\n\r\n const remainHoursAsDecimal =\r\n toCharge / Number(currentOutputPackPower.val);\r\n\r\n if (remainHoursAsDecimal < 48.0) {\r\n const remainFormatted = toHoursAndMinutes(\r\n Math.round(remainHoursAsDecimal * 60)\r\n );\r\n\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainInputTime`,\r\n remainFormatted,\r\n true\r\n );\r\n } else {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainInputTime`,\r\n \"\",\r\n true\r\n );\r\n }\r\n } else if (\r\n stateKey == \"packInput\" &&\r\n currentPackInputPower != null &&\r\n currentPackInputPower != undefined\r\n ) {\r\n // Discharging, calculate remaining discharge time\r\n const remainHoursAsDecimal =\r\n newValue / Number(currentPackInputPower.val);\r\n const remainFormatted = toHoursAndMinutes(\r\n Math.round(remainHoursAsDecimal * 60)\r\n );\r\n\r\n if (remainHoursAsDecimal < 48.0) {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainOutTime`,\r\n remainFormatted,\r\n true\r\n );\r\n } else {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainOutTime`,\r\n \"\",\r\n true\r\n );\r\n }\r\n }\r\n }\r\n } else if (newValue <= 0 && stateKey == \"outputPack\") {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainInputTime`,\r\n \"\",\r\n true\r\n );\r\n } else if (newValue <= 0 && stateKey == \"packInput\") {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainOutTime`,\r\n \"\",\r\n true\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 let stateNameEnergyWh = \"\";\r\n let stateNameEnergykWh = \"\";\r\n let stateNamePower = \"\";\r\n\r\n if (stateKey == \"pvPower1\") {\r\n stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.solarInputPv1EnergyTodayWh`;\r\n stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.solarInputPv1EnergyTodaykWh`;\r\n stateNamePower = `${productKey}.${deviceKey}.pvPower1`;\r\n } else if (stateKey == \"pvPower2\") {\r\n stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.solarInputPv2EnergyTodayWh`;\r\n stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.solarInputPv2EnergyTodaykWh`;\r\n stateNamePower = `${productKey}.${deviceKey}.pvPower2`;\r\n } else {\r\n stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodayWh`;\r\n stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodaykWh`;\r\n stateNamePower = `${productKey}.${deviceKey}.${stateKey}Power`;\r\n }\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 await adapter?.setState(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 // Timeframe = 30000ms, Job runs every 30 seconds...\r\n const timeFrame = 30000;\r\n\r\n // Calculate Energy value (Wh) from current power in the timeframe from last run...\r\n let addEnergyValue =\r\n (Number(currentPowerState.val) * timeFrame) / 3600000; // Wh\r\n\r\n // Use efficiency factor (used the one from Youtube Channel VoltAmpereLux - thanks!)\r\n const chargingFactor = 0.96; // Efficiency 96%\r\n const dischargingFactor = 1.08 - addEnergyValue / 10000; // Efficiency 92% - 98% (92% + Energy / 10000 = 600W -> +6%)\r\n\r\n // Calculate energy from efficiency factor if value for charging or discharging\r\n addEnergyValue =\r\n stateKey == \"outputPack\" && addEnergyValue > 0\r\n ? addEnergyValue * chargingFactor\r\n : addEnergyValue;\r\n addEnergyValue =\r\n stateKey == \"packInput\" && addEnergyValue > 0\r\n ? addEnergyValue * dischargingFactor\r\n : addEnergyValue;\r\n\r\n let newEnergyValue = Number(currentEnergyState.val) + addEnergyValue;\r\n\r\n // Fix negative value\r\n if (newEnergyValue < 0) {\r\n newEnergyValue = 0;\r\n }\r\n\r\n await adapter?.setState(stateNameEnergyWh, newEnergyValue, true);\r\n await adapter?.setState(\r\n stateNameEnergykWh,\r\n Number((newEnergyValue / 1000).toFixed(2)),\r\n true\r\n );\r\n\r\n // SOC and energy in batteries\r\n if (\r\n (stateKey == \"outputPack\" || stateKey == \"packInput\") &&\r\n addEnergyValue > 0\r\n ) {\r\n await calculateSocAndEnergy(\r\n adapter,\r\n productKey,\r\n deviceKey,\r\n stateKey,\r\n addEnergyValue\r\n );\r\n } else {\r\n if (stateKey == \"outputPack\") {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainInputTime`,\r\n \"\",\r\n true\r\n );\r\n } else if (stateKey == \"packInput\") {\r\n await adapter?.setState(\r\n `${productKey}.${deviceKey}.calculations.remainOutTime`,\r\n \"\",\r\n true\r\n );\r\n }\r\n }\r\n } else {\r\n await adapter?.setState(stateNameEnergyWh, 0, true);\r\n await adapter?.setState(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(async (stateKey: string) => {\r\n let stateNameEnergyWh = \"\";\r\n let stateNameEnergykWh = \"\";\r\n\r\n if (stateKey == \"pvPower1\") {\r\n stateNameEnergyWh = `${device.productKey}.${device.deviceKey}.calculations.solarInputPv1EnergyTodayWh`;\r\n stateNameEnergykWh = `${device.productKey}.${device.deviceKey}.calculations.solarInputPv1EnergyTodaykWh`;\r\n } else if (stateKey == \"pvPower2\") {\r\n stateNameEnergyWh = `${device.productKey}.${device.deviceKey}.calculations.solarInputPv2EnergyTodayWh`;\r\n stateNameEnergykWh = `${device.productKey}.${device.deviceKey}.calculations.solarInputPv2EnergyTodaykWh`;\r\n } else {\r\n stateNameEnergyWh = `${device.productKey}.${device.deviceKey}.calculations.${stateKey}EnergyTodayWh`;\r\n stateNameEnergykWh = `${device.productKey}.${device.deviceKey}.calculations.${stateKey}EnergyTodaykWh`;\r\n }\r\n\r\n await adapter?.setState(stateNameEnergyWh, 0, true);\r\n await adapter?.setState(stateNameEnergykWh, 0, true);\r\n });\r\n });\r\n};\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAAkC;AAIlC,MAAM,uBAAuB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,iBAAiB,OAC5B,SACA,YACA,cACkB;AAClB,QAAM,qBAAqB,OAAM,mCAAS;AAAA,IACxC,aAAa,MAAM,YAAY;AAAA;AAGjC,MAAI,oBAAoB;AACtB,WAAM,mCAAS;AAAA,MACb,GAAG,UAAU,IAAI,SAAS;AAAA,MAC1B,yDAAoB;AAAA,MACpB;AAAA;AAAA,EAEJ;AACF;AAEO,MAAM,eAAe,OAC1B,SACA,YACA,cACkB;AAElB,SAAM,mCAAS;AAAA,IACb,GAAG,UAAU,IAAI,SAAS;AAAA,IAC1B;AAAA,IACA;AAAA;AAIF,QAAM,gBAAgB,MAAM,QAAQ;AAAA,IAClC,GAAG,UAAU,IAAI,SAAS;AAAA,EAC5B;AACA,QAAM,mBAAmB,MAAM,QAAQ;AAAA,IACrC,GAAG,UAAU,IAAI,SAAS;AAAA,EAC5B;AAEA,QAAM,SAAS,OAAO,qDAAkB,GAAG,IAAI,OAAO,+CAAe,GAAG;AAGxE,SAAM,mCAAS;AAAA,IACb,GAAG,UAAU,IAAI,SAAS;AAAA,IAC1B;AAAA,IACA;AAAA;AAIF,SAAM,mCAAS;AAAA,IACb,GAAG,UAAU,IAAI,SAAS;AAAA,IAC1B;AAAA,IACA;AAAA;AAEJ;AAEO,MAAM,wBAAwB,OACnC,SACA,YACA,WACA,UACA,UACkB;AA9EpB;AA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UAAI,oBAAoB;AACxB,UAAI,qBAAqB;AAEzB,UAAI,YAAY,YAAY;AAC1B,4BAAoB,GAAG,OAAO,UAAU,IAAI,OAAO,SAAS;AAC5D,6BAAqB,GAAG,OAAO,UAAU,IAAI,OAAO,SAAS;AAAA,MAC/D,WAAW,YAAY,YAAY;AACjC,4BAAoB,GAAG,OAAO,UAAU,IAAI,OAAO,SAAS;AAC5D,6BAAqB,GAAG,OAAO,UAAU,IAAI,OAAO,SAAS;AAAA,MAC/D,OAAO;AACL,4BAAoB,GAAG,OAAO,UAAU,IAAI,OAAO,SAAS,iBAAiB,QAAQ;AACrF,6BAAqB,GAAG,OAAO,UAAU,IAAI,OAAO,SAAS,iBAAiB,QAAQ;AAAA,MACxF;AAEA,aAAM,mCAAS,SAAS,mBAAmB,GAAG;AAC9C,aAAM,mCAAS,SAAS,oBAAoB,GAAG;AAAA,IACjD,CAAC;AAAA,EACH,CAAC;AACH;",
6
6
  "names": []
7
7
  }
@@ -56,6 +56,7 @@ const startCheckStatesAndConnectionJob = async (adapter) => {
56
56
  const statesToReset = [
57
57
  "outputHomePower",
58
58
  "outputPackPower",
59
+ "gridInputPower",
59
60
  "packInputPower",
60
61
  "solarInputPower"
61
62
  ];
@@ -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\n/* import { connectMqttClient } from \"./mqttService\";\r\nimport { login } from \"./webService\"; */\r\nimport { ISolarFlowDeviceDetails } from \"../models/ISolarFlowDeviceDetails\";\r\nimport { calculateEnergy, resetTodaysValues } from \"./calculationService\";\r\n\r\n/* const refreshAccessToken = async (adapter: ZendureSolarflow): Promise<void> => {\r\n // Relogin every 3 hours to get a fresh accessToken!\r\n adapter.log.info(`[startRefreshAccessTokenTimerJob] Stop connections!`);\r\n\r\n // Scheduler beenden\r\n if (adapter.resetValuesJob) {\r\n adapter.resetValuesJob.cancel();\r\n }\r\n\r\n if (adapter.checkStatesJob) {\r\n adapter.checkStatesJob?.cancel();\r\n }\r\n\r\n if (adapter.calculationJob) {\r\n adapter.calculationJob.cancel();\r\n }\r\n\r\n if (adapter.mqttClient) {\r\n adapter.mqttClient.end();\r\n }\r\n\r\n adapter.log.info(\r\n `[startRefreshAccessTokenTimerJob] Refreshing accessToken in 10 seconds!`,\r\n );\r\n await adapter.delay(10 * 1000);\r\n\r\n adapter.resetValuesJob = undefined;\r\n adapter.checkStatesJob = undefined;\r\n adapter.calculationJob = undefined;\r\n adapter.mqttClient = undefined;\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.setState(\"info.connection\", true, true);\r\n\r\n connectMqttClient(adapter);\r\n });\r\n }\r\n}; */\r\n\r\nexport const startRefreshAccessTokenTimerJob = async (\r\n adapter: ZendureSolarflow\r\n): Promise<void> => {\r\n adapter.refreshAccessTokenInterval = adapter.setInterval(\r\n async () => {\r\n adapter.log.info(\r\n `Refresh Access Token - Adapter will restart in 20 seconds!`\r\n );\r\n\r\n await adapter.delay(20 * 1000);\r\n adapter.restart();\r\n },\r\n 3 * 60 * 60 * 1000\r\n );\r\n};\r\n\r\nexport const startResetValuesJob = async (\r\n adapter: ZendureSolarflow\r\n): Promise<void> => {\r\n adapter.resetValuesJob = scheduleJob(\"5 0 0 * * *\", () => {\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(\"*/30 * * * * *\", () => {\r\n adapter.deviceList.forEach((device) => {\r\n if (device.productKey != \"s3Xk4x\") {\r\n calculateEnergy(adapter, device.productKey, device.deviceKey);\r\n }\r\n });\r\n });\r\n};\r\n\r\nexport const startCheckStatesAndConnectionJob = 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 let refreshAccessTokenNeeded = false;\r\n\r\n adapter.log.debug(\r\n `[checkStatesJob] Starting check of states and connection!`\r\n );\r\n\r\n adapter.checkStatesJob = scheduleJob(\"*/5 * * * *\", async () => {\r\n adapter.deviceList.forEach(async (device: ISolarFlowDeviceDetails) => {\r\n if (refreshAccessTokenNeeded) {\r\n return;\r\n }\r\n\r\n const lastUpdate = await adapter?.getStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".lastUpdate\"\r\n );\r\n\r\n const wifiState = await adapter?.getStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".wifiState\"\r\n );\r\n\r\n const fiveMinutesAgo = (Date.now() / 1000 - 5 * 60) * 1000; // Five minutes ago\r\n const tenMinutesAgo = (Date.now() / 1000 - 10 * 60) * 1000; // Ten minutes ago\r\n\r\n if (\r\n lastUpdate &&\r\n lastUpdate.val &&\r\n Number(lastUpdate.val) < fiveMinutesAgo &&\r\n wifiState?.val == \"Connected\"\r\n ) {\r\n adapter.log.warn(\r\n `[checkStatesJob] Last update for deviceKey ${\r\n device.deviceKey\r\n } was at ${new Date(\r\n Number(lastUpdate)\r\n )}, device seems to be online - so maybe connection is broken - restart adapter in 20 seconds!`\r\n );\r\n\r\n await adapter.delay(20 * 1000);\r\n adapter.restart();\r\n\r\n // set marker, so we discontinue the forEach Loop because of reconnect!\r\n refreshAccessTokenNeeded = true;\r\n }\r\n\r\n if (\r\n lastUpdate &&\r\n lastUpdate.val &&\r\n Number(lastUpdate.val) < tenMinutesAgo &&\r\n !refreshAccessTokenNeeded\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?.setState(\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?.setState(\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};\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAA4B;AAK5B,gCAAmD;AA4C5C,MAAM,kCAAkC,OAC7C,YACkB;AAClB,UAAQ,6BAA6B,QAAQ;AAAA,IAC3C,YAAY;AACV,cAAQ,IAAI;AAAA,QACV;AAAA,MACF;AAEA,YAAM,QAAQ,MAAM,KAAK,GAAI;AAC7B,cAAQ,QAAQ;AAAA,IAClB;AAAA,IACA,IAAI,KAAK,KAAK;AAAA,EAChB;AACF;AAEO,MAAM,sBAAsB,OACjC,YACkB;AAClB,UAAQ,qBAAiB,kCAAY,eAAe,MAAM;AAExD,qDAAkB,OAAO;AAAA,EAC3B,CAAC;AACH;AAEO,MAAM,sBAAsB,OACjC,YACkB;AAClB,UAAQ,qBAAiB,kCAAY,kBAAkB,MAAM;AAC3D,YAAQ,WAAW,QAAQ,CAAC,WAAW;AACrC,UAAI,OAAO,cAAc,UAAU;AACjC,uDAAgB,SAAS,OAAO,YAAY,OAAO,SAAS;AAAA,MAC9D;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;AAEO,MAAM,mCAAmC,OAC9C,YACkB;AAElB,QAAM,gBAA0B;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,2BAA2B;AAE/B,UAAQ,IAAI;AAAA,IACV;AAAA,EACF;AAEA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r\nimport { scheduleJob } from \"node-schedule\";\r\nimport { ZendureSolarflow } from \"../main\";\r\n/* import { connectMqttClient } from \"./mqttService\";\r\nimport { login } from \"./webService\"; */\r\nimport { ISolarFlowDeviceDetails } from \"../models/ISolarFlowDeviceDetails\";\r\nimport { calculateEnergy, resetTodaysValues } from \"./calculationService\";\r\n\r\n/* const refreshAccessToken = async (adapter: ZendureSolarflow): Promise<void> => {\r\n // Relogin every 3 hours to get a fresh accessToken!\r\n adapter.log.info(`[startRefreshAccessTokenTimerJob] Stop connections!`);\r\n\r\n // Scheduler beenden\r\n if (adapter.resetValuesJob) {\r\n adapter.resetValuesJob.cancel();\r\n }\r\n\r\n if (adapter.checkStatesJob) {\r\n adapter.checkStatesJob?.cancel();\r\n }\r\n\r\n if (adapter.calculationJob) {\r\n adapter.calculationJob.cancel();\r\n }\r\n\r\n if (adapter.mqttClient) {\r\n adapter.mqttClient.end();\r\n }\r\n\r\n adapter.log.info(\r\n `[startRefreshAccessTokenTimerJob] Refreshing accessToken in 10 seconds!`,\r\n );\r\n await adapter.delay(10 * 1000);\r\n\r\n adapter.resetValuesJob = undefined;\r\n adapter.checkStatesJob = undefined;\r\n adapter.calculationJob = undefined;\r\n adapter.mqttClient = undefined;\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.setState(\"info.connection\", true, true);\r\n\r\n connectMqttClient(adapter);\r\n });\r\n }\r\n}; */\r\n\r\nexport const startRefreshAccessTokenTimerJob = async (\r\n adapter: ZendureSolarflow\r\n): Promise<void> => {\r\n adapter.refreshAccessTokenInterval = adapter.setInterval(\r\n async () => {\r\n adapter.log.info(\r\n `Refresh Access Token - Adapter will restart in 20 seconds!`\r\n );\r\n\r\n await adapter.delay(20 * 1000);\r\n adapter.restart();\r\n },\r\n 3 * 60 * 60 * 1000\r\n );\r\n};\r\n\r\nexport const startResetValuesJob = async (\r\n adapter: ZendureSolarflow\r\n): Promise<void> => {\r\n adapter.resetValuesJob = scheduleJob(\"5 0 0 * * *\", () => {\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(\"*/30 * * * * *\", () => {\r\n adapter.deviceList.forEach((device) => {\r\n if (device.productKey != \"s3Xk4x\") {\r\n calculateEnergy(adapter, device.productKey, device.deviceKey);\r\n }\r\n });\r\n });\r\n};\r\n\r\nexport const startCheckStatesAndConnectionJob = 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 \"gridInputPower\",\r\n \"packInputPower\",\r\n \"solarInputPower\",\r\n ];\r\n\r\n let refreshAccessTokenNeeded = false;\r\n\r\n adapter.log.debug(\r\n `[checkStatesJob] Starting check of states and connection!`\r\n );\r\n\r\n adapter.checkStatesJob = scheduleJob(\"*/5 * * * *\", async () => {\r\n adapter.deviceList.forEach(async (device: ISolarFlowDeviceDetails) => {\r\n if (refreshAccessTokenNeeded) {\r\n return;\r\n }\r\n\r\n const lastUpdate = await adapter?.getStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".lastUpdate\"\r\n );\r\n\r\n const wifiState = await adapter?.getStateAsync(\r\n device.productKey + \".\" + device.deviceKey + \".wifiState\"\r\n );\r\n\r\n const fiveMinutesAgo = (Date.now() / 1000 - 5 * 60) * 1000; // Five minutes ago\r\n const tenMinutesAgo = (Date.now() / 1000 - 10 * 60) * 1000; // Ten minutes ago\r\n\r\n if (\r\n lastUpdate &&\r\n lastUpdate.val &&\r\n Number(lastUpdate.val) < fiveMinutesAgo &&\r\n wifiState?.val == \"Connected\"\r\n ) {\r\n adapter.log.warn(\r\n `[checkStatesJob] Last update for deviceKey ${\r\n device.deviceKey\r\n } was at ${new Date(\r\n Number(lastUpdate)\r\n )}, device seems to be online - so maybe connection is broken - restart adapter in 20 seconds!`\r\n );\r\n\r\n await adapter.delay(20 * 1000);\r\n adapter.restart();\r\n\r\n // set marker, so we discontinue the forEach Loop because of reconnect!\r\n refreshAccessTokenNeeded = true;\r\n }\r\n\r\n if (\r\n lastUpdate &&\r\n lastUpdate.val &&\r\n Number(lastUpdate.val) < tenMinutesAgo &&\r\n !refreshAccessTokenNeeded\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?.setState(\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?.setState(\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};\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAA4B;AAK5B,gCAAmD;AA4C5C,MAAM,kCAAkC,OAC7C,YACkB;AAClB,UAAQ,6BAA6B,QAAQ;AAAA,IAC3C,YAAY;AACV,cAAQ,IAAI;AAAA,QACV;AAAA,MACF;AAEA,YAAM,QAAQ,MAAM,KAAK,GAAI;AAC7B,cAAQ,QAAQ;AAAA,IAClB;AAAA,IACA,IAAI,KAAK,KAAK;AAAA,EAChB;AACF;AAEO,MAAM,sBAAsB,OACjC,YACkB;AAClB,UAAQ,qBAAiB,kCAAY,eAAe,MAAM;AAExD,qDAAkB,OAAO;AAAA,EAC3B,CAAC;AACH;AAEO,MAAM,sBAAsB,OACjC,YACkB;AAClB,UAAQ,qBA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AEA,cAAM,cAAc,QAAQ,OAAO,cAAsB;AACvD,iBAAM,mCAAS;AAAA,YACb,OAAO,aAAa,MAAM,OAAO,YAAY,MAAM;AAAA,YACnD;AAAA,YACA;AAAA;AAAA,QAEJ,CAAC;AAGD,YAAI,OAAO,aAAa;AACtB,iBAAM,mCAAS;AAAA,YACb,OAAO,aAAa,MAAM,OAAO,YAAY;AAAA,YAC7C,OAAO;AAAA,YACP;AAAA;AAAA,QAEJ;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;",
6
6
  "names": []
7
7
  }
@@ -206,7 +206,7 @@ const addOrUpdatePackData = async (productKey, deviceKey, packData, isSolarFlow)
206
206
  }
207
207
  };
208
208
  const onMessage = async (topic, message) => {
209
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka;
209
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma;
210
210
  if (adapter) {
211
211
  if (topic.toLowerCase().includes("loginOut/force")) {
212
212
  }
@@ -374,6 +374,12 @@ const onMessage = async (topic, message) => {
374
374
  if (solarInputPower && Number(solarInputPower.val) < 10) {
375
375
  standbyUsage = 10 - Number(solarInputPower.val);
376
376
  }
377
+ const device = (_I = adapter == null ? void 0 : adapter.deviceList) == null ? void 0 : _I.find(
378
+ (x) => x.deviceKey == deviceKey && x.productKey == productKey
379
+ );
380
+ if (device && device._connectedWithAce) {
381
+ standbyUsage += 10;
382
+ }
377
383
  (0, import_adapterService.updateSolarFlowState)(
378
384
  adapter,
379
385
  productKey,
@@ -389,7 +395,7 @@ const onMessage = async (topic, message) => {
389
395
  0
390
396
  );
391
397
  }
392
- if (((_I = obj.properties) == null ? void 0 : _I.solarInputPower) != null && ((_J = obj.properties) == null ? void 0 : _J.solarInputPower) != void 0) {
398
+ if (((_J = obj.properties) == null ? void 0 : _J.solarInputPower) != null && ((_K = obj.properties) == null ? void 0 : _K.solarInputPower) != void 0) {
393
399
  (0, import_adapterService.updateSolarFlowState)(
394
400
  adapter,
395
401
  productKey,
@@ -398,7 +404,7 @@ const onMessage = async (topic, message) => {
398
404
  obj.properties.solarInputPower
399
405
  );
400
406
  }
401
- if (((_K = obj.properties) == null ? void 0 : _K.pvPower1) != null && ((_L = obj.properties) == null ? void 0 : _L.pvPower1) != void 0) {
407
+ if (((_L = obj.properties) == null ? void 0 : _L.pvPower1) != null && ((_M = obj.properties) == null ? void 0 : _M.pvPower1) != void 0) {
402
408
  (0, import_adapterService.updateSolarFlowState)(
403
409
  adapter,
404
410
  productKey,
@@ -408,7 +414,7 @@ const onMessage = async (topic, message) => {
408
414
  obj.properties.pvPower1
409
415
  );
410
416
  }
411
- if (((_M = obj.properties) == null ? void 0 : _M.pvPower2) != null && ((_N = obj.properties) == null ? void 0 : _N.pvPower2) != void 0) {
417
+ if (((_N = obj.properties) == null ? void 0 : _N.pvPower2) != null && ((_O = obj.properties) == null ? void 0 : _O.pvPower2) != void 0) {
412
418
  (0, import_adapterService.updateSolarFlowState)(
413
419
  adapter,
414
420
  productKey,
@@ -418,7 +424,7 @@ const onMessage = async (topic, message) => {
418
424
  obj.properties.pvPower2
419
425
  );
420
426
  }
421
- if (((_O = obj.properties) == null ? void 0 : _O.solarPower1) != null && ((_P = obj.properties) == null ? void 0 : _P.solarPower1) != void 0) {
427
+ if (((_P = obj.properties) == null ? void 0 : _P.solarPower1) != null && ((_Q = obj.properties) == null ? void 0 : _Q.solarPower1) != void 0) {
422
428
  (0, import_adapterService.updateSolarFlowState)(
423
429
  adapter,
424
430
  productKey,
@@ -427,7 +433,7 @@ const onMessage = async (topic, message) => {
427
433
  obj.properties.solarPower1
428
434
  );
429
435
  }
430
- if (((_Q = obj.properties) == null ? void 0 : _Q.solarPower2) != null && ((_R = obj.properties) == null ? void 0 : _R.solarPower2) != void 0) {
436
+ if (((_R = obj.properties) == null ? void 0 : _R.solarPower2) != null && ((_S = obj.properties) == null ? void 0 : _S.solarPower2) != void 0) {
431
437
  (0, import_adapterService.updateSolarFlowState)(
432
438
  adapter,
433
439
  productKey,
@@ -436,7 +442,7 @@ const onMessage = async (topic, message) => {
436
442
  obj.properties.solarPower2
437
443
  );
438
444
  }
439
- if (((_S = obj.properties) == null ? void 0 : _S.remainOutTime) != null && ((_T = obj.properties) == null ? void 0 : _T.remainOutTime) != void 0) {
445
+ if (((_T = obj.properties) == null ? void 0 : _T.remainOutTime) != null && ((_U = obj.properties) == null ? void 0 : _U.remainOutTime) != void 0) {
440
446
  (0, import_adapterService.updateSolarFlowState)(
441
447
  adapter,
442
448
  productKey,
@@ -445,7 +451,7 @@ const onMessage = async (topic, message) => {
445
451
  obj.properties.remainOutTime
446
452
  );
447
453
  }
448
- if (((_U = obj.properties) == null ? void 0 : _U.remainInputTime) != null && ((_V = obj.properties) == null ? void 0 : _V.remainInputTime) != void 0) {
454
+ if (((_V = obj.properties) == null ? void 0 : _V.remainInputTime) != null && ((_W = obj.properties) == null ? void 0 : _W.remainInputTime) != void 0) {
449
455
  (0, import_adapterService.updateSolarFlowState)(
450
456
  adapter,
451
457
  productKey,
@@ -454,7 +460,7 @@ const onMessage = async (topic, message) => {
454
460
  obj.properties.remainInputTime
455
461
  );
456
462
  }
457
- if (((_W = obj.properties) == null ? void 0 : _W.socSet) != null && ((_X = obj.properties) == null ? void 0 : _X.socSet) != void 0) {
463
+ if (((_X = obj.properties) == null ? void 0 : _X.socSet) != null && ((_Y = obj.properties) == null ? void 0 : _Y.socSet) != void 0) {
458
464
  (0, import_adapterService.updateSolarFlowState)(
459
465
  adapter,
460
466
  productKey,
@@ -470,7 +476,7 @@ const onMessage = async (topic, message) => {
470
476
  Number(obj.properties.socSet) / 10
471
477
  );
472
478
  }
473
- if (((_Y = obj.properties) == null ? void 0 : _Y.minSoc) != null && ((_Z = obj.properties) == null ? void 0 : _Z.minSoc) != void 0) {
479
+ if (((_Z = obj.properties) == null ? void 0 : _Z.minSoc) != null && ((__ = obj.properties) == null ? void 0 : __.minSoc) != void 0) {
474
480
  (0, import_adapterService.updateSolarFlowState)(
475
481
  adapter,
476
482
  productKey,
@@ -486,7 +492,7 @@ const onMessage = async (topic, message) => {
486
492
  Number(obj.properties.minSoc) / 10
487
493
  );
488
494
  }
489
- if (((__ = obj.properties) == null ? void 0 : __.inputLimit) != null && ((_$ = obj.properties) == null ? void 0 : _$.inputLimit) != void 0) {
495
+ if (((_$ = obj.properties) == null ? void 0 : _$.inputLimit) != null && ((_aa = obj.properties) == null ? void 0 : _aa.inputLimit) != void 0) {
490
496
  (0, import_adapterService.updateSolarFlowState)(
491
497
  adapter,
492
498
  productKey,
@@ -494,7 +500,7 @@ const onMessage = async (topic, message) => {
494
500
  "inputLimit",
495
501
  obj.properties.inputLimit
496
502
  );
497
- if (((_aa = productName == null ? void 0 : productName.val) == null ? void 0 : _aa.toString().toLowerCase().includes("ace")) || ((_ba = productName == null ? void 0 : productName.val) == null ? void 0 : _ba.toString().toLowerCase().includes("hyper"))) {
503
+ if (((_ba = productName == null ? void 0 : productName.val) == null ? void 0 : _ba.toString().toLowerCase().includes("solarflow")) || ((_ca = productName == null ? void 0 : productName.val) == null ? void 0 : _ca.toString().toLowerCase().includes("ace")) || ((_da = productName == null ? void 0 : productName.val) == null ? void 0 : _da.toString().toLowerCase().includes("hyper"))) {
498
504
  (0, import_adapterService.updateSolarFlowControlState)(
499
505
  adapter,
500
506
  productKey,
@@ -504,7 +510,7 @@ const onMessage = async (topic, message) => {
504
510
  );
505
511
  }
506
512
  }
507
- if (((_ca = obj.properties) == null ? void 0 : _ca.gridInputPower) != null && ((_da = obj.properties) == null ? void 0 : _da.gridInputPower) != void 0) {
513
+ if (((_ea = obj.properties) == null ? void 0 : _ea.gridInputPower) != null && ((_fa = obj.properties) == null ? void 0 : _fa.gridInputPower) != void 0) {
508
514
  (0, import_adapterService.updateSolarFlowState)(
509
515
  adapter,
510
516
  productKey,
@@ -513,7 +519,7 @@ const onMessage = async (topic, message) => {
513
519
  obj.properties.gridInputPower
514
520
  );
515
521
  }
516
- if (((_ea = obj.properties) == null ? void 0 : _ea.acMode) != null && ((_fa = obj.properties) == null ? void 0 : _fa.acMode) != void 0) {
522
+ if (((_ga = obj.properties) == null ? void 0 : _ga.acMode) != null && ((_ha = obj.properties) == null ? void 0 : _ha.acMode) != void 0) {
517
523
  (0, import_adapterService.updateSolarFlowState)(
518
524
  adapter,
519
525
  productKey,
@@ -529,7 +535,7 @@ const onMessage = async (topic, message) => {
529
535
  obj.properties.acMode
530
536
  );
531
537
  }
532
- if (((_ga = obj.properties) == null ? void 0 : _ga.hyperTmp) != null && ((_ha = obj.properties) == null ? void 0 : _ha.hyperTmp) != void 0) {
538
+ if (((_ia = obj.properties) == null ? void 0 : _ia.hyperTmp) != null && ((_ja = obj.properties) == null ? void 0 : _ja.hyperTmp) != void 0) {
533
539
  (0, import_adapterService.updateSolarFlowState)(
534
540
  adapter,
535
541
  productKey,
@@ -538,7 +544,7 @@ const onMessage = async (topic, message) => {
538
544
  obj.properties.hyperTmp / 10 - 273.15
539
545
  );
540
546
  }
541
- if (((_ia = obj.properties) == null ? void 0 : _ia.acOutputPower) != null && ((_ja = obj.properties) == null ? void 0 : _ja.acOutputPower) != void 0) {
547
+ if (((_ka = obj.properties) == null ? void 0 : _ka.acOutputPower) != null && ((_la = obj.properties) == null ? void 0 : _la.acOutputPower) != void 0) {
542
548
  (0, import_adapterService.updateSolarFlowState)(
543
549
  adapter,
544
550
  productKey,
@@ -547,7 +553,7 @@ const onMessage = async (topic, message) => {
547
553
  obj.properties.acOutputPower
548
554
  );
549
555
  }
550
- if (((_ka = obj.properties) == null ? void 0 : _ka.gridPower) != null && ((_la = obj.properties) == null ? void 0 : _la.gridPower) != void 0) {
556
+ if (((_ma = obj.properties) == null ? void 0 : _ma.gridPower) != null && ((_na = obj.properties) == null ? void 0 : _na.gridPower) != void 0) {
551
557
  (0, import_adapterService.updateSolarFlowState)(
552
558
  adapter,
553
559
  productKey,
@@ -556,8 +562,8 @@ const onMessage = async (topic, message) => {
556
562
  obj.properties.gridPower
557
563
  );
558
564
  }
559
- if (((_ma = obj.properties) == null ? void 0 : _ma.acSwitch) != null && ((_na = obj.properties) == null ? void 0 : _na.acSwitch) != void 0) {
560
- const value = ((_oa = obj.properties) == null ? void 0 : _oa.acSwitch) == 0 ? false : true;
565
+ if (((_oa = obj.properties) == null ? void 0 : _oa.acSwitch) != null && ((_pa = obj.properties) == null ? void 0 : _pa.acSwitch) != void 0) {
566
+ const value = ((_qa = obj.properties) == null ? void 0 : _qa.acSwitch) == 0 ? false : true;
561
567
  (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "acSwitch", value);
562
568
  (0, import_adapterService.updateSolarFlowControlState)(
563
569
  adapter,
@@ -567,8 +573,8 @@ const onMessage = async (topic, message) => {
567
573
  value
568
574
  );
569
575
  }
570
- if (((_pa = obj.properties) == null ? void 0 : _pa.dcSwitch) != null && ((_qa = obj.properties) == null ? void 0 : _qa.dcSwitch) != void 0) {
571
- const value = ((_ra = obj.properties) == null ? void 0 : _ra.dcSwitch) == 0 ? false : true;
576
+ if (((_ra = obj.properties) == null ? void 0 : _ra.dcSwitch) != null && ((_sa = obj.properties) == null ? void 0 : _sa.dcSwitch) != void 0) {
577
+ const value = ((_ta = obj.properties) == null ? void 0 : _ta.dcSwitch) == 0 ? false : true;
572
578
  (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "dcSwitch", value);
573
579
  (0, import_adapterService.updateSolarFlowControlState)(
574
580
  adapter,
@@ -578,7 +584,7 @@ const onMessage = async (topic, message) => {
578
584
  value
579
585
  );
580
586
  }
581
- if (((_sa = obj.properties) == null ? void 0 : _sa.dcOutputPower) != null && ((_ta = obj.properties) == null ? void 0 : _ta.dcOutputPower) != void 0) {
587
+ if (((_ua = obj.properties) == null ? void 0 : _ua.dcOutputPower) != null && ((_va = obj.properties) == null ? void 0 : _va.dcOutputPower) != void 0) {
582
588
  (0, import_adapterService.updateSolarFlowState)(
583
589
  adapter,
584
590
  productKey,
@@ -587,11 +593,11 @@ const onMessage = async (topic, message) => {
587
593
  obj.properties.dcOutputPower
588
594
  );
589
595
  }
590
- if (((_ua = obj.properties) == null ? void 0 : _ua.pvBrand) != null && ((_va = obj.properties) == null ? void 0 : _va.pvBrand) != void 0) {
591
- const value = ((_wa = obj.properties) == null ? void 0 : _wa.pvBrand) == 0 ? "Others" : ((_xa = obj.properties) == null ? void 0 : _xa.pvBrand) == 1 ? "Hoymiles" : ((_ya = obj.properties) == null ? void 0 : _ya.pvBrand) == 2 ? "Enphase" : ((_za = obj.properties) == null ? void 0 : _za.pvBrand) == 3 ? "APSystems" : ((_Aa = obj.properties) == null ? void 0 : _Aa.pvBrand) == 4 ? "Anker" : ((_Ba = obj.properties) == null ? void 0 : _Ba.pvBrand) == 5 ? "Deye" : ((_Ca = obj.properties) == null ? void 0 : _Ca.pvBrand) == 6 ? "Bosswerk" : "Unknown";
596
+ if (((_wa = obj.properties) == null ? void 0 : _wa.pvBrand) != null && ((_xa = obj.properties) == null ? void 0 : _xa.pvBrand) != void 0) {
597
+ const value = ((_ya = obj.properties) == null ? void 0 : _ya.pvBrand) == 0 ? "Others" : ((_za = obj.properties) == null ? void 0 : _za.pvBrand) == 1 ? "Hoymiles" : ((_Aa = obj.properties) == null ? void 0 : _Aa.pvBrand) == 2 ? "Enphase" : ((_Ba = obj.properties) == null ? void 0 : _Ba.pvBrand) == 3 ? "APSystems" : ((_Ca = obj.properties) == null ? void 0 : _Ca.pvBrand) == 4 ? "Anker" : ((_Da = obj.properties) == null ? void 0 : _Da.pvBrand) == 5 ? "Deye" : ((_Ea = obj.properties) == null ? void 0 : _Ea.pvBrand) == 6 ? "Bosswerk" : "Unknown";
592
598
  (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "pvBrand", value);
593
599
  }
594
- if (((_Da = obj.properties) == null ? void 0 : _Da.inverseMaxPower) != null && ((_Ea = obj.properties) == null ? void 0 : _Ea.inverseMaxPower) != void 0) {
600
+ if (((_Fa = obj.properties) == null ? void 0 : _Fa.inverseMaxPower) != null && ((_Ga = obj.properties) == null ? void 0 : _Ga.inverseMaxPower) != void 0) {
595
601
  (0, import_adapterService.updateSolarFlowState)(
596
602
  adapter,
597
603
  productKey,
@@ -600,7 +606,7 @@ const onMessage = async (topic, message) => {
600
606
  obj.properties.inverseMaxPower
601
607
  );
602
608
  }
603
- if (((_Fa = obj.properties) == null ? void 0 : _Fa.wifiState) != null && ((_Ga = obj.properties) == null ? void 0 : _Ga.wifiState) != void 0) {
609
+ if (((_Ha = obj.properties) == null ? void 0 : _Ha.wifiState) != null && ((_Ia = obj.properties) == null ? void 0 : _Ia.wifiState) != void 0) {
604
610
  (0, import_adapterService.updateSolarFlowState)(
605
611
  adapter,
606
612
  productKey,
@@ -609,7 +615,7 @@ const onMessage = async (topic, message) => {
609
615
  obj.properties.wifiState == 1 ? "Connected" : "Disconnected"
610
616
  );
611
617
  }
612
- if (((_Ha = obj.properties) == null ? void 0 : _Ha.packNum) != null && ((_Ia = obj.properties) == null ? void 0 : _Ia.packNum) != void 0) {
618
+ if (((_Ja = obj.properties) == null ? void 0 : _Ja.packNum) != null && ((_Ka = obj.properties) == null ? void 0 : _Ka.packNum) != void 0) {
613
619
  (0, import_adapterService.updateSolarFlowState)(
614
620
  adapter,
615
621
  productKey,
@@ -618,7 +624,7 @@ const onMessage = async (topic, message) => {
618
624
  obj.properties.packNum
619
625
  );
620
626
  }
621
- if (((_Ja = obj.properties) == null ? void 0 : _Ja.hubState) != null && ((_Ka = obj.properties) == null ? void 0 : _Ka.hubState) != void 0) {
627
+ if (((_La = obj.properties) == null ? void 0 : _La.hubState) != null && ((_Ma = obj.properties) == null ? void 0 : _Ma.hubState) != void 0) {
622
628
  (0, import_adapterService.updateSolarFlowState)(
623
629
  adapter,
624
630
  productKey,