summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2017-01-30 15:50:08 +0100
committerJo-Philipp Wich <jo@mein.io>2017-01-30 15:50:45 +0100
commit926935f83170e38452a5191d13aa8b04021606ff (patch)
tree1c3776ef0a65d16368d5df85c0cc5ceacdeb1af4 /modules/luci-mod-admin-full/luasrc/model/cbi/admin_system
parent7c744309c51295abba53bfa56319f314df9040f7 (diff)
luci-mod-admin-full: fixes for usbport LED triggers
The previous commit erroneously used "ports" instead of "port" as name for the option widget, causing wrong uci values to be written. Also work around some cbi idiosyncrasies regarding MultiValue widgets which prevented rendering the correct initial selection state. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-mod-admin-full/luasrc/model/cbi/admin_system')
-rw-r--r--modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua31
1 files changed, 26 insertions, 5 deletions
diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua
index 4b6f397e6a..74e2f1a19d 100644
--- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua
+++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_system/leds.lua
@@ -7,10 +7,11 @@ local sysfs_path = "/sys/class/leds/"
local leds = {}
local fs = require "nixio.fs"
-local util = require "nixio.util"
+local nu = require "nixio.util"
+local util = require "luci.util"
if fs.access(sysfs_path) then
- leds = util.consume((fs.dir(sysfs_path)))
+ leds = nu.consume((fs.dir(sysfs_path)))
end
if #leds == 0 then
@@ -110,12 +111,32 @@ function usbdev.remove(self, section)
end
-usbport = s:option(MultiValue, "ports", translate("USB Ports"))
+usbport = s:option(MultiValue, "port", translate("USB Ports"))
usbport:depends("trigger", "usbport")
usbport.rmempty = true
usbport.widget = "checkbox"
+usbport.cast = "table"
usbport.size = 1
+function usbport.valuelist(self, section)
+ local port, ports = nil, {}
+ for port in util.imatch(m.uci:get("system", section, "port")) do
+ local b, n = port:match("^usb(%d+)-port(%d+)$")
+ if not (b and n) then
+ b, n = port:match("^(%d+)-(%d+)$")
+ end
+ if b and n then
+ ports[#ports+1] = "usb%u-port%u" %{ tonumber(b), tonumber(n) }
+ end
+ end
+ return ports
+end
+
+function usbport.validate(self, value)
+ return type(value) == "string" and { value } or value
+end
+
+
for p in nixio.fs.glob("/sys/bus/usb/devices/[0-9]*/manufacturer") do
local id = p:match("%d+-%d+")
local mf = nixio.fs.readfile("/sys/bus/usb/devices/" .. id .. "/manufacturer") or "?"
@@ -123,8 +144,8 @@ for p in nixio.fs.glob("/sys/bus/usb/devices/[0-9]*/manufacturer") do
usbdev:value(id, "%s (%s - %s)" %{ id, mf, pr })
end
-for p in nixio.fs.glob("/sys/bus/usb/devices/[0-9]*") do
- local bus, port = p:match("(%d+)-(%d+)")
+for p in nixio.fs.glob("/sys/bus/usb/devices/*/usb[0-9]*-port[0-9]*") do
+ local bus, port = p:match("usb(%d+)-port(%d+)")
if bus and port then
usbport:value("usb%u-port%u" %{ tonumber(bus), tonumber(port) },
"Hub %u, Port %u" %{ tonumber(bus), tonumber(port) })