If I want to create a widget like following (sample code from creating a new widget):
- name: prop1
label: Prop 1
description: A text prop
- name: item
description: An item to control
title: '=(props.item) ? "State of " + props.item : "Set props to test!"'
content: =items[props.item].displayState || items[props.item].state
How can I get access to the equipment item and the location item of “props.item” without manually configuring them?
I am looking for something like props.item.getLocation() or props.item.location …
I have not found something in the documentation or forum, but maybe looked at the wrong place
Thanks in advance for any hints
The short answer is that you can’t. That information is not part of the
items object that is passed to the widgets.
The long answer is that it is possible (but not trivial) using the
semantics metadata. To get an item with its metadata you have have that item returned by a repeater (which gets the full item information via an API call including any metadata you request using the
fetchMetadata property). The semantic metadata of a point will return then equipment name in a
isPointOf property then you would have to repeat the process on the equipment item to get the equipment’s
hasLocation semantic property.
Unless you have a very complex system in mind, the chances are good that you will spend less time just configuring a few widgets manually with the semantic info then developing and deploying a widget that will do all of this.
Thanks for clarification and context.
Maybe that’s something for the next version, to have this available similar to rules where we can do Semantics.getLocation(item) what I really like.
There would be a lot of positives in such a system, but it’s not a small ask.
A lot of time and effort has been spent minimizing the amount on information passed from the server to the UI in order to keep the UI light and responsive. Adding semantic information for every item would be simple but a huge increase in information, much of which would never get used so it would waste a lot of bandwidth and resources. Adding the information conditionally, might be possible but very complex.