#726525 should parse /sys directly, rather than calling acpi

#726525#5
Date:
2013-10-16 12:40:27 UTC
From:
To:
When my battery is full, fdpowermon still shows "Charging, 98%".
That's because the regexp that extracts the data from the acpi -b
output doesn't match the full status: "Battery 0: Full, 100%".
(This is probably also why removing the battery still shows the old
info, instead of reflecting the current state... see #676213.
The regexp doesn't match, so it just loops without doing anything.)

Perhaps it would also be nicer to directly access the
/sys/class/power_supply/* stuff?  That would prevent spawning
a couple of processes every 3 seconds. Fall back to acpi -b
if the system has an unexpected /sys/class/power_supply/ layout.

The following patch fixes it for me.

thanks,
Paul
--- /usr/bin/fdpowermon	2012-01-11 01:02:58.000000000 +0100
+++ /tmp/fdpowermon	2013-10-15 18:48:07.701382173 +0200
@@ -25,7 +25,7 @@
    open my $acpi, "acpi -b |";
    while ($acpi_output = <$acpi>) {
	chomp $acpi_output;
-		if ($acpi_output =~ /^Battery (\d): ((Dis)?[Cc]harging|Unknown), ((\d)+)%(, ([\d:]*))?/) {
+		if ($acpi_output =~ /^Battery (\d): ((Dis)?[Cc]harging|Unknown|Full), ((\d)+)%(, ([\d:]*))?/) {
	    $bat = $1;
	    $state = $2;
	    $level = $4;

#726525#10
Date:
2013-11-11 15:26:08 UTC
From:
To:
retitle 726525 should parse /sys directly, rather than calling acpi
severity 726525 wishlist
thanks

Op 16-10-13 14:40, Paul Slootman schreef:

This was fixed in fdpowermon 1.6 (which did not make stable only because
it missed the freeze due to my procrastination)

[...]

Yeah, I should probably do that. Polling really isn't a good use of
resources, even if we do it only once every three seconds.

The reason I didn't was lazyness, but that's really not a good enough
excuse. I'll look into this when next I have some time. For now,
retitling and changing severity so this part of the bug stands out ;-)

Since acpi itself does little more than reading files in that directory,
I doubt I'll have more luck in that case (unless there's a bug in my
code, of course, which should then be fixed). Since adding fallback code
would add complexity to fdpowermon _and_ result in code paths which
would see very little testing, I'll just drop that part instead.