-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bat_now.status is nil #451
Comments
Looking at bat.lua, I see that it sets bat_now.status to bat_now.n_status[1], which is null because "battery" isn't set. This wasn't autodetected. It's BAT0 on my system. Setting arg.battery solves the problem, but I'm wondering if this should be considered a bug? |
What does this mean? Do you have the directory Try the following in a Lua shell (spawn it in a terminal by typing io.popen("ls -1 /sys/class/power_supply/"):read("*all"):match("BAT%w+") Tell me if it outputs "BAT0". Also, if you have a ThinkPad, consider trying this widget instead. |
The lua binary is not on my shell's path, as defined by the PATH environment variable... It doesn't seem to be installed anywhere. Awesome seems to use liblua5.3-0, and not require a lua CLI? Anyway...
Yep, which is why everything works when I define arg.battery.
Yep, which is why everything works when I define arg.battery. |
I know that you have the file. What I asked you is to run a command in the Lua command-line interpreter that does exactly what the widget does in this function, to see what is the output and fix it. Both Awesome and Lain depend on Lua. I understand that liblua5.3.-0 installs it, even though you say you do not have it in your PATH variable. Hence, from what you say I do not understand what you have done. Can I assume that you added Lua to your user path and ran the command as I asked? Otherwise, do it. And if you want my further attention, avoid pointless and childish copy-pasting. |
Sorry, I didn't realize copy-pasting could be construed as childish. I was simply answering two different questions with the same answer. There is no lua binary on this system, yet Awesome works fine. The package liblua5.3.-0 only has some .so files in it. The lua binary seems to be in lua5.2, which is not installed on this system. Just some confusion, that's all. I've installed lua5.2, just to run your test. Outputs BAT0, no problem. The problem is in here somewhere. Lines 39 to 48 in 33c0e0c
It's not |
Just be nice and not redundant. It's my honest advice.
You say that the string matching works. Let's debug the function integrity. Change this: Line 50 in 33c0e0c
To this: bat.get_batteries() If it doesn't work, put after here the following line: naughty.notify{ timeout = 0, text = bstr .. " " .. tostring(batteries[1]) .. " " .. ac } |
I'm a few steps ahead of that. Believe it or not, it's actually something to do with
Works, but
doesn't work, even though |
Is Did you try constructing the argument before? if pspath == nil then naughty.notify { text = "nil", timeout = 0 } end
local cmd_str = string.format("ls -1 %s", pspath)
helpers.line_callback(cmd_str, function(line)
-- [...]
end) |
No, believe it or not! Which is why I'm down in the pits looking at I should have been clearer and said:
gives results, while
returns nothing, even though from the shell |
If this is not a bug of mine, I can only speculate:
EDIT: The net widget also uses |
Is Because I can't make sense of the trace. I sprinkled some notifies in. It is finding BAT0.
What I get is
Besides the weird order ("later is" where it is), it looks like the callback's getting called twice? |
Your log makes perfect sense:
As a result, the widget is perfectly working, the problem is that you are trying to get the information before this is retrieved. The solution is to use defensive programming: local bat = lain.widget.bat {
settings = function()
bat_header = " Bat "
bat_p = (bat_now.perc or "N/A") .. "% "
bat_t = (bat_now.time or "N/A") .. " "
bat_s = (bat_now.status or "N/A/") .. " "
widget:set_markup(markup.font(theme.font, markup(gray, bat_header) .. bat_p .. bat_t .. bat_s))
end
} The reason behind is that my widgets are asynchronous. However, this style of programming is also useful for detecting system changes (e.g., battery removed or added) or failures (e.g., battery failing!). Sorry, I should have detected this immediately from your code. Anyway, I believe this thread is a contribution to new users. I will add a link to the main wiki page. In the future, check how I configure widgets in my themes for reference. You have different examples there. Also, as I wrote before, you can check |
Because of operator precedence, the fix actually needs to be:
Also, I've added the guard to just bat_s because only So, you could probably fix it for all users at: If I'm not mistaken, the widget updates every 30 seconds, not asynchronously? |
I will add the fix, thanks.
That's the update frequency, but the update itself is asynchronous, as you have seen. |
Cool, after a rough start, I knew we'd be friends Luca. |
awesome -v
andlua -v
awesome v4.2 (Human after all)
lua not on path
Expecting
bat_now.status
to have a value as defined in the wikiActual: bat_now.status is nil
without bat_now.status, the below config works.
The text was updated successfully, but these errors were encountered: