Skip to content

addMetadata() not working with ItemName #534

Description

@LuiSauberhorn

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

  1. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting feedbackawaiting feedback from the issue authorbugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions