Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StateDescription to Item #347

Open
wertzui opened this issue Jun 19, 2024 · 0 comments
Open

Add StateDescription to Item #347

wertzui opened this issue Jun 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@wertzui
Copy link

wertzui commented Jun 19, 2024

At the moment, Item in JS does not expose the StateDescription and especially the Options.

According to #109 (comment) it should be possible to add these through the items metadata which I have not tested, but it is at least not possible to retrieve them that way.

In my use case, I'm looking into items which are bound to a thing's channel that only allows a couple of strings as values (like an enum).
Examples are the list of available apps in the lgwebos binding, or the allowedStates in a channel of the mqtt binding.
These allowed states are exposed in the item through the getStateDescription().options list.

A workaround at the moment is to get the raw item like below:

const { items, logm, utils} = require("openhab");
const logger = log("Scratchpad");

const itemName = "LivingRoomTvApplication";
const item = items.getItem(itemName);
const rawItem = item.rawItem;
const stateDescription = rawItem.getStateDescription();
const options = stateDescription.options;
options.forEach(option => {
    const label = option.getLabel();
    const value = option.getValue();
    logger.info(`Label: ${label}, Value: ${value}`);
});
@wertzui wertzui added the enhancement New feature or request label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant