Skip to content

Commit

Permalink
parse faultStr on the UI, so that the user does not need to read JSON…
Browse files Browse the repository at this point in the history
… encoded text
  • Loading branch information
yankee42 committed Feb 8, 2022
1 parent 2c6e9b6 commit 673a708
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions web/status/processAllMqttMsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
* @author Lena Kümmel
*/

function formatJsonString(str) {
try {
parsed = JSON.parse(str)
if (typeof parsed === 'string') {
return parsed
}
// if it is not a string, we just use the json as supplied
} catch (e) {
// ignore error - just use the original text
}
return str
}

function getIndex(topic) {
// get occurrence of numbers between / / in topic
// since this is supposed to be the index like in openwb/lp/4/w
Expand Down Expand Up @@ -118,7 +131,7 @@ function processEvuMsg (mqttmsg, mqttpayload) {
setWarningLevel(mqttpayload, '#faultStrEvuRow');
break;
case "openWB/evu/faultStr":
textShow(mqttpayload, '#faultStrEvu');
textShow(formatJsonString(mqttpayload), '#faultStrEvu');
break;
}
}
Expand Down Expand Up @@ -154,7 +167,7 @@ function processPvMsg (mqttmsg, mqttpayload) {
}
else if ( mqttmsg.match(/^openWB\/pv\/[0-9]+\/faultStr$/i) )
{
textShow(mqttpayload, '#inverter' + index + ' .faultStrPv');
textShow(formatJsonString(mqttpayload), '#inverter' + index + ' .faultStrPv');
}
else if ( mqttmsg.match(/^openWB\/pv\/[0-9]+\/boolPVConfigured$/i) )
{
Expand Down Expand Up @@ -209,7 +222,7 @@ function processBatMsg (mqttmsg, mqttpayload) {
setWarningLevel(mqttpayload, '#faultStrBatRow');
break;
case "openWB/housebattery/faultStr":
textShow(mqttpayload, '#faultStrBat');
textShow(formatJsonString(mqttpayload), '#faultStrBat');
break;
}
}
Expand Down Expand Up @@ -296,13 +309,13 @@ function processLpMsg (mqttmsg, mqttpayload) {
setWarningLevel(mqttpayload, '#lp' + index + ' .faultStrLpRow');
}
else if ( mqttmsg.match( /^openwb\/lp\/[1-9][0-9]*\/faultStr$/i ) ) {
textShow(mqttpayload, '#lp' + index + ' .faultStrLp');
textShow(formatJsonString(mqttpayload), '#lp' + index + ' .faultStrLp');
}
else if ( mqttmsg.match( /^openwb\/lp\/[1-9][0-9]*\/socFaultState$/i ) ) {
setWarningLevel(mqttpayload, '#lp' + index + ' .faultStrSocLpRow');
}
else if ( mqttmsg.match( /^openwb\/lp\/[1-9][0-9]*\/socFaultStr$/i ) ) {
textShow(mqttpayload, '#lp' + index + ' .faultStrSocLp');
textShow(formatJsonString(mqttpayload), '#lp' + index + ' .faultStrSocLp');
}
else {
switch (mqttmsg) {
Expand Down Expand Up @@ -474,4 +487,4 @@ function visibilityCard(card, mqttpayload) {
}
}
}
}
}

0 comments on commit 673a708

Please sign in to comment.