Fixed a bunch of typos and issues in syscontrol uevent update

This commit is contained in:
Yessiest 2022-09-04 21:08:41 +04:00
parent f8f500d306
commit 2031ca424e
1 changed files with 4 additions and 3 deletions

View File

@ -90,19 +90,19 @@ syscontrol.power_supply.read_attribs = function(dev_name)
end end
local uevent_data = {} local uevent_data = {}
local device = { local device = {
type = fhandler:read("*a"), type = fhandler:read("*a"):match("%S*"),
full_path = "/sys/class/power_supply/"..dev_name, full_path = "/sys/class/power_supply/"..dev_name,
name = dev_name name = dev_name
} }
fhandler:close() fhandler:close()
uevent:read("*a"):gsub("[^\n]+",function(line) uevent_f:read("*a"):gsub("[^\n]+",function(line)
local key,value = line:match("^([^=]+)=([^=]*)") local key,value = line:match("^([^=]+)=([^=]*)")
if value:match("^%d+$") then if value:match("^%d+$") then
value = tonumber(value) value = tonumber(value)
end end
uevent_data[key] = value uevent_data[key] = value
end) end)
uevent:close() uevent_f:close()
if device.type == "Battery" then if device.type == "Battery" then
device.model = uevent_data.POWER_SUPPLY_MODEL_NAME or "N/A" device.model = uevent_data.POWER_SUPPLY_MODEL_NAME or "N/A"
device.energy_full_design = uevent_data.POWER_SUPPLY_ENERGY_FULL_DESIGN device.energy_full_design = uevent_data.POWER_SUPPLY_ENERGY_FULL_DESIGN
@ -117,6 +117,7 @@ syscontrol.power_supply.read_attribs = function(dev_name)
elseif device.type == "Mains" then elseif device.type == "Mains" then
device.online = (uevent_data.POWER_SUPPLY_ONLINE == 1) device.online = (uevent_data.POWER_SUPPLY_ONLINE == 1)
end end
return device
else else
return nil, err return nil, err
end end