Child UIs as resources — tabbed children, packaged automatically

The child-devices post covered the API. This one is about what the children look like. Because here's a happy accident of the HC3: the UI editor never touches a child device's view. Which means the modern view elements — tabbed panels, collapsible sections — that are off-limits in a QA you'd edit on the controller are completely safe on children. And with flua, declaring those child UIs got a whole lot easier.

The quick recap: how a child's UI talks back

A child device can carry its own uiView — passed to createChildDevice as initialProperties.uiView. When someone taps a control on a child, the controller calls the method named in the binding — actionName = "turnOn" means turnOn — on the child's class, with plain arguments. No callback table, no middleman: each child resolves its own methods, so two children can both have a "Turn On" button that does different things. (The full event model — main QA, children, old and new view format — is in the companion post, The button that did nothing.)

So a tabbed child is a uiView table plus a class with the methods. The table is the annoying part to write by hand — it is the same shape flua's compiler produces. flua --tool ui --as-lua prints any declared UI as a paste-ready table with the method names baked into the bindings, the way a child's view needs them:

-- local uiView = {...}   # child bindings, paste-ready

The main act: declare them, don't paste them

Pasting works — but pasted tables are a maintenance tax: the moment the UI changes, the paste goes stale. flua 0.1.182 added a better way: the --%%rsrc directive. Declare each child UI in the QA file itself, in the same row language as --%%u:

--%%rsrc:uiA:{tabView="mainTabs",activeTab="control",onTabChanged="tabChanged",tabs={
--  {name="control",text="Control",components={
--    {{button="onBtn",text="Turn On",onReleased="turnOn"}},
--    {{slider="dim",text="Brightness",min="0",max="100",value="50",onChanged="dim"}}
--  }}}}

function QuickApp:onInit()
  self:createChildDevice({ name = "A", type = "com.fibaro.floodSensor",
    initialProperties = { uiView = fibaro.RSRC.uiA } }, Child)
end

Each resource becomes fibaro.RSRC.name — compiled to a child-style uiView, method names and all, ready for createChildDevice.

One field note: an argless binding (a button) must carry json.array() for its arguments — a plain empty table encodes as an object and the HC3 app silently drops the press. flua emits the marked form automatically.

Resource names are Lua identifiers (they become fibaro.RSRC.name), and the directive is the future home of other resource kinds — icon bitmaps, config blobs, whatever needs to travel with the QA.

Example: flua --examples → ui-3-children.lua (three children — tabbed, collapsible and a 6-button panel — all declared with --%%rsrc) · flua: https://github.com/jangabrielsson/flua