I’m trying to add an oh-label-item component to a list that would change it’s icon and text based on the item it displays.
So far, I have two separte labels displaying power grid draw and supply, but as they are mutually exclusive I would rather display one label that switches it’s state depending on the values.
I can’t find a working syntax for the item (value) definition to display either the value from =props.senecHomeGridSupplyItem or =props.senecHomeGridDrawItem depending on the value of =props.senecHomeGridSupplyItem being > 0
The tite is displayed as undefined and not changing as exptected
I finally got it working.
The missing .state was a copy&paste mess, thanks for the hint!
The items I use for the comparison have a trailing ’ W’ so I needed to cut and parse them as well.
The final code below, FYI.
Is it possible to use variables here?
It looks quite messy to have the comparison for all these attributes
Since you are using Number.parseFloat to convert to a numerical value, you don’t need to worry about trimming off the unit, parseFloat will do that automatically for you.
No, you can’t do variable assignment in the widget expressions. However, if you are on the latest snapshot (or upgrade to the newest milestone when it comes out soon) there is a new shortcut you can use that cleans things up nicely. @@'itemName' will work in place of items[itemName].state, so you your case all you would need would be Number.parseFloat(@@props.senecHomeGridSupplyItem)