Raspberry Pi 3 with openhabian
I’m trying to use the simplified access to the ItemSemantics in openhab-js 4.2.1, trying to retrieve the location of a triggering Item;
var it = items[event.itemName]
Unfortunately, this produces an error:
2023-04-24 12:35:06.281 [INFO ] [enhab.automation.script.ui.appliance] - 4.2.1
org.graalvm.polyglot.PolyglotException: TypeError: items.getItem is not a function
at <js>.get location(/etc/openhab/automation/js/node_modules/openhab/items/item-semantics.js:109) ~[?:?]
at <js>.:program(<eval>:3) ~[?:?]
It’s probably a stupid mistake on my side, but I somehow thought, that openhab-js has taken away the need to access the rawItem in order to collect the semantic information.
It’s not quite so bad to return the name instead of the Item. Once the user has the name they can use items to get access to the Item if they need it. It’s an extra step but at least we don’t need to mess with the raw Java Item.
I’m not sure the impact of moving the semantics stuff to the items.js file. That file is already over 600 lines long, what another 122?
Instead of importing items, could we pass it in the constructor to ItemSemantics?
I haven’t checked this one, but I suppose the same issue exists for items[event.itemName].semantics.equipment
When do you think, this feature will be included in the next openhab-js version?
It’s already coded and merged into main. A new version of the library hasn’t been released so you can either wait for the next point release or clone the main branch of the openhab-js repo and put that in the $OH_CONF/automation/js/node-modules folder (you’ll need to remember to remove it once the release does occur, it’s better to use the built in library most of the time).