Get category in Blockly I do not get the Category but undefinded

Hi everyone,

I am using Blockly to create a rule in openHAB 5.1.1

I am using a loop to go through a list of items retrieved by tags. Within the loop, I am trying to access the category of the item. While the item itself is found correctly, the category block (which translates to .category in the generated code) returns undefined even if the object before showed a content in the property.

Thanks for helping
/Franz

myTriggeredChannelList = event.channelUID.split(':');
myButton = myTriggeredChannelList.slice(-1)[0];
myTriggeredChannelList.pop();
myLocation = String(things.getThing((myTriggeredChannelList.join(':'))).location);
mySearchTagLocation = String(myLocation) + 'Dimmer';
var myListItem_list = items.getItemsByTag(... (mySearchTagLocation.split(',').map(tagElement => tagElement.trim())));
for (var myListItem_index in myListItem_list) {
  myListItem = myListItem_list[myListItem_index];
  console.info(('item: ' + String(myListItem)));
  console.info(('itemCategory: ' + String(myListItem.category)));
}

Hi,
I don’t know the cause, but you can query the category/icon property with rawItem.Category. Use the inline_script block for this

console.info(myListItem.rawItem.Category.toString());
1 Like

Looking at the docs, there doesn’t appear to be a .category on the Item. I don’t know if it’s been removed for some reason or if it was never there and Blockly added this call in error.

In the mean time you should use either tags, or metadata, or the inline script @Tschetan posted below instead.

And file an issue. I’m not sure the best place to do so though. Probably on openhab-js to add the category to the Item.

Hi @rlkoshak ,

thanks a lot for your quick reply…

I‘m not sure. If you take a look at the screenshot in the right side you see that there is marked in red that the item contains this attribute.
So there seems to be a different issue with it.

@rlkoshak ok, I’ve created an issue for openhab-js

@stefan.hoehn: Also for you as info as it is was more or less detected while using blockly

1 Like

I did see that. But you’ll see in the docs that it’s not mentioned. JavaScript Scripting - Automation | openHAB. And if you look at the documentation of the Item class it’s not listed as a data member. Item - openHAB JS.

Finally, if you look at the code for the Item class, in particular the toString() method you’ll see that it returns the toString from the rawItem, meaning the original Java Item, and not the JS wrapped version of the Item. So what you see in the toString doesn’t reflect the members of the actual JS Item class.

  toString () {
    return this.rawItem.toString();
  }

I’d have to go through the history of the code to see if it ever was there, but it’s definitely not there now.

1 Like