Martin-Gleiss / smartvisu

smartVISU is a framework to create a visualisation for a knx-installation with simple html-pages. To read and write group-telegramms special tags are used.
http://www.smartvisu.de
GNU General Public License v3.0
101 stars 103 forks source link

no values ​​displayed in widget status.log and status.activelist with ioBroker #735

Closed uwe5 closed 2 years ago

uwe5 commented 2 years ago

Wenn ich status.log oder status.activelist verwenden möchte, funktioniert dies nicht mit den ioBroker Treiber. Ich habe folgende Lösung gefunden:

in der Datei io_iobroker.js dies geändert:

stateChanged: function(item, state) {
    if (state === null || typeof state !== 'object') return;
    var val = state.val;
    // convert boolean
    if (val === false) 
        val = 0;
    if (val === true) 
        val = 1;
        // convert jsonarray        
        if (val &&
        typeof val === 'string' &&
        val.length > 4 &&
        val[0] === '[' &&
        val[1] === '{' &&
        val[val.length - 2] === '}' &&
        val[val.length - 1] === ']') {
        try {
            val = JSON.parse(val);
        } catch (e) {
            console.log('Command seems to be an object, but cannot parse it: ' + val);
        }
        }        

    widget.update(item, val);
},

Ich weis aber nicht ob dies Seitenefekte auf andere Widgets hat, in meinem Setup läuft es, benutze allerdings nicht alle SmartVisu-Widgets.

Wäre schön wenn die nächste SmartVisu Version status.log und status.activelist mit ioBroker unterstützt.

wvhn commented 2 years ago

Thanks for the contribution. Before I integrate this into the driver I ask you to test a simplified code which allows list items (arrays) to be parsed, as well. List items are needed e.g. for dynamic select menus. JSON.parse can handle both objects and arrays:

stateChanged: function(item, state) {
    if (state === null || typeof state !== 'object') return;
        var val = state.val;

    // convert boolean
    if (val === false) 
        val = 0;
    if (val === true) 
        val = 1;

    // numbers get converted in widget.update -> no need to do it here

    // text needs no conversion

    // convert arrays and JSON arrays        
    if (val &&
        typeof val === 'string' &&
        val[0] === '[' &&
        val[val.length - 1] === ']') {
        try {
             val = JSON.parse(val);
        } catch (e) {
            console.log('Data seems to be an array, but cannot parse it: ' + val);
        }
    }       
    widget.update(item, val);
},
uwe5 commented 2 years ago

Änderung funktioniert super!

{{ status.activelist('', '0_userdata.0.activelist', 'headline', 'date', 'message', 'flag') }} 0_userdata.0.activelist = [{"color":"#660000","icon":"fts_window_1w_open","headline":"Fenster offen, Batterie 75%", "date":"ab 28.06.2022 08:23 Uhr","message":"Bitte schließen"},{"color":"#006600","icon":"fts_window_1w", "headline":"Fenster zu, Batterie 75%", "date":"ab 27.06.2022 10:22 Uhr","message":"alles Ok"}]

und bei {{ basic.select('', '0_userdata.0.basicselectitem', '', '', '', '', '', '', '0_userdata.0.basicselectitemvals', '0_userdata.0.basicselectitemtxts') }} item = 1 itemvals = ["1","2","3"] itemtxts = ["eins","zwei","drei"]

image

wvhn commented 2 years ago

Cool. Danke. Ich nehme das in den develop branch. Closed with #737