3 [`tp_smapi`](http://www.thinkwiki.org/wiki/Tp_smapi) interface and widget creator.
6 local tp_smapi = lain.widget.contrib.tp_smapi(apipath)
9 The argument `apipath` is an optional string which defines the API path. Its default value is `"/sys/devices/platform/smapi"`.
13 ## tp_smapi.get(batid, feature)
15 Gets the `feature` of battery `batid`. Returns a string. The list of available features is available at [this page](https://www.thinkwiki.org/wiki/Tp_smapi#Battery_status_features).
17 ## tp_smapi.installed(batid)
19 Checks if battery `batid` is installed. Returns a boolean.
21 ## tp_smapi.status(batid)
23 Gets the status of battery `batid`. Returns a string ("charging", "discharging", or "full").
25 ## tp_smapi.percentage(batid)
27 Gets the percentage of battery `batid`. Returns a numeric string.
29 ## tp_smapi.time(batid)
31 Gets the time of battery `batid`. Depending on the current status, it can be either running or charging time. Returns a string of the format `HH:MM`.
35 Removes any notification spawned by `tp_smapi.show`.
37 ## tp_smapi.show(batid, seconds, scr)
39 Notifies the current information of battery `batid` for `seconds` seconds on screen `scr`.
40 The argument `scr` is optional, and if missing, the notification will be displayed on the currently focused screen.
42 ## tp_smapi.create_widget(args)
44 Creates a [lain widget](https://github.com/lcpz/lain/wiki/Widgets#usage) of the available ThinkPad batteries.
47 local tpbat = tp_smapi.create_widget()
52 Variable | Meaning | Type | Default
54 `widget` | The widget type to use | [`wibox.widget`](https://awesomewm.org/doc/api/classes/wibox.widget.html) | [`wibox.widget.textbox`](https://awesomewm.org/doc/api/classes/wibox.widget.textbox.html)
55 `timeout` | Refresh timeout (in seconds) | integer | 30
56 `pspath` | Power supply directory path | string | "/sys/class/power_supply/"
57 `battery` | Single battery id | string | autodetected
58 `batteries` | Multiple batteries id table | table of strings | autodetected
59 `settings` | User settings | function | empty function
61 The widget will try to autodetect `battery` and `batteries`. If something
62 goes wrong, you will have to define them manually. In that case, you only have
63 to define one between `battery` and `batteries`. If you have one battery, you
64 can either use `args.battery = "BAT*"` or `args.batteries = {"BAT*"}`, where `BAT*`
65 is the identifier of your battery in `pspath` (do not use it as a wildcard).
66 Of course, if you have multiple batteries, you need to use the latter option.
68 If you define `pspath`, **be sure** to not forget the final slash (/).
70 `settings` can use the `tpbat_now` table, which contains the following strings:
72 - `status`, general status ("N/A", "discharging", "charging", "full");
73 - `n_status[i]`, i-th battery status (like above);
74 - `n_perc[i]`, i-th battery charge percentage (like above);
75 - `n_time[i]`, i-th battery running or charging time (HH:MM string or "N/A");
77 `n_time[i]` is the running time of battery `i` when it is discharging, and the charging time otherwise.
81 Variable | Meaning | Type
83 `widget` | The widget | [`wibox.widget`](https://awesomewm.org/doc/api/classes/wibox.widget.html) | [textbox](https://awesomewm.org/doc/api/classes/wibox.widget.textbox.html)
84 `batteries` | Battery identifiers | Table of strings
85 `update` | Update `widget` | function
86 `timer` | The widget timer | [`gears.timer`](https://awesomewm.org/doc/api/classes/gears.timer.html)
88 The `update` function can be used to refresh the widget before `timeout` expires.
93 local tp_smapi = lain.widget.contrib.tp_smapi()
94 local bat = tp_smapi.create_widget {
97 widget:set_markup(tpbat_now.n_perc[1] .. "%")
101 bat.widget:connect_signal("mouse::enter", function () tp_smapi.show("BAT0") end)
102 bat.widget:connect_signal("mouse::leave", function () tp_smapi.hide() end)