summaryrefslogtreecommitdiff
path: root/testcases
diff options
context:
space:
mode:
authorjohcgt <35880934+johcgt@users.noreply.github.com>2018-01-28 14:37:51 +0000
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2018-01-28 15:37:51 +0100
commitd5c69a9d60a0bf9b6fbbaff7e122042410bfe44a (patch)
treeb819b8e107218e77f743f534a318c20b36a05f1d /testcases
parentef8f9ddcd722a9c29f901a8bbf163acbdbcb866a (diff)
Treat zero battery capacity as "not available" (#259)
`print_battery_info` computes `batt_info.percentage_remaining` by dividing batt_info.remaining by `full`. If `full` is `0` then the battery remaining will be reported as "inf". Before this, it tries to set `full` to either the design capacity or to the last known good charge. It determines if these values are available by checking whether their fields in `batt_info` are non-negative. As it initialized `batt_info` with values of `-1`, a non-negative value implies that something has provided a value. `slurp_all_batteries` and `add_battery_info` however initialize these fields to zero, so if these functions are called then `batt_info.full_design` will always be used. This means that on systems that don't provide a value for design capacity the percentage remaining will be reported as "inf", unless the user has set `last_full_capacity` to `true` in their `i3status.conf`. This patch changes `print_battery_info` to expect values for the battery capacity to be strictly greater than zero. This seems reasonable as a battery with a capacity of zero isn't useful. An alternative solution would be to change `slurp_all_batteries` and `add_battery_info` to initialize `batt_info` with `-1`, as `print_battery_info` does. This is less appealing as `add_battery_info` is accumulating the values, so using `-1` would introduce off-by-one errors without additional code to avoid them.
Diffstat (limited to 'testcases')
-rw-r--r--testcases/018-battery-capacity/1/uevent2
-rw-r--r--testcases/018-battery-capacity/expected_output.txt1
-rw-r--r--testcases/018-battery-capacity/i3status.conf10
-rw-r--r--testcases/019-battery-capacity/1/uevent2
-rw-r--r--testcases/019-battery-capacity/expected_output.txt1
-rw-r--r--testcases/019-battery-capacity/i3status.conf11
6 files changed, 27 insertions, 0 deletions
diff --git a/testcases/018-battery-capacity/1/uevent b/testcases/018-battery-capacity/1/uevent
new file mode 100644
index 0000000..00b1148
--- /dev/null
+++ b/testcases/018-battery-capacity/1/uevent
@@ -0,0 +1,2 @@
+POWER_SUPPLY_CHARGE_FULL=100
+POWER_SUPPLY_CHARGE_NOW=50
diff --git a/testcases/018-battery-capacity/expected_output.txt b/testcases/018-battery-capacity/expected_output.txt
new file mode 100644
index 0000000..ab07d0a
--- /dev/null
+++ b/testcases/018-battery-capacity/expected_output.txt
@@ -0,0 +1 @@
+50.00%
diff --git a/testcases/018-battery-capacity/i3status.conf b/testcases/018-battery-capacity/i3status.conf
new file mode 100644
index 0000000..7a3443c
--- /dev/null
+++ b/testcases/018-battery-capacity/i3status.conf
@@ -0,0 +1,10 @@
+general {
+ output_format = "none"
+}
+
+order += "battery all"
+
+battery all {
+ format = "%percentage"
+ path = "testcases/018-battery-capacity/%d/uevent"
+}
diff --git a/testcases/019-battery-capacity/1/uevent b/testcases/019-battery-capacity/1/uevent
new file mode 100644
index 0000000..d004bf1
--- /dev/null
+++ b/testcases/019-battery-capacity/1/uevent
@@ -0,0 +1,2 @@
+POWER_SUPPLY_CHARGE_FULL_DESIGN=100
+POWER_SUPPLY_CHARGE_NOW=50
diff --git a/testcases/019-battery-capacity/expected_output.txt b/testcases/019-battery-capacity/expected_output.txt
new file mode 100644
index 0000000..ab07d0a
--- /dev/null
+++ b/testcases/019-battery-capacity/expected_output.txt
@@ -0,0 +1 @@
+50.00%
diff --git a/testcases/019-battery-capacity/i3status.conf b/testcases/019-battery-capacity/i3status.conf
new file mode 100644
index 0000000..8152d44
--- /dev/null
+++ b/testcases/019-battery-capacity/i3status.conf
@@ -0,0 +1,11 @@
+general {
+ output_format = "none"
+}
+
+order += "battery all"
+
+battery all {
+ format = "%percentage"
+ path = "testcases/019-battery-capacity/%d/uevent"
+ last_full_capacity = true
+}