- gauge_t value = NAN;
-
- submitted_this_run = 0;
-
- if (getvalue(STATEFS_ROOT "ChargePercentage", &value))
- battery_submit("charge", value, NULL);
- // Use capacity as a charge estimate if ChargePercentage is not available
- else if (getvalue(STATEFS_ROOT "Capacity", &value))
- battery_submit("charge", value, NULL);
-
- if (getvalue(STATEFS_ROOT "Current", &value))
- battery_submit("current", value * 1e-6, NULL); // from uA to A
-
- if (getvalue(STATEFS_ROOT "Energy", &value))
- battery_submit("energy_wh", value * 1e-6, NULL); // from uWh to Wh
-
- if (getvalue(STATEFS_ROOT "Power", &value))
- battery_submit("power", value * 1e-6, NULL); // from uW to W
-
- if (getvalue(STATEFS_ROOT "Temperature", &value))
- battery_submit("temperature", value * 0.1, NULL); // from 10xC to C
-
- if (getvalue(STATEFS_ROOT "TimeUntilFull", &value))
- battery_submit("duration", value, "full");
-
- if (getvalue(STATEFS_ROOT "TimeUntilLow", &value))
- battery_submit("duration", value, "low");
+ value_t v;
+ int success = 0;
+
+ if (parse_value_file(STATEFS_ROOT "ChargePercentage", &v, DS_TYPE_GAUGE) ==
+ 0) {
+ battery_submit("charge", v.gauge, NULL);
+ success++;
+ } else if (parse_value_file(STATEFS_ROOT "Capacity", &v, DS_TYPE_GAUGE) ==
+ 0) {
+ // Use capacity as a charge estimate if ChargePercentage is not available
+ battery_submit("charge", v.gauge, NULL);
+ success++;
+ } else {
+ WARNING("battery plugin: Neither \"" STATEFS_ROOT "ChargePercentage\" "
+ "nor \"" STATEFS_ROOT "Capacity\" could be read.");
+ }