Bug 492480 - Battery monitor labels only battery as Battery 2
Summary: Battery monitor labels only battery as Battery 2
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Battery Monitor (show other bugs)
Version: 6.1.4
Platform: Arch Linux Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2024-09-01 07:03 UTC by Parker Reed
Modified: 2024-09-20 18:32 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.2.0
Sentry Crash Report:


Attachments
Screenshot (54.28 KB, image/png)
2024-09-01 07:03 UTC, Parker Reed
Details
upower (1.57 KB, text/plain)
2024-09-18 06:33 UTC, Parker Reed
Details
plasmawindowed (325.56 KB, image/png)
2024-09-18 08:03 UTC, Parker Reed
Details
powerdevil (162.23 KB, image/png)
2024-09-18 08:10 UTC, Parker Reed
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Parker Reed 2024-09-01 07:03:35 UTC
Created attachment 173188 [details]
Screenshot

SUMMARY

Tray applet shows single battery at /sys/class/power_supply/BAT1 as "Battery 2"

STEPS TO REPRODUCE
1. Have a single battery available to the system labeled as BAT1

OBSERVED RESULT

Label shows "Battery 2"

EXPECTED RESULT

Only show "Battery" if BAT1 is the only one available.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.1.4
KDE Frameworks Version: 6.5.0
Qt Version: 6.8.0
Kernel Version: 6.10.6-arch1-1 (64-bit)
Graphics Platform: Wayland

ADDITIONAL INFORMATION

Attached screenshot
Comment 1 Parker Reed 2024-09-01 07:06:55 UTC
Seemingly all the Framework laptops have their battery labeled as BAT1 which is where I noticed this (Framework 16)
Comment 2 Parker Reed 2024-09-01 09:21:14 UTC
So this may be a recent kernel change to avoid using BAT0. All of my machines on 6.10 are BAT1 and show "Battery 2" in the applet
Comment 3 Parker Reed 2024-09-01 16:05:30 UTC
Checked with a few friends and it looks like even with BAT1 they are only seeing the "Battery" label

So this might be a bug that was introduced in the testing Plasma updates.
Comment 4 Justin Zobel 2024-09-02 04:36:19 UTC
In my git master session I can only see "Battery" on the applet and /sys/class/power_supply/ contains just BAT0 and AC. I'm on 6.10.6 kernel as well.

Does your /sys/class/power_supply/ show any other batteries?
Comment 5 Parker Reed 2024-09-02 15:31:47 UTC
I only show one battery but it is labeled as BAT1, hence getting the "Battery 2" label

ACAD  BAT1  ucsi-source-psy-USBC000:001  ucsi-source-psy-USBC000:002  ucsi-source-psy-USBC000:003  ucsi-source-psy-USBC000:004

All of my AMD machines show as BAT1
Comment 6 Bug Janitor Service 2024-09-17 03:47:06 UTC
๐Ÿ›๐Ÿงน โš ๏ธ This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information, then set the bug status to REPORTED. If there is no change for at least 30 days, it will be automatically closed as RESOLVED WORKSFORME.

For more information about our bug triaging procedures, please read https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging.

