Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
3.0 KiB

2 years ago
2 years ago
2 years ago
  1. -- This file is part of Reno desktop.
  2. --
  3. -- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  4. --
  5. -- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. --
  7. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
  8. -- Powerman X - second generation of the power management daemon
  9. local sysctl = require("syscontrol")
  10. local naughty = require("naughty")
  11. local gears = require("gears")
  12. local batteries = sysctl.power_supply.enumerate()
  13. local state_tracking = {}
  14. -- Configuration variables
  15. local cfg = config.powerman or {}
  16. local quality_min = cfg.battery_quality_min or 33
  17. local capacity_min = cfg.battery_capacity_min or 15
  18. -- Main loop
  19. gears.timer({
  20. timeout = 2,
  21. autostart = true,
  22. callback = function()
  23. for _,v in pairs(batteries) do
  24. local data,_ = sysctl.power_supply.read_attribs(v)
  25. state_tracking[v] = state_tracking[v] or {}
  26. if data.type == "Battery" then
  27. if (tonumber(data.quality) < quality_min) and
  28. (not state_tracking[v].quality_notification) then
  29. naughty.notify({
  30. title = "Critical battery condition",
  31. text = "Battery "..data.name.." has reached critically low condition, seek a suitable replacement"
  32. })
  33. state_tracking[v].quality_notification = true
  34. end
  35. if (tonumber(data.capacity) <= capacity_min) and
  36. (not data.charging) and
  37. (not state_tracking[v].capacity_notification) then
  38. naughty.notify({
  39. title = "Battery capacity low",
  40. text = "Battery "..data.name.." capacity is at "..tostring(data.capacity).."%"
  41. })
  42. state_tracking[v].capacity_notification = true
  43. end
  44. if (tonumber(data.capacity) > capacity_min) then
  45. state_tracking[v].capacity_notification = false
  46. end
  47. if (data.capacity == "100") and
  48. (data.charging) and
  49. (not state_tracking[v].charged_notification) then
  50. naughty.notify({
  51. title = "Battery is completely charged",
  52. text = "Disconnect the charger from the power grid to avoid passive electricity usage."
  53. })
  54. end
  55. if (not data.charging) then
  56. state_tracking[v].charged_notification = false
  57. end
  58. end
  59. end
  60. end
  61. })