ap-timer.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. local uci = require('simple-uci').cursor()
  2. if not uci:get('ap-timer', 'settings') then
  3. uci:section('ap-timer', 'ap-timer', 'settings')
  4. uci:save('ap-timer')
  5. end
  6. if not uci:get('ap-timer', 'all') then
  7. uci:section('ap-timer', 'day', 'all')
  8. uci:save('ap-timer')
  9. end
  10. local f = Form(translate('AP Timer'), translate(
  11. 'You can setup the AP Timer here'))
  12. local s = f:section(Section)
  13. enabled = s:option(Flag, 'enabled', translate('Enabled'))
  14. enabled.default = uci:get_bool('ap-timer', 'settings', 'enabled')
  15. enabled.optional = false
  16. function enabled:write(data)
  17. uci:set('ap-timer', 'settings', 'enabled', data)
  18. end
  19. local timer_type = s:option(ListValue, 'type', translate('Type'))
  20. timer_type.default = uci:get('ap-timer', 'settings', 'type')
  21. timer_type:depends(enabled, true)
  22. timer_type:value('day', translate('Daily'))
  23. function timer_type:write(data)
  24. uci:set('ap-timer', 'settings', 'type', data)
  25. end
  26. local s = f:section(Section)
  27. o = s:option(DynamicList, 'on', translate('ON'))
  28. o.default = uci:get_list('ap-timer', 'all', 'on')
  29. o.placeholder = '06:30'
  30. o:depends(timer_type, 'day')
  31. o.optional = false
  32. o.datatype = 'minlength(5)'
  33. function o:write(data)
  34. uci:set_list('ap-timer', 'all', 'on', data)
  35. end
  36. o = s:option(DynamicList, 'off', translate('OFF'))
  37. o.default = uci:get_list('ap-timer', 'all', 'off')
  38. o.placeholder = '23:00'
  39. o:depends(timer_type, 'day')
  40. o.optional = false
  41. o.datatype = 'minlength(5)'
  42. function o:write(data)
  43. uci:set_list('ap-timer', 'all', 'off', data)
  44. end
  45. function f:write()
  46. uci:commit('ap-timer')
  47. end
  48. return f