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

No way to determine a null value in existing State without Warning #519

Closed
Pittini opened this issue Mar 10, 2020 · 11 comments
Closed

No way to determine a null value in existing State without Warning #519

Pittini opened this issue Mar 10, 2020 · 11 comments
Labels

Comments

@Pittini
Copy link

Pittini commented Mar 10, 2020

I have an existing state, but no value, so .val= null and .notexist=true.

Inked2020-03-10 15_48_46-objects - ioBroker_LI

If i try to determine there is an value or not i use getState() like this:

let MTDummy = getState(hcpraefix + "Rooms." + ChoosenRoom + "." + "MinimumTemperature"); if (MTDummy.val != null) { //Prüfen ob Minimum Temp Null ist setState(praefix + "RoomValues." + "MinimumTemperature", getState(hcpraefix + "Rooms." + ChoosenRoom + "." + "MinimumTemperature").val); } else { log("MinimumTemp=Null, skipping entry"); };

This works, but causes a long warning like that:

`javascript.0 2020-03-10 15:38:36.099 warn (1426) at process._tickCallback (internal/process/next_tick.js:68:7)
javascript.0 2020-03-10 15:38:36.099 warn (1426) at promise.then (/opt/iobroker/node_modules/standard-as-callback/built/index.js:19:49)
javascript.0 2020-03-10 15:38:36.099 warn (1426) at tryCatcher (/opt/iobroker/node_modules/standard-as-callback/built/utils.js:11:23)
javascript.0 2020-03-10 15:38:36.098 warn (1426) at (anonymous function).(anonymous function) (/opt/iobroker/node_modules/iobroker.objects-redis/index.js:17:71697)
javascript.0 2020-03-10 15:38:36.098 warn (1426) at /opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1976:42
javascript.0 2020-03-10 15:38:36.098 warn (1426) at Object. (script.js.common.HeatingControlVis:158:13)
javascript.0 2020-03-10 15:38:36.098 warn (1426) at main (script.js.common.HeatingControlVis:172:5)
javascript.0 2020-03-10 15:38:36.098 warn (1426) at SetVis (script.js.common.HeatingControlVis:306:19)
javascript.0 2020-03-10 15:38:36.098 warn (1426) getState "heatingcontrol.0.Rooms.Toilette.MinimumTemperature" not found (3) states[id]=null`

I think, there should be an possibility to dertermine the state without warning.

@AlCalzone
Copy link
Collaborator

Seems to work for me:

log(JSON.stringify(getState("tradfri.0.G-131074.color")))

Log:

javascript.0 | 2020-03-10 18:19:03.521 | info | (900) script.js.Test: registered 0 subscriptions and 0 schedules
javascript.0 | 2020-03-10 18:19:03.520 | info | (900) script.js.Test:  {"val":null,"ack":true,"ts":1583130636115,"q":0,"from":"system.adapter.tradfri.0","user":"system.user.admin","lc":1569347682113}
javascript.0 | 2020-03-10 18:18:51.179 | info | (900) Start javascript script.js.Test

Which adapter version do you use?

@Pittini
Copy link
Author

Pittini commented Mar 10, 2020

Adapter is 4.4.2

And no, doesnt works here, look:
Inked2020-03-10 18_52_21-javascript - ioBroker_LI

And here the corresponding log:
`

avascript.0 2020-03-10 18:51:16.254 warn (1426) at processImmediate (timers.js:658:5)
javascript.0 2020-03-10 18:51:16.254 warn (1426) at tryOnImmediate (timers.js:676:5)
javascript.0 2020-03-10 18:51:16.254 warn (1426) at runCallback (timers.js:705:18)
javascript.0 2020-03-10 18:51:16.254 warn (1426) at Immediate.setImmediate (/opt/iobroker/node_modules/iobroker.js-controller/lib/adapter.js:4851:37)
javascript.0 2020-03-10 18:51:16.253 warn (1426) at Object.stateChange (/opt/iobroker/node_modules/iobroker.javascript/main.js:450:25)
javascript.0 2020-03-10 18:51:16.253 warn (1426) at Object.callback (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1122:38)
javascript.0 2020-03-10 18:51:16.253 warn (1426) at Object. (script.js.common.HeatingControlVis:404:9)
javascript.0 2020-03-10 18:51:16.253 warn (1426) at SetVis (script.js.common.HeatingControlVis:307:25)
javascript.0 2020-03-10 18:51:16.253 warn (1426) getState "heatingcontrol.0.Rooms.Werkstatt.MinimumTemperature" not found (3) states[id]=null

`

@GermanBluefox
Copy link
Contributor

If state does not exist, you will get warning, like by Pittini. If state exists, but the value is null, no warning will be generated, like by AlCalzone

@AlCalzone
Copy link
Collaborator

Was the state maybe created after the script adapter was started? In that case, it could be the caching issue #109

@Apollon77
Copy link
Contributor

existsState should exist in current versions as method to check a state
But missing in docs!!

@Pittini
Copy link
Author

Pittini commented Mar 11, 2020

Was the state maybe created after the script adapter was started? In that case, it could be the caching issue #109

No the state is some month old.

@Pittini
Copy link
Author

Pittini commented Mar 11, 2020

existsState works fine, thats the solution for me.
If the behaviour with getState now is an Issue or not, is your decision

@AlCalzone
Copy link
Collaborator

I think the problem is:
The state does really not exist (i.e. there is no object, which is what existsState checks). But you have a null value for it, which is why the admin shows it.
If that is the case, the behavior is correct IMO.

@Pittini
Copy link
Author

Pittini commented Mar 11, 2020

The state does really not exist (i.e. there is no object, which is what existsState checks). But you have a null value for it, which is why the admin shows it.

I don't know what exactly is going on there. The Dp was generated from the HeatingControl Adapter, maybe you can take a look in the code to adress the problem better.

@GermanBluefox
Copy link
Contributor

I don't understand why you check non existing state and wondering about, that it does not exist?

The long warning is because you trying to get an attribute of null object.
If you will change your script to:

let MTDummy = getState(hcpraefix + "Rooms." + ChoosenRoom + "." + "MinimumTemperature"); 
if (MTDummy && MTDummy.val != null) { //Prüfen ob Minimum Temp Null ist 
    setState(praefix + "RoomValues." + "MinimumTemperature", getState(hcpraefix + "Rooms." + ChoosenRoom + "." + "MinimumTemperature").val); 
} else { 
    log("MinimumTemp=Null, skipping entry"); 
}

You will get only 2 warning:

getState "heatingcontrol.0.Rooms.Werkstatt.MinimumTemperature" not found (3) states[id]=null
MinimumTemp=Null, skipping entry

@Pittini
Copy link
Author

Pittini commented Mar 22, 2020

Can be closed, the Problem was an misconfigured state from the Heatingcontrol Adapter. After fixing, my code works as it should.
https://github.com/rg-engineering/ioBroker.heatingcontrol/issues/84

and the similar problem here:
https://github.com/rg-engineering/ioBroker.heatingcontrol/issues/86
and here
https://github.com/rg-engineering/ioBroker.heatingcontrol/issues/87

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

No branches or pull requests

4 participants