Removed some useless else statements
This commit is contained in:
parent
b65d509380
commit
b4e028b21f
72
bat.lua
72
bat.lua
|
@ -38,43 +38,43 @@ local function worker(format, batid)
|
|||
-- Check if the file wasn't found or the battery isn't present
|
||||
if infofile == nil or string.find(infofile, "present:[%s]+no") then
|
||||
return {"/", "/", "/"}
|
||||
else
|
||||
-- Get capacity information
|
||||
local capacity = string.match(infofile, "last full capacity:[%s]+([%d]+).*")
|
||||
|
||||
|
||||
-- Get /proc/acpi/battery state
|
||||
local f = io.open("/proc/acpi/battery/"..batid.."/state")
|
||||
local statefile = f:read("*all")
|
||||
f:close()
|
||||
|
||||
-- Get state information
|
||||
local state = string.match(statefile, "charging state:[%s]+([%a]+).*")
|
||||
local state = battery_state[state] or battery_state["unknown"]
|
||||
|
||||
-- Get charge information
|
||||
local rate = string.match(statefile, "present rate:[%s]+([%d]+).*")
|
||||
local remaining = string.match(statefile, "remaining capacity:[%s]+([%d]+).*")
|
||||
|
||||
|
||||
-- Calculate percentage
|
||||
local percent = math.floor(remaining / capacity * 100)
|
||||
local percent = string.format("%02d", percent)
|
||||
|
||||
-- Calculate remaining (charging or discharging) time
|
||||
if state == "+" then
|
||||
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
|
||||
elseif state == "-" then
|
||||
timeleft = tonumber(remaining) / tonumber(rate)
|
||||
else
|
||||
return { state, percent, "/" }
|
||||
end
|
||||
local hoursleft = math.floor(timeleft)
|
||||
local minutesleft = math.floor((timeleft - hoursleft) * 60 )
|
||||
local time = string.format("%02d:%02d", hoursleft, minutesleft)
|
||||
|
||||
return {state, percent, time}
|
||||
end
|
||||
|
||||
-- Get capacity information
|
||||
local capacity = string.match(infofile, "last full capacity:[%s]+([%d]+).*")
|
||||
|
||||
|
||||
-- Get /proc/acpi/battery state
|
||||
local f = io.open("/proc/acpi/battery/"..batid.."/state")
|
||||
local statefile = f:read("*all")
|
||||
f:close()
|
||||
|
||||
-- Get state information
|
||||
local state = string.match(statefile, "charging state:[%s]+([%a]+).*")
|
||||
local state = battery_state[state] or battery_state["unknown"]
|
||||
|
||||
-- Get charge information
|
||||
local rate = string.match(statefile, "present rate:[%s]+([%d]+).*")
|
||||
local remaining = string.match(statefile, "remaining capacity:[%s]+([%d]+).*")
|
||||
|
||||
|
||||
-- Calculate percentage
|
||||
local percent = math.floor(remaining / capacity * 100)
|
||||
local percent = string.format("%02d", percent)
|
||||
|
||||
-- Calculate remaining (charging or discharging) time
|
||||
if state == "+" then
|
||||
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
|
||||
elseif state == "-" then
|
||||
timeleft = tonumber(remaining) / tonumber(rate)
|
||||
else
|
||||
return { state, percent, "/" }
|
||||
end
|
||||
local hoursleft = math.floor(timeleft)
|
||||
local minutesleft = math.floor((timeleft - hoursleft) * 60 )
|
||||
local time = string.format("%02d:%02d", hoursleft, minutesleft)
|
||||
|
||||
return {state, percent, time}
|
||||
end
|
||||
-- }}}
|
||||
|
||||
|
|
48
weather.lua
48
weather.lua
|
@ -41,32 +41,30 @@ local function worker(format, station)
|
|||
}
|
||||
|
||||
-- Check if there was a timeout or a problem with the station
|
||||
if ws == nil then
|
||||
return weather
|
||||
else
|
||||
weather["{city}"] = -- City and/or area
|
||||
string.match(ws, "^(.+)%,.*%([%u]+%)") or weather["{city}"]
|
||||
weather["{wind}"] = -- Wind direction and degrees if available
|
||||
string.match(ws, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or weather["{wind}"]
|
||||
weather["{windmph}"] = -- Wind speed in MPH if available
|
||||
string.match(ws, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or weather["{windmph}"]
|
||||
weather["{sky}"] = -- Sky conditions if available
|
||||
string.match(ws, "Sky[%s]conditions:[%s](.-)[%c]") or weather["{sky}"]
|
||||
weather["{weather}"] = -- Weather conditions if available
|
||||
string.match(ws, "Weather:[%s](.-)[%c]") or weather["{weather}"]
|
||||
weather["{tempf}"] = -- Temperature in fahrenheit
|
||||
string.match(ws, "Temperature:[%s]([%d%.]+).*[%c]") or weather["{tempf}"]
|
||||
weather["{tempc}"] = -- Temperature in celsius
|
||||
string.match(ws, "Temperature:[%s][%d%.]+[%s]F[%s]%(([%d%.]+)[%s]C%)[%c]") or weather["{tempc}"]
|
||||
weather["{humid}"] = -- Relative humidity in percent
|
||||
string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or weather["{humid}"]
|
||||
weather["{press}"] = -- Pressure in hPa
|
||||
string.match(ws, "Pressure[%s].+%((.+)[%s]hPa%)") or weather["{press}"]
|
||||
if ws == nil then return weather end
|
||||
|
||||
-- Wind speed in KMH if MPH was available
|
||||
if weather["{windmph}"] ~= "N/A" then
|
||||
weather["{windkmh}"] = math.floor(weather["{windmph}"] * 1.6)
|
||||
end
|
||||
weather["{city}"] = -- City and/or area
|
||||
string.match(ws, "^(.+)%,.*%([%u]+%)") or weather["{city}"]
|
||||
weather["{wind}"] = -- Wind direction and degrees if available
|
||||
string.match(ws, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or weather["{wind}"]
|
||||
weather["{windmph}"] = -- Wind speed in MPH if available
|
||||
string.match(ws, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or weather["{windmph}"]
|
||||
weather["{sky}"] = -- Sky conditions if available
|
||||
string.match(ws, "Sky[%s]conditions:[%s](.-)[%c]") or weather["{sky}"]
|
||||
weather["{weather}"] = -- Weather conditions if available
|
||||
string.match(ws, "Weather:[%s](.-)[%c]") or weather["{weather}"]
|
||||
weather["{tempf}"] = -- Temperature in fahrenheit
|
||||
string.match(ws, "Temperature:[%s]([%d%.]+).*[%c]") or weather["{tempf}"]
|
||||
weather["{tempc}"] = -- Temperature in celsius
|
||||
string.match(ws, "Temperature:[%s][%d%.]+[%s]F[%s]%(([%d%.]+)[%s]C%)[%c]") or weather["{tempc}"]
|
||||
weather["{humid}"] = -- Relative humidity in percent
|
||||
string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or weather["{humid}"]
|
||||
weather["{press}"] = -- Pressure in hPa
|
||||
string.match(ws, "Pressure[%s].+%((.+)[%s]hPa%)") or weather["{press}"]
|
||||
|
||||
-- Wind speed in KMH if MPH was available
|
||||
if weather["{windmph}"] ~= "N/A" then
|
||||
weather["{windkmh}"] = math.floor(weather["{windmph}"] * 1.6)
|
||||
end
|
||||
|
||||
return weather
|
||||
|
|
34
wifi.lua
34
wifi.lua
|
@ -38,25 +38,25 @@ local function worker(format, iface)
|
|||
-- interface is not a wireless one
|
||||
if iw == nil or string.find(iw, "No such device") then
|
||||
return winfo
|
||||
else
|
||||
-- The output differs from system to system, some stats can
|
||||
-- be separated by =, and not all drivers report all stats
|
||||
winfo["{ssid}"] = -- SSID can have almost anything in it
|
||||
string.match(iw, 'ESSID[=:]"([%w%p]+[%s]*[%w%p]*]*)"') or winfo["{ssid}"]
|
||||
winfo["{mode}"] = -- Modes are simple, but also match the "-" in Ad-Hoc
|
||||
string.match(iw, "Mode[=:]([%w%-]*)") or winfo["{mode}"]
|
||||
winfo["{chan}"] = -- Channels are plain digits
|
||||
string.match(iw, "Channel[=:]([%d]+)") or winfo["{chan}"]
|
||||
winfo["{rate}"] = -- Bitrate can start with a space and we want to display Mb/s
|
||||
string.match(iw, "Bit Rate[=:]([%s]?[%d%.]*[%s][%/%a]+)") or winfo["{rate}"]
|
||||
-- winfo["{link}"] = -- Link quality can contain a slash: 32/100
|
||||
-- string.match(iw, "Link Quality[=:]([%d]+[%/%d]*)") or winfo["{link}"]
|
||||
winfo["{link}"] = -- * match only the first number, great data for a progressbar
|
||||
string.match(iw, "Link Quality[=:]([%d]+)") or winfo["{link}"]
|
||||
winfo["{sign}"] = -- Signal level can be a negative value, also display decibel notation
|
||||
string.match(iw, "Signal level[=:]([%-%d]+[%s][%a]*)") or winfo["{sign}"]
|
||||
end
|
||||
|
||||
-- The output differs from system to system, some stats can
|
||||
-- be separated by =, and not all drivers report all stats
|
||||
winfo["{ssid}"] = -- SSID can have almost anything in it
|
||||
string.match(iw, 'ESSID[=:]"([%w%p]+[%s]*[%w%p]*]*)"') or winfo["{ssid}"]
|
||||
winfo["{mode}"] = -- Modes are simple, but also match the "-" in Ad-Hoc
|
||||
string.match(iw, "Mode[=:]([%w%-]*)") or winfo["{mode}"]
|
||||
winfo["{chan}"] = -- Channels are plain digits
|
||||
string.match(iw, "Channel[=:]([%d]+)") or winfo["{chan}"]
|
||||
winfo["{rate}"] = -- Bitrate can start with a space and we want to display Mb/s
|
||||
string.match(iw, "Bit Rate[=:]([%s]?[%d%.]*[%s][%/%a]+)") or winfo["{rate}"]
|
||||
-- winfo["{link}"] = -- Link quality can contain a slash: 32/100
|
||||
-- string.match(iw, "Link Quality[=:]([%d]+[%/%d]*)") or winfo["{link}"]
|
||||
winfo["{link}"] = -- * match only the first number, great data for a progressbar
|
||||
string.match(iw, "Link Quality[=:]([%d]+)") or winfo["{link}"]
|
||||
winfo["{sign}"] = -- Signal level can be a negative value, also display decibel notation
|
||||
string.match(iw, "Signal level[=:]([%-%d]+[%s][%a]*)") or winfo["{sign}"]
|
||||
|
||||
return winfo
|
||||
end
|
||||
-- }}}
|
||||
|
|
Loading…
Reference in New Issue