Closed ThaDaVos closed 3 weeks ago
Maybe this should be moved to a feature request - as it's apparently by design: https://www.openhab.org/docs/ui/building-pages.html#dynamically-configuring-components-with-expressions
It is by design. The devs have put a lot of work in to minimize the amount of information that has to be passed back and forth between the server and the UI in order to maintain UI responsiveness.
The widgets really shouldn't need to be able to run a full javascript engine. If you're doing something that computationally intensive, offload the work to a rule that stores the result in an item, and just use the item the UI.
As for quantity types, just handle them with a simple string -> number conversion and then perform whatever unit manipulation you want manually, that's a far lower impact on the widget resources.
The only thing I want to add is that the JS environment that runs in OH rules/transformations is completely and wholly separate and independent from the JS environment that executes in your web browser to execute the widgets.
In this case, the Item
class in the JS Scripting add-on's helper library has direct access to the Java Item class provided by openHAB. It can have that access because it runs on the server. All that is available in the UI is what gets to it through the REST API.
What I meant more was, instead of the whole api - you could include the two properties numericState and quantityState just as displayState is added already - why? Simply to not have to parse the string to a number for example - doing that a lot can also cause a slow down
Simply to not have to parse the string to a number for example - doing that a lot can also cause a slow down
Based on experience and experiments, even adding displayState
was a stretch. In fact, even if you have a State Description Pattern, displayState
will only be there if it's different from state
. Even just adding displayState
every time adds too much load. Adding two new fields would be beyond what can be supported I would think.
I don't get why it's such a load? I build Vue based apps for work - loading JSON with thousands of properties and nested objects and the page experience still smooth - so how could adding two properties increase the UI load so much? Or is it the Server side you're talking about?
I don't which side but as I understand it is the load in handling and process the event stream.
I don't get why it's such a load? I build Vue based apps for work - loading JSON with thousands of properties and nested objects and the page experience still smooth - so how could adding two properties increase the UI load so much?
Item states are sent from the server to the UI over an SSE stream, which has to be processed by the UI. Every new property adds some weight to the processing of that event stream and also requires some more bandwidth — the question is how much.
Let me comment on the two requested properties:
quantityState
: Impossible to add, because the Quantity
class is part of the JS Scripting helper library and is wrapping openHAB‘s Java QuantityType. Both are not available in the browser.
numericState
: Could be added by modifying the processing of the event stream inside the UI, however trying to parse a number from every new pushed state may create some load (you could attempt it only for some types to improve that behaviour).
@ghys WDYT?
Closing as numericState
has been added meanwhile and quantityState
cannot be added, see my explanation above.
Please use a state description pattern to convert the displayState
to the required unit you want to show.
The problem
It seems that when working on the widgets, they do not support the
.numericState
and.quantityState
options of the items (maybe many more new properties) - I thought they did as it could remedy the old ugly check.displayState
and then check.state
code - but.numericState
always returns undefinedChecking the item returned from
items
gives only thestate
andtype
values (see second screenshot belowExpected behavior
Or full Javascript support - or at least access to these new properties to ease the creation of Widgets now we have UoM
Steps to reproduce
.numericState
inside theWidgets Expression Tester
for a UoM used itemYour environment
Browser console
Browser network traffic
Additional information