According to documentation, addMetadata(itemOrName, namespace, value, configurationopt, persistopt) → {ItemMetadata} should add metadata for an item, if itemOrName is the item or the item name. However, it only works for me if it is the item object.
Expected Behaviour
Both code snippets should lead to the same outcome. while option 1 seems to work in few cases (maybe wrong as I did a lot of debugging), options 2 always work:
Option 1:
const itemname = "testitem";
items.metadata.addMetadata(itemname, "TEST", "testvalue", null, true)
Option 2:
const itemname = "testitem";
const item = items.getItem(itemname);
items.metadata.addMetadata(item, "TEST", "testvalue", null, true)
Current Behaviour
Option 1 does not add metadata, while option 2 does.
Possible Solution
Make both work according to type of variable itemOrName. If it is a string, fetch the corresponding item.
Steps to Reproduce
- Execute code given above in a rule
Your Environment
- openHAB version: used (check Main UI -> About): 5.1.4.
- openhab-js version used (run
console.log('openhab-js ' + utils.OPENHAB_JS_VERSION) from a JS script): openhab-js 5.17.1
- Operating System and version (e.g. desktop or mobile, Windows 10, Raspbian Buster, ...): "Debian GNU/Linux 13 (trixie)
According to documentation, addMetadata(itemOrName, namespace, value, configurationopt, persistopt) → {ItemMetadata} should add metadata for an item, if itemOrName is the item or the item name. However, it only works for me if it is the item object.
Expected Behaviour
Both code snippets should lead to the same outcome. while option 1 seems to work in few cases (maybe wrong as I did a lot of debugging), options 2 always work:
Option 1:
Option 2:
Current Behaviour
Option 1 does not add metadata, while option 2 does.
Possible Solution
Make both work according to type of variable itemOrName. If it is a string, fetch the corresponding item.
Steps to Reproduce
Your Environment
console.log('openhab-js ' + utils.OPENHAB_JS_VERSION)from a JS script): openhab-js 5.17.1