Hello,
I’m trying to simplify a custom MainUI widget in openHAB 5.x.
The widget itself is based on a standard list item, e.g. oh-toggle-item. I would like to use oh-context above it so I can define constants/functions once and reuse them in the list item’s expressions.
A minimal example:
version: 1
widgets:
test_context_toggle:
component: oh-context
config:
constants:
test: "'Hello'"
slots:
default:
- component: oh-toggle-item
config:
item: Location_Lamp_Switch
title: Test
subtitle: =const.test
The problem is that oh-toggle-item no longer renders as a normal list item when placed below oh-context.
By contrast, a plain oh-toggle works correctly below oh-context:
component: oh-context
slots:
default:
- component: oh-toggle
config:
item: Location_Pendant_Switch
This makes me suspect that list-item components such as oh-toggle-item, oh-label-item, etc. depend on being direct children of a list/list-card context, and that inserting oh-context between the list and the item breaks that rendering context.
The reason I would like to use oh-context is not primarily layout-related. I need to perform a fairly expensive/static lookup once, for example:
_UI[item] -> { i: baseIcon, l: label, r: renderingRule }
and then reuse the result several times in:
title:
icon:
iconColor:
...
Without oh-context, the same long expression has to be repeated for every property.
So the questions are:
- Is it expected that
oh-toggle-itemdoes not render correctly when it is a child ofoh-context? - Is there a supported way to keep
oh-toggle-itemas a proper list item while still giving it access toconst/fnfrom anoh-context? - Is there another supported mechanism for defining a local reusable variable/constant for the config of a root list-item component?
- If not, is repeating the full expression in every property currently the only option?
The intended structure would ideally be something conceptually like:
oh-context
constants:
ui: <lookup performed once>
oh-toggle-item
title: =const.ui.l
icon: =const.ui.i
iconColor: ...
but while still preserving normal list-item rendering inside an oh-location-card / list context.
If useful, I can also provide a minimal reproducer showing the rendering difference between oh-toggle and oh-toggle-item below oh-context.