Hi,
I’ve seen a few old posts asking this question, sort of. But no relevant solutions.
I am creating a widget that populates various fields based on a single item.
This is a light widget that can control a number of different light types: on/off only, CCT, RGBWW, some have illuminance threshold and motion on/off controls, some have auto off timers etc etc.
“Lamp” is the only prop that is set.
Then various list-items and sliders etc use an expression similar to
=props.lightItem + "_Brightness"
This is working well and everything is doing the right thing.
The problem I have is that there are various parts that will only sometimes have an item to refer to.
I think this is slowing down the page load where I have 14 of these widgets. Feels like it is fully searching everything before erroring, and my log is filled with all the items that cannot be referred to. Everything is snappy and functional once loaded.
When you create a new widget, the default code has an example that checks if a prop is present,
title: '=(props.item) ? "prop exists " : "prop doesn't exist"'
But I can’t make it work when referring to an item that isn’t a defined prop. The following (and variations that I tried) doesn’t work
title: '=(items[props.lightItem + "_Brightness"]) ? "item exists " : "item doesn't exist"'
I could probably solve this by having more things to set in the props, but I really like how the entire widget functions with just one reference to the main light item.
Any ideas??