Thank you for helping us make KDE software even better for everyone!
Comment 7 Nate Graham 2024-09-17 20:56:32 UTC
So you're only seeing this on Framework hardware? Or elsewhere too?
Comment 8 Parker Reed 2024-09-17 21:13:01 UTC
(In reply to Nate Graham from comment #7)
> So you're only seeing this on Framework hardware? Or elsewhere too?

I am seeing this on all of my AMD hardware currently, so Framework 16 and a T495.

Using up-to-date kernels on Arch Linux.

Currently have 6.2 beta on the Framework and it is still showing the same behavior.
Comment 9 Justin Zobel 2024-09-18 04:41:19 UTC
I'm not seeing this on my all AMD device.

Operating System: Solus 4.5
KDE Plasma Version: 6.1.90
KDE Frameworks Version: 6.7.0
Qt Version: 6.7.2
Kernel Version: 6.10.9-302.current (64-bit)
Graphics Platform: Wayland
Processors: 16 ร— AMD Ryzen 7 PRO 4750U with Radeon Graphics
Memory: 29.1 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Manufacturer: LENOVO
Product Name: 20Y1001SAU
System Version: ThinkPad P14s Gen 1
Comment 10 Parker Reed 2024-09-18 04:45:30 UTC
The behavior is seemingly entirely dependent on whether your /sys/class/power_supply folder has a BAT0 or BAT1.

None of my devices have any capabilities for multiple batteries, but they are all labeled as BAT1, which would be 2.

What is your battery labeled as under sysfs?
Comment 11 Justin Zobel 2024-09-18 04:48:57 UTC
BAT0
Comment 12 Parker Reed 2024-09-18 04:51:58 UTC
I guess this doesn't rule out a kernel bug or configuration issue. The only commonality between my devices is using Arch Linux.

Recently switched to Linux Zen on the framework and its BAT1 as well.

I'll ask around on the framework discussion to see what their devices show.
Comment 13 Parker Reed 2024-09-18 04:59:48 UTC
I'm seeing a bunch of mentions of this being handled with quirks in the kernel

https://github.com/torvalds/linux/commit/c986a7024916c92a775fc8d853fba3cae1d5fde4
Comment 14 Parker Reed 2024-09-18 05:14:29 UTC
Okay, so just realized I do have more AMD hardware.

Steam Deck is also BAT1 but 5.27 but power widget correctly labels it as "Battery".

Ally, FW 16, T495 all on 6.1/6.2 are BAT1 and have the "Battery 2" label.

So, if you need a testing device to triage against, Steam Deck would be a good bet with an up-to-date operating system installed.
Comment 15 Parker Reed 2024-09-18 05:51:14 UTC
Even stranger, I just booted the Ally on 6.10.10 and it's showing BAT0, but the applet still says battery 2.

I could have sworn this was reading BAT1 earlier. There's a second fake PS controller battery, but that's correctly labeled in the power widget.
Comment 16 Parker Reed 2024-09-18 06:33:56 UTC
Created attachment 173815 [details]
upower

I'm hitting this condition without having more than one battery

https://invent.kde.org/plasma/plasma-workspace/-/blob/master/dataengines/powermanagement/powermanagementengine.cpp#L476

For reference here's my Framework upower output
Comment 17 Parker Reed 2024-09-18 06:42:13 UTC
I figured it out finally.

DisplayDevice has battery stats but no vendor info.

This increments unnamedBattery by 1. The real battery comes along and trips it over to 2.

[parker@parker-framework powerdevil]$ upower -i /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Wed 18 Sep 2024 02:40:00 AM EDT (7 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              21.9971 Wh
    energy-full:         84.01 Wh
    energy-rate:         18.7308 W
    charge-cycles:       N/A
    time to empty:       1.2 hours
    percentage:          26%
    icon-name:          'battery-low-symbolic'
Comment 18 Parker Reed 2024-09-18 06:48:46 UTC
Same on the Ally

[parker@rogally ~]$ upower -i /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Wed 18 Sep 2024 02:48:00 AM EDT (27 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              26.211 Wh
    energy-full:         33.957 Wh
    energy-rate:         6.568 W
    charge-cycles:       N/A
    time to empty:       4.0 hours
    percentage:          77%
    icon-name:          'battery-full-symbolic'
Comment 19 Parker Reed 2024-09-18 06:56:17 UTC
Is DisplayDevice not monitor in UPower's world? Now I'm not so sure if that's what's tripping the counter.
Comment 20 Parker Reed 2024-09-18 07:22:19 UTC
I recompiled upower to return nothing on creating the DisplayDevice node. Had no affect on Plasma. Still reporting "Battery 2"
Comment 21 Parker Reed 2024-09-18 08:03:34 UTC
Created attachment 173817 [details]
plasmawindowed

If I run org.kde.plasma.battery with plasmawindowed within the same session it shows the correct "Battery" label

Attached screenshot
Comment 22 Parker Reed 2024-09-18 08:10:57 UTC
Created attachment 173818 [details]
powerdevil

If I kill and restart org_kde_powerdevil it shows up correctly
Comment 23 Parker Reed 2024-09-18 09:47:01 UTC
I was mistaken in my first assumption of it being powermanagementengine

Turns out what handles this for the powerdevil applet is components/batterycontrol/batteriesnamesmonitor_p.cpp

Working through some debug messages to try and see why first start of power devil iterates over two batteries but the restart works fine.
Comment 24 Bug Janitor Service 2024-09-18 10:50:50 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4718
Comment 25 Oliver Beard 2024-09-19 21:04:00 UTC
Git commit 1931e036558be81bf192bfece13134116014fda7 by Oliver Beard.
Committed on 19/09/2024 at 20:45.
Pushed by olib into branch 'master'.

components/batterycontrol: Re-use battery names correctly
Previously, if a battery was seen twice, it would not re-use the existing name, leading to the user seeing a single battery called "Battery 2".
The code has also been re-written to be more intelligible.

M  +28   -18   components/batterycontrol/batteriesnamesmonitor_p.cpp
M  +2    -6    components/batterycontrol/batteriesnamesmonitor_p.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/1931e036558be81bf192bfece13134116014fda7
Comment 26 Oliver Beard 2024-09-19 23:02:16 UTC
Git commit 9f98a249fceb08e6f097e142a00ce5b4dec53fad by Oliver Beard.
Committed on 19/09/2024 at 23:02.
Pushed by olib into branch 'Plasma/6.2'.

components/batterycontrol: Re-use battery names correctly
Previously, if a battery was seen twice, it would not re-use the existing name, leading to the user seeing a single battery called "Battery 2".
The code has also been re-written to be more intelligible.


(cherry picked from commit 1931e036558be81bf192bfece13134116014fda7)

Co-authored-by: Oliver Beard <olib141@outlook.com>

M  +28   -18   components/batterycontrol/batteriesnamesmonitor_p.cpp
M  +2    -6    components/batterycontrol/batteriesnamesmonitor_p.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/9f98a249fceb08e6f097e142a00ce5b4dec53fad