All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Interface with thinkpad battery information
6 Licensed under GNU General Public License v2
7 * (c) 2013, Conor Heine
11 local first_line = require("lain.helpers").first_line
13 local string = { format = string.format }
14 local tonumber = tonumber
15 local setmetatable = setmetatable
18 local apipath = "/sys/devices/platform/smapi"
20 -- Most are readable values, but some can be written to (not implemented, yet?)
23 charging_max_current = true,
24 charging_max_voltage = true,
29 design_capacity = true,
30 design_voltage = true,
32 first_use_date = true,
33 force_discharge = false,
34 group0_voltage = true,
35 group1_voltage = true,
36 group2_voltage = true,
37 group3_voltage = true,
38 inhibit_charge_minutes = false,
40 last_full_capacity = true,
41 manufacture_date = true,
46 remaining_capacity = true,
47 remaining_charging_time = true,
48 remaining_percent = true,
49 remaining_percent_error = true,
50 remaining_running_time = true,
51 remaining_running_time_now = true,
53 start_charge_thresh = false,
55 stop_charge_thresh = false,
60 function smapi:battery(name)
64 bat.path = apipath .. "/" .. name
66 function bat:get(item)
67 return self.path ~= nil and readable[item] and first_line(self.path .. "/" .. item) or nil
70 function bat:installed()
71 return self:get("installed") == "1"
75 return self:get('state')
78 -- Remaining time can either be time until battery dies or time until charging completes
79 function bat:remaining_time()
80 local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time'
81 local mins_left = self:get(time_val)
83 if not mins_left:find("^%d+") then return "N/A" end
85 local hrs = math.floor(mins_left / 60)
86 local min = mins_left % 60
88 return string.format("%02d:%02d", hrs, min)
91 function bat:percent()
92 return tonumber(self:get("remaining_percent"))
95 return setmetatable(bat, {__metatable = false, __newindex = false})