Identity active/inactive
Example: Toggle the active state of an identity.
-
led green if active
-
led off if inactive
identity_ready.xml |
---|
| <templates>
<template name="Toggle identity active">
<keyConfiguration>
<lua><code><![CDATA[
local config_path_active = "/identities/identity[" .. identity .."]/active"
local active = false
-- called on changes to the configuration
-- get the active state and set the led
local function onConfigChange()
active = config.get(config_path_active) == "true"
if active then
key.setLed("green")
else
key.setLed("off")
end
end
-- called when the key is pressed
-- check the current state and set to the other
function onKeyUp()
if active then
config.set(config_path_active, "false")
else
config.set(config_path_active, "true")
end
end
config.register(config_path_active, onConfigChange)
-- trigger once to get the current state
onConfigChange()
]]></code>
<params>
<param name="identity"><value/></param>
</params>
</lua>
</keyConfiguration>
<parameters>
<parameter name="@string/identity">
<path>//param[@name="identity"]/value</path>
</parameter>
</parameters>
</template>
</templates>
|
Example: Toggle identity active state and set to default if switching to enabled
identity_ready_default.xml |
---|
| <templates patch="true">
<template name="Toggle identity active with default">
<keyConfiguration>
<lua>
<![CDATA[```
local config_path_active = "/identities/identity[" .. identity .."]/active"
local config_path_current = "/telephony/activeLine"
local active
local current
-- called on changes to the configuration
-- get the active state and current identity and set the led
local function onConfigChange()
active = config.get(config_path_active) == "true"
current = config.get(config_path_current .. "/id")
if active then
if current == identity then
key.setLed("green")
else
key.setLed("off")
end
else
key.setLed("orange")
end
end
-- called when the key is pressed
-- check the current state and set to the other
-- set the default identity also when setting to enabled
function onKeyUp()
if active then
config.set(config_path_active, "false")
else
config.set(config_path_active, "true")
config.set(config_path_current .. "/id", identity)
end
end
config.register(config_path_active, onConfigChange)
config.register(config_path_current, onConfigChange)
-- trigger once to get the current state
onConfigChange()
|
//param[@name="identity"]/value
```