Jython -> JSScripting, isinstance and test if NULL, UnDefType

hi,

i have encountered more questions in my migration from jython to jsscripting and namely i cannot find a replacement for the following (OH 3.4.2, JSScripting Helper Library 4.0):

Jython:

if isinstance(item.state, UnDefType):
				events.sendCommand(item.name, "ON")

or

if isinstance(items[event.itemName], UnDefType):

Another questions, what is the best way to test for NULL?

JSScripting:

var Sonoff3 = items.getItem("Sonoff3_Temperatur").state

if (Sonoff3 === null) ....  
// or
if (Sonoff3 == "NULL") ....

Thanks a lot!

Always look to the docs. JavaScript Scripting - Automation | openHAB

if(items[event.itemName].isUninitialized) {

Again, per the reference docs for JS Scripting, which are really quite complete and comprehensive, the .state of an Item is always a String. So

if(Sonoff3 == 'NULL`) {

Note in openhab-js 4.0 there was added a better way to get at the Items. items['ItemName'] or items.ItemName both work. No more need to call items.getItem('ItemName').

openhab-js goes to great lengths to make it possible to say working completely with JavaScript Objects and types so it’s only rarely that you should need to do this. But if you really want the exact equivalence to this test above:

var {UnDefType} = require('@runtime'); // see https://next.openhab.org/docs/configuration/jsr223.html#scriptextension-objects-all-jsr223-languages for what's available in @runtime

...

  if(item.rawState instanceof UnDefType) {

or

var UnDefType = Java.type('org.openhab.core.library.types.UnDefType');

...

  if(item.rawState instanceof UnDefType) {

thank you, you are right, i need to read the doc more carefully. i have tried isUninitialized , my mistake was the brackets …


if (items.Chromecast_Audio2_albumName.isUninitialized()) {  ....

instead of

if (items.Chromecast_Audio2_albumName.isUninitialized) {  ....