seit der Umstellung auf admin 5.1.23 und js aktuell wirft mir dein Skript Fehler ins LOG.
2021-08-23 08:28:06.911 - warn: javascript.0 (17826) Read-only state "javascript.0.LogParser.LogParser_Warn_JSONzuHTML" has been written without ack-flag with value "
Aktuelles Skript von dir:
/******************************************************************************************************
* JSON-Datenpunkt in HTML umwandeln
* --------------------------------------------------------------
* Zweck: Überwacht einen JSON-Datenpunkt und sobald geändert, wird JSON in HTML umgewandelt und
* in einem eigenen Datenpunkt ausgegeben
* Publiziert: https://forum.iobroker.net/topic/32540/json-zu-html-und-in-datei-schreiben-ablegen
* Autor: Mic-M (Github) | Mic (ioBroker)
* --------------------------------------------------------------------------------------
* Change Log:
* 0.0.1 Mic-M * Initial release
******************************************************************************************************/
/*********************************************************************************************
* Einstellungen
*********************************************************************************************/
// JSON-Datenpunkt
const g_jsonState = 'logparser.0.filters.Warn.json';
// Neuer Datenpunkt für HTML-Ausgabe
const g_htmlState = 'LogParser.LogParser_Warn_JSONzuHTML';
// Spalte entfernen (für Log Parser Adapter 'ts' nehmen, da dieser autmatisch den timestamp hinzufügt),
// sonst leer lassen
const g_removeColumn = 'ts';
/*********************************************************************************************
* Ab hier nichts mehr ändern
*********************************************************************************************/
main();
function main() {
// Create state for HTML, if not yet existing
createState(g_htmlState, {'name':'HTML Table', 'type':'string', 'read':true, 'write':false, 'role':'html', 'def':'' }, () => {
// State created, so let's subscribe to the given JSON state
on({id: g_jsonState, change:'ne'}, function(obj) {
// JSON state changed
if(obj.state.val && obj.state.val.length > 10) {
// state is not empty
const jsonObject = JSON.parse(obj.state.val);
if(g_removeColumn) {
for (let lpEntry of jsonObject) {
delete lpEntry[g_removeColumn];
}
}
setState(g_htmlState, json2table(jsonObject, ''));
}
});
});
}
/**
* Convert JSON to HTML table
* Source: https://travishorn.com/building-json2table-turn-json-into-an-html-table-a57cf642b84a
*
* @param {object} jsonObject The JSON as object.
* @param {string} [classes] Optional: You can apply one or multiple classes (space separated) to <table>.
* @return {string} The HTML result as string
*/
function json2table(jsonObject, classes = '') {
const cols = Object.keys(jsonObject[0]);
let headerRow = '';
let bodyRows = '';
classes = classes || '';
cols.map(function(col) {
headerRow += '<th>' + capitalizeFirstLetter(col) + '</th>';
});
jsonObject.map(function(row) {
bodyRows += '<tr>';
cols.map(function(colName) {
bodyRows += '<td>' + row[colName] + '</td>';
})
bodyRows += '</tr>';
});
const addClasses = (classes && classes.length > 1) ? ' class="' + classes + '"' : '';
return '<table' + addClasses + '><thead><tr>' +
headerRow +
'</tr></thead><tbody>' +
bodyRows +
'</tbody></table>';
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
}
@Mic Könntest du dir das vielleicht mal anschauen? Was müsste ich im Skript ändern?
Lieben Gruß und vielen Dank