Every HC3 device has a type, and types have structure: properties with types and defaults, interfaces that add more of them, actions the device answers. Until now flua's emulator kept the plumbing but not the meaning — an interface on a QA was stored and that was that. No more: flua now models the device catalog properly. Your QA boots with the properties its type declares, interfaces compose for real, and flua checks your values against the declared types. This post tours the three behaviors.
A QA's device structure comes from the catalog: typed properties at
their declared defaults, the interfaces the type carries, and the
actions it answers. The --%%interface: directive adds an
interface the type does not already have — and the interface's
properties arrive with it:
--%%name:Autolight
--%%type:com.fibaro.binarySwitch
--%%interface:autoTurnOff
function QuickApp:onInit()
local d = api.get("/devices/" .. self.id)
print("INTERFACES", table.concat(d.interfaces, ","))
print("OFF", d.properties.autoOffTimestamp, d.properties.autoOffDefaultTime)
print("SET_AUTOOFF", d.actions.setAutoOff)
exit(0)
end
flua --api local autolight.lua
[Autolight5000]: INTERFACES light,autoTurnOff,quickApp
[Autolight5000]: OFF 0 900 -- the interface's defaults
[Autolight5000]: SET_AUTOOFF 3 -- the action, with its arg count
Every type in the catalog composes this way — properties from the type, extra properties and actions from each interface it declares.
The REST route behaves too: POST /plugins/interfaces
adds the interface's properties and actions, remove takes them away
again — and, like on the HC3, an interface change restarts the
plugin. The demo therefore uses a driver QA so the target's restarts
don't interfere:
driver.lua — flips interfaces on the Lamp QA:
api.post("/plugins/interfaces", {action = "add", deviceId = lamp,
interfaces = {"energy"}})
local d = api.get("/devices/" .. lamp)
print("ADDED", d.properties.energy, d.properties.storeEnergyData, d.actions.reset)
api.post("/plugins/interfaces", {action = "remove", deviceId = lamp,
interfaces = {"energy"}})
d = api.get("/devices/" .. lamp)
print("REMOVED", d.properties.energy, d.actions.reset)
flua --api local lamp.lua driver.lua
[Lamp5000]: LAMP_BOOT
[Driver5001]: ADDED 0.0 true 1
[Driver5001]: REMOVED nil nil
[Lamp5000]: LAMP_BOOT -- the add restarted the plugin
[Lamp5000]: LAMP_BOOT -- and so did the remove
Adding a type's own interface back later restores its defaults; an interface name flua does not know is still stored plainly, with no invented properties.
An interface change restarts the plugin — even when nothing
changes: adding an interface the QA already has still restarts it.
A QA that adds its own interfaces in onInit therefore
loops forever unless it checks first:
function QuickApp:onInit()
if not self:hasInterface("autoTurnOff") then
self:addInterfaces({"autoTurnOff"})
end
end
flua --api local guard.lua
[GuardDemo5000]: BOOT -- once: hasInterface said true, nothing to add
[GuardDemo5000]: HAS true
hasInterface is the gate: add only what is missing, and
a re-boot after a real change is a one-time event, not a loop. The
remove side is symmetrical — check before you remove.
Because the properties are typed, flua can check what you put in them.
The emulator warns when updateProperty sets a value that
does not fit the declaration — the kind of mismatch the controller
silently ignores, leaving you to wonder why nothing happened:
self:updateProperty("value", true)
self:updateProperty("value", "yes") -- the type declares bool
flua --api local warn.lua
[WarnDemo5000]: updateProperty: property 'value' is declared bool, got str
(the real HC3 silently ignores the update)
[WarnDemo5000]: DONE yes -- flua warns and applies, never rejects
Warnings fire once per property and are on by default —
--%%warn:propertyType=false silences them. And the same
check runs statically, before anything executes:
flua --check warn.lua
warn.lua: warning: updateProperty: property 'value' is declared bool,
the literal "yes" does not fit (the real HC3 silently ignores the update)
Enum-valued properties (like deviceRole) are checked
against their vocabulary too. The check is deliberately conservative:
literal arguments only, warn-only, never a rejection — flua never breaks
a QA the controller would accept.
The catalog behind all this is larger than before — 190 device types, one command away:
flua --tool catalog # one type per line flua --tool catalog --json # the machine-readable list
Honest edges: the checks are guidance, not enforcement — flua warns and applies, and an interface it does not know stays plain storage. The action arg counts are metadata for now, not enforced call shapes. The model is the foundation; the checks are the first thing built on it.
Next time: endpoint packages — wrap a simulated endpoint in a QA and distribute it as a .fqa, emulation like any other QA.