Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createState() in "0_userdata.0" overwrites existing state #597

Closed
BoehserWolf opened this issue Jun 6, 2020 · 8 comments
Closed

createState() in "0_userdata.0" overwrites existing state #597

BoehserWolf opened this issue Jun 6, 2020 · 8 comments

Comments

@BoehserWolf
Copy link

A user created state in "0_userdata.0" with createState() gets overwritten on next script restart although state already exists. The forceCreate parameter may implicitely be set or exclicitely be set to false - no change in behaviour.

This is confirmed with JS-controller 2.2.9 and 4.6.17 (see forum thread).

Test script to confirm:
`createState(
'0_userdata.0.test.state1',
{name: 'test state1'},
function() { log('created'); });

createState(
'0_userdata.0.test.state2',
0,
false, // force
{name: 'test state2'},
function() { log('created (force:false)'); });
`

Run script once to create the states. Run script next time(s) to confirm states being overwritten.

@paul53
Copy link
Contributor

paul53 commented Jun 7, 2020

sandbox.js, Zeile 1842: Kann man Datenpunkte unter "0_userdata.0" mit adapter.getObject() prüfen ?

@paul53
Copy link
Contributor

paul53 commented Jun 7, 2020

Ich würde Zeilen 1842 bis 1916 ersetzen durch (bitte prüfen):
`

        let id = adapter.namespace + '.' + name;
        if (name.match(/^javascript\.\d+\./) || name.startsWith('0_userdata.0.')) {
            id = name;
        }

        adapter.getForeignObject(id, function (err, obj) {
            if (err || !obj || forceCreation) {
                // todo: store object in objects to have this object directly after callback
                // create new one
                adapter.setForeignObject(id, {
                    common: common,
                    native: native,
                    type:   'state'
                }, function (err) {
                    err && adapter.log.warn('Cannot set object "' + id + '": ' + err);

                    if (initValue !== undefined) {
                        if (isObject(initValue) && initValue.ack !== undefined) {
                            adapter.setForeignState(id, initValue, callback);
                        } else {
                            adapter.setForeignState(id, initValue, true, callback);
                        }
                    } else if (!forceCreation) {
                        adapter.setForeignState(id, null, true, callback);
                    } else {
                        if (typeof callback === 'function') {
                            try {
                                callback.call(sandbox, id);
                            } catch (e) {
                                errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
                            }
                        }
                    }
                });
            } else {
                if (!adapter.config.subscribe && !states[id]) {
                    states[id] = {val: null, ack: true};
                }
                // state yet exists
                if (typeof callback === 'function') {
                    try {
                        callback.call(sandbox, id);
                    } catch (e) {
                        errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
                    }
                }
            }
        });

`

@Apollon77
Copy link
Contributor

Hm ... ja sowas in der Art ... muss nochmal genau drüber nachdenken.

@Apollon77
Copy link
Contributor

Bitte in Javascript 4.6.19 versuchen

@paul53
Copy link
Contributor

paul53 commented Jul 26, 2020

Ist in Javascript 4.6.19 nicht behoben.

@Apollon77
Copy link
Contributor

Ok, JETZT hab ichs verstanden :-) 4.6.20 incoming

@paul53
Copy link
Contributor

paul53 commented Jul 26, 2020

Funktioniert in Version 4.6.20

@Apollon77
Copy link
Contributor

Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants