Identity active/inactive

Example: Toggle the active state of an identity.

  • led green if active
  • led off if inactive
identity_ready.xml
  1. <templates>
  2. <template name="Toggle identity active">
  3. <keyConfiguration>
  4. <lua>
  5. <code><![CDATA[
  6. local config_path_active = "/identities/identity[" .. identity .."]/active"
  7. local active = false
  8.  
  9. -- called on changes to the configuration
  10. -- get the active state and set the led
  11. local function onConfigChange()
  12. active = config.get(config_path_active) == "true"
  13. if active then
  14. key.setLed("green")
  15. else
  16. key.setLed("off")
  17. end
  18. end
  19.  
  20. -- called when the key is pressed
  21. -- check the current state and set to the other
  22. function onKeyUp()
  23. if active then
  24. config.set(config_path_active, "false")
  25. else
  26. config.set(config_path_active, "true")
  27. end
  28. end
  29.  
  30. config.register(config_path_active, onConfigChange)
  31. -- trigger once to get the current state
  32. onConfigChange()
  33. ]]></code>
  34. <params>
  35. <param name="identity"><value/></param>
  36. </params>
  37. </lua>
  38. </keyConfiguration>
  39. <parameters>
  40. <parameter name="@string/identity">
  41. <path>//param[@name="identity"]/value</path>
  42. </parameter>
  43. </parameters>
  44. </template>
  45. </templates>

Example: Toggle identity active state and set to default if switching to enabled

  • led green if active and default
  • led orange if inactive
  • led off if active but not default
identity_ready_default.xml
  1. <templates patch="true">
  2. <template name="Toggle identity active with default">
  3. <keyConfiguration>
  4. <lua>
  5. <code><![CDATA[
  6. local config_path_active = "/identities/identity[" .. identity .."]/active"
  7. local config_path_current = "/telephony/activeLine"
  8.  
  9. local active
  10. local current
  11.  
  12. -- called on changes to the configuration
  13. -- get the active state and current identity and set the led
  14. local function onConfigChange()
  15. active = config.get(config_path_active) == "true"
  16. current = config.get(config_path_current .. "/id")
  17. if active then
  18. if current == identity then
  19. key.setLed("green")
  20. else
  21. key.setLed("off")
  22. end
  23. else
  24. key.setLed("orange")
  25. end
  26. end
  27.  
  28. -- called when the key is pressed
  29. -- check the current state and set to the other
  30. -- set the default identity also when setting to enabled
  31. function onKeyUp()
  32. if active then
  33. config.set(config_path_active, "false")
  34. else
  35. config.set(config_path_active, "true")
  36. config.set(config_path_current .. "/id", identity)
  37. end
  38. end
  39.  
  40. config.register(config_path_active, onConfigChange)
  41. config.register(config_path_current, onConfigChange)
  42. -- trigger once to get the current state
  43. onConfigChange()
  44. ]]></code>
  45. <params>
  46. <param name="identity"><value/></param>
  47. </params>
  48. </lua>
  49. </keyConfiguration>
  50. <parameters>
  51. <parameter name="@string/identity">
  52. <path>//param[@name="identity"]/value</path>
  53. </parameter>
  54. </parameters>
  55. </template>
  56. </templates>