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.

63 lines
3.0 KiB

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 awful = require("awful")
  13. local batteries = sysctl.power_supply.enumerate()
  14. local state_tracking = {}
  15. -- Configuration variables
  16. local cfg = config.powerman or {}
  17. local quality_min = cfg.battery_quality_min or 33
  18. local capacity_min = cfg.battery_capacity_min or 15
  19. -- Main loop
  20. local update_loop = gears.timer({
  21. timeout = 2,
  22. autostart = true,
  23. callback = function()
  24. for k,v in pairs(batteries) do
  25. local data,err = sysctl.power_supply.read_attribs(v)
  26. state_tracking[v] = state_tracking[v] or {}
  27. if data.type == "Battery" then
  28. if (tonumber(data.quality) < quality_min) and
  29. (not state_tracking[v].quality_notification) then
  30. naughty.notify({
  31. title = "Critical battery condition",
  32. text = "Battery "..data.name.." has reached critically low condition, seek a suitable replacement"
  33. })
  34. state_tracking[v].quality_notification = true
  35. end
  36. if (tonumber(data.capacity) <= capacity_min) and
  37. (not data.charging) and
  38. (not state_tracking[v].capacity_notification) then
  39. naughty.notify({
  40. title = "Battery capacity low",
  41. text = "Battery "..data.name.." capacity is at "..tostring(data.capacity).."%"
  42. })
  43. state_tracking[v].capacity_notification = true
  44. end
  45. if (tonumber(data.capacity) > capacity_min) then
  46. state_tracking[v].capacity_notification = false
  47. end
  48. if (data.capacity == "100") and
  49. (data.charging) and
  50. (not state_tracking[v].charged_notification) then
  51. naughty.notify({
  52. title = "Battery is completely charged",
  53. text = "Disconnect the charger from the power grid to avoid passive electricity usage."
  54. })
  55. end
  56. if (not data.charging) then
  57. state_tracking[v].charged_notification = false
  58. end
  59. end
  60. end
  61. end
  62. })