Skip to content

Commit

Permalink
avoid crash
Browse files Browse the repository at this point in the history
  • Loading branch information
rg-engineering committed Dec 8, 2024
1 parent d7da097 commit 93b61f1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
6 changes: 3 additions & 3 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@
"lg": 4,
"xl": 4
},
"sendTo2": {
"sendTo2FindParameters": {
"type": "sendTo",
"label": "send It",
"label": "find paramter",
"variant": "outlined",
"showProcess": true,
"command": "findParams",
"jsonData": "{ \"${data.Circuit4Find}\"}",
"jsonData": "{ \"circuit\": \"${data.Circuit4Find}\"}",
"xs": 12,
"sm": 12,
"md": 6,
Expand Down
89 changes: 48 additions & 41 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function startAdapter(options) {
switch (obj.command) {
case "findParams":
// e.g. send email or pushover or whatever
adapter.log.debug("findParams command");
//adapter.log.debug("findParams command");
// Send response in callback if required
await FindParams(obj);
break;
Expand Down Expand Up @@ -1312,64 +1312,71 @@ async function FindParams(obj) {
const list = [];

try {
const circuit = obj.message;

const socket = new net.Socket();
const promiseSocket = new PromiseSocket(socket);
if (obj.message != null) {

await promiseSocket.connect(parseInt(adapter.config.targetTelnetPort), adapter.config.targetIP);
adapter.log.debug("telnet connected for cmd");
promiseSocket.setTimeout(5000);
const circuit = obj.message;

await promiseSocket.write("find -c " + circuit + " -F circuit,name\n");
const socket = new net.Socket();
const promiseSocket = new PromiseSocket(socket);

const data = await promiseSocket.read();
await promiseSocket.connect(parseInt(adapter.config.targetTelnetPort), adapter.config.targetIP);
adapter.log.debug("telnet connected for cmd");
promiseSocket.setTimeout(5000);

if (data.includes("ERR")) {
adapter.log.warn("received error! sent find, received " + data + " please check ebusd logs for details!");
}
else {
adapter.log.debug("received " + typeof data + " " + data);
}
/*
received object ehp,AccelerationTestModeehp,AccelerationTestModeehp,ActualEnvironmentPowerehp,ActualEnvironmentPowerehp,ActualEnvironmentPowerPercentageehp,ActualEnvironmentPowerPercentageehp,ApplianceCodeehp,ApplianceCodeehp,Backupehp,Backupehp,BackupHoursehp,BackupHoursHcehp,BackupHoursHwcehp,BackupHysteresisehp,BackupIntegralehp,BackupModeHcehp,BackupModeHwcehp,BackupPowerCutehp,BackupStartsehp,BackupStartsHcehp,BackupStartsHwcehp,BackupTypeehp,BivalentTempehp,Bleedingehp,Bleedingehp,CirPumpehp,CirPumpehp,Code1ehp,Code1Code2Validehp,Code2ehp,Compehp,Compehp,CompControlStateehp,CompCutPressHighCountehp,CompCutPressLowCountehp,CompCutTempCountehp,CompDemandehp,CompHoursehp,CompHoursHcehp,CompHoursHwcehp,CompHysteresisehp,CompIntegralehp,CompPressHighehp,CompPressHighehp,CompPressLowehp,CompPressLowehp,CompStartsehp,CompStartsHcehp,CompStartsHwcehp,CompStateehp,CondensorTempehp,CondensorTempehp,currenterrorehp,Dateehp,DateTimeehp,DeltaTempT6T7ehp,ElectricWiringDiagramehp,ElectricWiringDiagramehp,EnergyBalancingReleaseehp,errorhistoryehp,FlowTempehp,FlowTempehp,FlowtempCoolingMinehp,FlowTempOffsetehp,Hc1Pumpehp,Hc1Pumpehp,Hc1PumpHoursehp,Hc1PumpPortehp,Hc1PumpStartsehp,Hc2Pumpehp,Hc2PumpHoursehp,HcFlowTempehp,HcFlowTempOffsetehp,HcModeDemandHoursehp,HcModeFulfilledHoursehp,HcParallelStorageFillingEnabledehp,HcPressehp,HcReturnTempehp,HcReturnTempehp,HcReturnTempOffsetehp,HeatPumpStatusehp,HeatPumpStatusehp,HeatpumpTypeehp,HwcHcValveehp,HwcHcValveehp,HwcHcValveStartsehp,HwcLaggingTimeehp,HwcLoadingDelayehp,HwcModeDemandHoursehp,HwcModeFulfilledHoursehp,HwcPumpStartsehp,HwcSwitchehp,HwcTempehp,HwcTempehp,HwcTempOffsetehp,HydraulicSchemeehp,ICLOutehp,ICLOutehp,Injectionehp,Integralehp,Mixer1DutyCycleehp,NumberCompStartsehp,OutsideTempehp,OutsideTempOffsetehp,OverpressureThresholdehp,PhaseOrderehp,PhaseOrderehp,PhaseStatusehp,PhaseStatusehp,PowerCutehp,PowerCutPreloadingehp,PressSwitchehp,PressSwitchehp,RebootCounterehp,ReturnTempMaxehp,SetModeehp,SoftwareCodeehp,Source2PumpHoursehp,Sourceehp,Sourceehp,SourceHoursehp,SourcePortehp,SourcePressehp,SourcePumpPrerunTimeehp,SourceStartsehp,SourceSwitchehp,SourceSwitchehp,SourceTempInputehp,SourceTempInputehp,SourceTempInputOffsetehp,SourceTempOutputehp,SourceTempOutputehp,SourceTempOutputOffsetehp,SourceTempOutputT8Minehp,StateSoftwareCodeehp,StateSoftwareCodeehp,Status01ehp,Status02ehp,Status16ehp,Statusehp,StatusCirPumpehp,StorageTempBottomehp,StorageTempBottomehp,StorageTempBottomOffsetehp,StorageTempTopehp,StorageTempTopehp,StorageTempTopOffsetehp,Subcoolingehp,Superheatehp,T19MaxToCompOffehp,TempInputehp,TempInputehp,TempInputOffsetehp,TempOutputehp,TempOutputehp,TempOutputOffsetehp,Timeehp,TimeBetweenTwoCompStartsMinehp,TimeCompOffMinehp,TimeCompOnMinehp,TimeOfNextPredictedPowerCutehp,TimeOfNextPredictedPowerCutehp,Weekdayehp,YieldTotalehp,YieldTotal
*/
const str = new TextDecoder().decode(data);
const datas = str.split(/\r?\n/);
await promiseSocket.write("find -c " + circuit + " -F circuit,name\n");

for (let i = 0; i < datas.length; i++) {
const data = await promiseSocket.read();

//adapter.log.debug(JSON.stringify(datas[i]));
if (data.includes("ERR")) {
adapter.log.warn("received error! sent find, received " + data + " please check ebusd logs for details!");
}
else {
adapter.log.debug("received " + typeof data + " " + data);
}
/*
received object ehp,AccelerationTestModeehp,AccelerationTestModeehp,ActualEnvironmentPowerehp,ActualEnvironmentPowerehp,ActualEnvironmentPowerPercentageehp,ActualEnvironmentPowerPercentageehp,ApplianceCodeehp,ApplianceCodeehp,Backupehp,Backupehp,BackupHoursehp,BackupHoursHcehp,BackupHoursHwcehp,BackupHysteresisehp,BackupIntegralehp,BackupModeHcehp,BackupModeHwcehp,BackupPowerCutehp,BackupStartsehp,BackupStartsHcehp,BackupStartsHwcehp,BackupTypeehp,BivalentTempehp,Bleedingehp,Bleedingehp,CirPumpehp,CirPumpehp,Code1ehp,Code1Code2Validehp,Code2ehp,Compehp,Compehp,CompControlStateehp,CompCutPressHighCountehp,CompCutPressLowCountehp,CompCutTempCountehp,CompDemandehp,CompHoursehp,CompHoursHcehp,CompHoursHwcehp,CompHysteresisehp,CompIntegralehp,CompPressHighehp,CompPressHighehp,CompPressLowehp,CompPressLowehp,CompStartsehp,CompStartsHcehp,CompStartsHwcehp,CompStateehp,CondensorTempehp,CondensorTempehp,currenterrorehp,Dateehp,DateTimeehp,DeltaTempT6T7ehp,ElectricWiringDiagramehp,ElectricWiringDiagramehp,EnergyBalancingReleaseehp,errorhistoryehp,FlowTempehp,FlowTempehp,FlowtempCoolingMinehp,FlowTempOffsetehp,Hc1Pumpehp,Hc1Pumpehp,Hc1PumpHoursehp,Hc1PumpPortehp,Hc1PumpStartsehp,Hc2Pumpehp,Hc2PumpHoursehp,HcFlowTempehp,HcFlowTempOffsetehp,HcModeDemandHoursehp,HcModeFulfilledHoursehp,HcParallelStorageFillingEnabledehp,HcPressehp,HcReturnTempehp,HcReturnTempehp,HcReturnTempOffsetehp,HeatPumpStatusehp,HeatPumpStatusehp,HeatpumpTypeehp,HwcHcValveehp,HwcHcValveehp,HwcHcValveStartsehp,HwcLaggingTimeehp,HwcLoadingDelayehp,HwcModeDemandHoursehp,HwcModeFulfilledHoursehp,HwcPumpStartsehp,HwcSwitchehp,HwcTempehp,HwcTempehp,HwcTempOffsetehp,HydraulicSchemeehp,ICLOutehp,ICLOutehp,Injectionehp,Integralehp,Mixer1DutyCycleehp,NumberCompStartsehp,OutsideTempehp,OutsideTempOffsetehp,OverpressureThresholdehp,PhaseOrderehp,PhaseOrderehp,PhaseStatusehp,PhaseStatusehp,PowerCutehp,PowerCutPreloadingehp,PressSwitchehp,PressSwitchehp,RebootCounterehp,ReturnTempMaxehp,SetModeehp,SoftwareCodeehp,Source2PumpHoursehp,Sourceehp,Sourceehp,SourceHoursehp,SourcePortehp,SourcePressehp,SourcePumpPrerunTimeehp,SourceStartsehp,SourceSwitchehp,SourceSwitchehp,SourceTempInputehp,SourceTempInputehp,SourceTempInputOffsetehp,SourceTempOutputehp,SourceTempOutputehp,SourceTempOutputOffsetehp,SourceTempOutputT8Minehp,StateSoftwareCodeehp,StateSoftwareCodeehp,Status01ehp,Status02ehp,Status16ehp,Statusehp,StatusCirPumpehp,StorageTempBottomehp,StorageTempBottomehp,StorageTempBottomOffsetehp,StorageTempTopehp,StorageTempTopehp,StorageTempTopOffsetehp,Subcoolingehp,Superheatehp,T19MaxToCompOffehp,TempInputehp,TempInputehp,TempInputOffsetehp,TempOutputehp,TempOutputehp,TempOutputOffsetehp,Timeehp,TimeBetweenTwoCompStartsMinehp,TimeCompOffMinehp,TimeCompOnMinehp,TimeOfNextPredictedPowerCutehp,TimeOfNextPredictedPowerCutehp,Weekdayehp,YieldTotalehp,YieldTotal
*/
const str = new TextDecoder().decode(data);
const datas = str.split(/\r?\n/);

const names = datas[i].split(",");
for (let i = 0; i < datas.length; i++) {

//doppelte und leere herausfiltern
let add = true;
//adapter.log.debug(JSON.stringify(datas[i]));

if (names[0] == "" || names[1] == "") {
add = false;
}
else {
const names = datas[i].split(",");

//doppelte und leere herausfiltern
let add = true;

if (names[0] == "" || names[1] == "") {
add = false;
}
else {

for (let n = 0; n < list.length; n++) {
for (let n = 0; n < list.length; n++) {

if (list[n].circuit == names[0] && list[n].name == names[1]) {
add = false;
//already in list
if (list[n].circuit == names[0] && list[n].name == names[1]) {
add = false;
//already in list
}
}
}
}

if (add) {
const entry = {
active: false,
circuit: names[0],
name: names[1]
};
if (add) {
const entry = {
active: false,
circuit: names[0],
name: names[1]
};

list.push(entry);
list.push(entry);
}
}
}
else {
adapter.log.error("no circuit defined where to look for parameter, check values!");
}
} catch (e) {
adapter.log.error("exception in FindParams " + "[" + e + "]");
}
Expand Down

0 comments on commit 93b61f1

Please sign in to comment.