summaryrefslogtreecommitdiffstats
path: root/lass/3modules
diff options
context:
space:
mode:
authorlassulus <lass@aidsballs.de>2016-06-18 21:51:45 +0200
committerlassulus <lass@aidsballs.de>2016-06-18 21:51:45 +0200
commit1b238cf556064996b9db9b4a86c232228a0e9114 (patch)
tree16a8ddc0e014d864d84b7f6831e685a24286573a /lass/3modules
parent6e2cbdfb734d24a5c4dfb37b9ccc0b093c07c1f6 (diff)
l 3 power-action: add charging check
Diffstat (limited to 'lass/3modules')
-rw-r--r--lass/3modules/power-action.nix28
1 files changed, 27 insertions, 1 deletions
diff --git a/lass/3modules/power-action.nix b/lass/3modules/power-action.nix
index 631e651f..06a31627 100644
--- a/lass/3modules/power-action.nix
+++ b/lass/3modules/power-action.nix
@@ -25,6 +25,16 @@ let
plans = mkOption {
type = with types; attrsOf (submodule {
options = {
+ charging = mkOption {
+ type = nullOr bool;
+ default = null;
+ description = ''
+ check for charging status.
+ null = don't care
+ true = only if system is charging
+ false = only if system is discharging
+ '';
+ };
upperLimit = mkOption {
type = int;
};
@@ -53,15 +63,31 @@ let
};
startScript = pkgs.writeDash "power-action" ''
+ set -euf
+
power="$(${powerlvl})"
+ state="$(${state})"
${concatStringsSep "\n" (mapAttrsToList writeRule cfg.plans)}
'';
+ charging_check = plan:
+ if (plan.charging == null) then "" else
+ if plan.charging
+ then ''&& [ "$state" = "true" ]''
+ else ''&& ! [ "$state" = "true" ]''
+ ;
writeRule = _: plan:
- "if [ $power -ge ${toString plan.lowerLimit} ] && [ $power -le ${toString plan.upperLimit} ]; then ${plan.action}; fi";
+ "if [ $power -ge ${toString plan.lowerLimit} ] && [ $power -le ${toString plan.upperLimit} ] ${charging_check plan}; then ${plan.action}; fi";
powerlvl = pkgs.writeDash "powerlvl" ''
cat /sys/class/power_supply/BAT0/capacity
'';
+ state = pkgs.writeDash "state" ''
+ if [ "$(cat /sys/class/power_supply/BAT0/status)" = "Charging" ]
+ then echo "true"
+ else echo "false"
+ fi
+ '';
+
in out