Bug 489003

Summary: Cant change power profiles with widget despite power-profiles-daemon being enabled and working
Product: [Plasma] plasmashell Reporter: Zoey Ahmed <bruhzakahmed420666>
Component: Battery MonitorAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: jpetso, justin, kde, kde, natalie_clarius, nate, salvatore.c, sprit152009, tandiv15.bansal
Priority: NOR    
Version: 6.1.0   
Target Milestone: 1.0   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In: 6.2.0
Sentry Crash Report:

Description Zoey Ahmed 2024-06-22 19:40:39 UTC
SUMMARY
On a new Install of Fedora KDE 40, in the power management profile I am unable to change my power profiles or get the battery life left in my laptop [Image 1] , and when I hover it, it states I do not have a battery in my laptop despite the fact I do [Image 2] , and it is detached using upower [Image 3] .
Power-profiles is running without any errors [Image 4]. All 3 power profiles are detected in powerprofilectrl and I am able to change them and have the changes detected. [Image 5].
For reference, I am using the power management widget by itself instead of in the system tray as by default in KDE Plasma. 
When I installed GNOME, it detected my battery and allowed me to change my power profiles properly.

The images are on: https://imgur.com/gallery/kde-3333333333333-775cTMc
SPECS
My laptop is a Lenovo Ideapad 5i Pro Gen 5, with these specs:
Operating System: Fedora Linux 40
KDE Plasma Version: 6.1.0
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.1
Kernel Version: 6.9.5-200.fc40.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 8 × 11th Gen Intel® Core™ i5-1135G7 @ 2.40GHz
Memory: 7.5 GiB of RAM
Graphics Processor: Mesa Intel® Xe Graphics
Manufacturer: LENOVO
Product Name: 82L3
System Version: IdeaPad 5 Pro 14ITL6 

STEPS TO REPRODUCE
1. Install Fedora 40 KDE Plasma on a laptop with a battery
2. Remove the system tray and add the power profile
3. Observe the above described behaviour.
Comment 1 Zoey Ahmed 2024-06-22 19:47:09 UTC
FWIW, I just checked and in the power management panel in the system tray it does report all the information correctly.
https://imgur.com/gallery/squeak-squeak-r3NTw6j
Comment 2 Jakob Petsovits 2024-06-23 10:25:23 UTC
Let me confirm: You added a Power and Battery widget to your desktop, and displays different (incorrect) values there compared with the version in your system tray?

But also in the original imgur album, the second image shows "No Batteries Available" when hovering over the system tray icon... so it's not just the stand-alone widget that's showing wrong values?
Comment 3 Zoey Ahmed 2024-06-23 11:25:22 UTC
(In reply to Jakob Petsovits from comment #2)
> Let me confirm: You added a Power and Battery widget to your desktop, and
> displays different (incorrect) values there compared with the version in
> your system tray?
That is correct. The system tray version is fine, but the standalone power widget is broken.
> 
> But also in the original imgur album, the second image shows "No Batteries
> Available" when hovering over the system tray icon... so it's not just the
> stand-alone widget that's showing wrong values?
Nope thats the standalone widget, the system tray power widget does show my battery, sorry for the confusion
Comment 4 Totore 2024-06-24 07:20:38 UTC
I'm also having that issue.
I can look at battery level and infos in "Infos about System" in KDE Control Center but not in the Plasma Applet.

Operating System: Arch Linux 
KDE Plasma Version: 6.1.0
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.1
Kernel Version: 6.9.6-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 5800HS with Radeon Graphics
Memory: 22.9 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Manufacturer: ASUSTeK COMPUTER INC.
Product Name: ROG Zephyrus G14 GA401QH_GA401QH
System Version: 1.0

systemctl status power-profiles-daemon.service 
● power-profiles-daemon.service - Power Profiles daemon
     Loaded: loaded (/usr/lib/systemd/system/power-profiles-daemon.service; enabled; preset: disabled)
     Active: active (running) since Mon 2024-06-24 08:26:54 CEST; 45min ago
 Invocation: c8a43d5bc6864af6a60dc5cd506f3973
   Main PID: 737 (power-profiles-)
      Tasks: 4 (limit: 28086)
     Memory: 1.5M (peak: 2.4M)
        CPU: 74ms
     CGroup: /system.slice/power-profiles-daemon.service
             └─737 /usr/lib/power-profiles-daemon

giu 24 08:26:54 esseci-arch systemd[1]: Starting Power Profiles daemon...
giu 24 08:26:54 esseci-arch systemd[1]: Started Power Profiles daemon.
Comment 5 César Montoya 2024-06-27 15:46:33 UTC
Can confirm same behavior, from a fresh install of KDE Plasma on Fedora 40, I added the "Power and Battery" widget to the panel, and it displays no batteries, as well as the power-profiles not supported message, relevant terminal outputs (https://pastebin.com/t75TdtHc).

Additional information: Removing the widget and adding it again fixes the issue, but it will appear again on next boot.

SPECS
Operating System: Fedora Linux 40
KDE Plasma Version: 6.1.0
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.1
Kernel Version: 6.9.5-200.fc40.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 8 × 11th Gen Intel® Core™ i5-1135G7 @ 2.40GHz
Memory: 31.1 GiB of RAM
Graphics Processor: Mesa Intel® Xe Graphics
Manufacturer: HP
Product Name: HP Pavilion Laptop 15-eg0xxx
System Version: Type1ProductConfigId
Comment 6 Yaroslav 2024-06-28 07:13:56 UTC
I have the same issue.

Operating System: Fedora Linux 40
KDE Plasma Version: 6.1.1
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.1
Kernel Version: 6.9.6-cb1.0.fc40.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 9 PRO 7940HS w/ Radeon 780M Graphics
Memory: 58.6 ГиБ of RAM
Graphics Processor: AMD Radeon 780M
Manufacturer: HP
Product Name: HP EliteBook 845 14 inch G10 Notebook PC
System Version: SBKPF

That widget does not work:
https://i.imgur.com/UTY6H9W.png

And this works as expected:
https://i.imgur.com/rCqVYDU.png

I'm using tuned:
tuned-2.23.0-5.fc40.noarch
tuned-ppd-2.23.0-5.fc40.noarch
Comment 7 Divyanshu 2024-07-03 04:37:02 UTC
I am also experiencing the same issue. This happens every time I boot up linux. I am using an empty panel and I have added the battery as a widget in that. I have to manually remove and re-add the widget for it work properly. 

Linux/KDE Plasma: Arch Linux - 6.6.36-1-lts (64-bit)
(available in About System)
KDE Plasma Version: 6.1.1
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.2
Graphics Platform: Wayland
Processors: Intel Core i7-1165G7
Memory: 16 GiB of RAM
Graphics Processor: Intelgrated Intel Iris Xe
Manufacturer: Lenovo
Product Name: Lenovo Ideapad Slim 5i Pro
Comment 8 César Montoya 2024-07-28 12:57:23 UTC
I found something interesting about this bug, it would be useful if the others can confirm the behavior:

This issue only appears if you boot WITH the charger connected, when booting the laptop without the charger connected (a.k.a. using battery) the issue is not reproducible.
Comment 9 Nate Graham 2024-07-29 20:27:44 UTC
Fascinating. I can reproduce that with my Lenovo ThinkPad X1 Yoga (gen 4) laptop.

Zoey, can you reproduce it as well?
Comment 10 Totore 2024-07-30 10:32:04 UTC
(In reply to César Montoya from comment #8)
> I found something interesting about this bug, it would be useful if the
> others can confirm the behavior:
> 
> This issue only appears if you boot WITH the charger connected, when booting
> the laptop without the charger connected (a.k.a. using battery) the issue is
> not reproducible.

I tried two times without the charger connected, I can't confirm what you saying, still the issue persist.


Operating System: Arch Linux 
KDE Plasma Version: 6.1.3
KDE Frameworks Version: 6.4.0
Qt Version: 6.7.2
Kernel Version: 6.10.2-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 5800HS with Radeon Graphics
Memory: 22.9 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Manufacturer: ASUSTeK COMPUTER INC.
Product Name: ROG Zephyrus G14 GA401QH_GA401QH
System Version: 1.0
Comment 11 César Montoya 2024-07-30 12:35:39 UTC
(In reply to Totore from comment #10)
> (In reply to César Montoya from comment #8)
> > I found something interesting about this bug, it would be useful if the
> > others can confirm the behavior:
> > 
> > This issue only appears if you boot WITH the charger connected, when booting
> > the laptop without the charger connected (a.k.a. using battery) the issue is
> > not reproducible.
> 
> I tried two times without the charger connected, I can't confirm what you
> saying, still the issue persist.
> 
> 
> Operating System: Arch Linux 
> KDE Plasma Version: 6.1.3
> KDE Frameworks Version: 6.4.0
> Qt Version: 6.7.2
> Kernel Version: 6.10.2-arch1-1 (64-bit)
> Graphics Platform: Wayland
> Processors: 16 × AMD Ryzen 7 5800HS with Radeon Graphics
> Memory: 22.9 GiB of RAM
> Graphics Processor: AMD Radeon Graphics
> Manufacturer: ASUSTeK COMPUTER INC.
> Product Name: ROG Zephyrus G14 GA401QH_GA401QH
> System Version: 1.0

And that is indeed my fault, forgot to add some details :P

While trying to fix the issue I added "acpi_osi=Linux" to the kernel parameters, that's what mitigated the issue and made everything ok when booting without the charger connected, for reference.

Give it a try and tell me if there's any difference.
Comment 12 Totore 2024-07-30 14:13:58 UTC
(In reply to César Montoya from comment #11)
> (In reply to Totore from comment #10)
> > (In reply to César Montoya from comment #8)
> > > I found something interesting about this bug, it would be useful if the
> > > others can confirm the behavior:
> > > 
> > > This issue only appears if you boot WITH the charger connected, when booting
> > > the laptop without the charger connected (a.k.a. using battery) the issue is
> > > not reproducible.
> > 
> > I tried two times without the charger connected, I can't confirm what you
> > saying, still the issue persist.
> > 
> > 
> > Operating System: Arch Linux 
> > KDE Plasma Version: 6.1.3
> > KDE Frameworks Version: 6.4.0
> > Qt Version: 6.7.2
> > Kernel Version: 6.10.2-arch1-1 (64-bit)
> > Graphics Platform: Wayland
> > Processors: 16 × AMD Ryzen 7 5800HS with Radeon Graphics
> > Memory: 22.9 GiB of RAM
> > Graphics Processor: AMD Radeon Graphics
> > Manufacturer: ASUSTeK COMPUTER INC.
> > Product Name: ROG Zephyrus G14 GA401QH_GA401QH
> > System Version: 1.0
> 
> And that is indeed my fault, forgot to add some details :P
> 
> While trying to fix the issue I added "acpi_osi=Linux" to the kernel
> parameters, that's what mitigated the issue and made everything ok when
> booting without the charger connected, for reference.
> 
> Give it a try and tell me if there's any difference.

Tried but nothing changed, the only workaround it's the one you mentioned before. Adding again the widget in the panel resolve the issue, but that has to be done every restart of the system.
Comment 13 César Montoya 2024-08-12 20:11:57 UTC
(In reply to Totore from comment #12)
 
> Tried but nothing changed, the only workaround it's the one you mentioned
> before. Adding again the widget in the panel resolve the issue, but that has
> to be done every restart of the system.

Sorry for the previous noise, I don't know how it solved consistently that time, but it is in fact not a solution, only workaround is what we already agreed upon
Comment 14 Jakob Petsovits 2024-08-12 20:48:56 UTC
I'm going to assume that the issue is in the way that the applet [1] initializes its values. When it is started, it sends a query to D-Bus once per D-Bus service ("org.kde.Solid.PowerManagement", "org.freedesktop.PowerManagement", "net.hadess.PowerProfiles") to see if the interface is present. If the D-Bus service does not exist at initialization time, the applet will stay empty forever.

If any of the queried interfaces isn't online yet, e.g. because plasmashell and its wallpaper desktop area with widget were faster at starting up, then the widget will remain empty. I think it's likely that this is what we're seeing here.

The applet should change its code to observe when an interface gets registered or unregistered, probably with a QDBusServiceWatcher. Once the interface is found or disappears, update the values for use by the applet's QML.

[1] https://invent.kde.org/plasma/powerdevil/-/blob/0f8e6dabc0623305a449a3592ed7bbdf76f5548c/applets/batterymonitor/plugin/powermanagementcontrol.cpp (on master branch between 6.1 and 6.2)
Comment 15 Justin Zobel 2024-09-02 13:13:37 UTC
(In reply to Jakob Petsovits from comment #14)
> I'm going to assume that the issue is in the way that the applet [1]
> initializes its values. When it is started, it sends a query to D-Bus once
> per D-Bus service ("org.kde.Solid.PowerManagement",
> "org.freedesktop.PowerManagement", "net.hadess.PowerProfiles") to see if the
> interface is present. If the D-Bus service does not exist at initialization
> time, the applet will stay empty forever.
> 
> If any of the queried interfaces isn't online yet, e.g. because plasmashell
> and its wallpaper desktop area with widget were faster at starting up, then
> the widget will remain empty. I think it's likely that this is what we're
> seeing here.
> 
> The applet should change its code to observe when an interface gets
> registered or unregistered, probably with a QDBusServiceWatcher. Once the
> interface is found or disappears, update the values for use by the applet's
> QML.
> 
> [1]
> https://invent.kde.org/plasma/powerdevil/-/blob/
> 0f8e6dabc0623305a449a3592ed7bbdf76f5548c/applets/batterymonitor/plugin/
> powermanagementcontrol.cpp (on master branch between 6.1 and 6.2)

Is this something you could start a merge request for?
Comment 16 Jakob Petsovits 2024-09-02 14:45:41 UTC
(In reply to Justin Zobel from comment #15)
> Is this something you could start a merge request for?

I can, but I have a few higher-priority tasks on my list that I'd like to land before 6.2 beta gets released. I'll add the "junior-jobs" label in the meantime, in case someone else is looking for a relatively easy fix to contribute :)
Comment 17 Bug Janitor Service 2024-09-13 18:04:27 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/425
Comment 18 Jakob Petsovits 2024-09-19 18:13:07 UTC
Git commit 8e698dbcdc9ce95095ea2739713fde05ca4822f5 by Jakob Petsovits.
Committed on 19/09/2024 at 18:06.
Pushed by jpetso into branch 'master'.

applets/batterymonitor: React to D-Bus service (un)register events

Previously, the "Power and Battery" applet only checked for the
presence of PowerDevil's D-Bus services once when it starts up.
This appears to (mostly?) work for applets embedded in a panel,
but does not work for applets on the desktop itself.
Likely there's a timing issue and applets on the desktop start
sooner than PowerDevil will advertise its services.

A better way to work is for the applet to monitor the bus for when
the relevant services appear or disappear. When observing a service
registered or unregistered event, the applet gets set up accordingly.

This fixes the race condition for two out of three applet parts
(power profiles, inhibitions) but does not fix battery status;
the data for that is coming from `BatteryControlModel`
in plasma-workspace. A similar fix will have to be implemented there.
Related: bug 488915, bug 492859, bug 492945

M  +88   -12   applets/batterymonitor/plugin/powermanagementcontrol.cpp
M  +10   -2    applets/batterymonitor/plugin/powermanagementcontrol.h
M  +77   -1    applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +10   -1    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/8e698dbcdc9ce95095ea2739713fde05ca4822f5
Comment 19 Bug Janitor Service 2024-09-19 19:26:38 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4729
Comment 20 Jakob Petsovits 2024-09-20 12:48:15 UTC
Git commit 0979a34248efa8eac087e418a4cf4419549ece0c by Jakob Petsovits.
Committed on 20/09/2024 at 12:26.
Pushed by jpetso into branch 'master'.

components/batterycontrol: React to D-Bus service (un)register events

Previously, the "Power and Battery" applet only checked for the
presence of PowerDevil's D-Bus services once when it starts up.
This appears to (mostly?) work for applets embedded in a panel,
but does not work for applets on the desktop itself.
Likely there's a timing issue and applets on the desktop start
sooner than PowerDevil will advertise its services.

A better way to work is for the applet to monitor the bus for when
the relevant services appear or disappear. When observing a service
registered or unregistered event, the applet gets set up accordingly.

This fixes the race condition for one out of three applet parts
(battery state) but does not fix power profiles & inhibitions;
these were fixed separately in the powerdevil repository
via commit 8e698dbc.
Related: bug 488915, bug 492859, bug 492945

M  +82   -15   components/batterycontrol/batterycontrol.cpp
M  +6    -1    components/batterycontrol/batterycontrol.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/0979a34248efa8eac087e418a4cf4419549ece0c
Comment 21 Bug Janitor Service 2024-09-23 21:46:21 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/428
Comment 22 Jakob Petsovits 2024-09-23 21:48:44 UTC
Git commit 5e8cd380806da20d0b12bf97a3629ac70aa2b77c by Jakob Petsovits.
Committed on 23/09/2024 at 21:41.
Pushed by jpetso into branch 'Plasma/6.2'.

applets/batterymonitor: React to D-Bus service (un)register events

Previously, the "Power and Battery" applet only checked for the
presence of PowerDevil's D-Bus services once when it starts up.
This appears to (mostly?) work for applets embedded in a panel,
but does not work for applets on the desktop itself.
Likely there's a timing issue and applets on the desktop start
sooner than PowerDevil will advertise its services.

A better way to work is for the applet to monitor the bus for when
the relevant services appear or disappear. When observing a service
registered or unregistered event, the applet gets set up accordingly.

This fixes the race condition for two out of three applet parts
(power profiles, inhibitions) but does not fix battery status;
the data for that is coming from `BatteryControlModel`
in plasma-workspace. A similar fix will have to be implemented there.
Related: bug 488915, bug 492859, bug 492945

M  +88   -12   applets/batterymonitor/plugin/powermanagementcontrol.cpp
M  +10   -2    applets/batterymonitor/plugin/powermanagementcontrol.h
M  +77   -1    applets/batterymonitor/plugin/powerprofilescontrol.cpp
M  +10   -1    applets/batterymonitor/plugin/powerprofilescontrol.h

https://invent.kde.org/plasma/powerdevil/-/commit/5e8cd380806da20d0b12bf97a3629ac70aa2b77c
Comment 23 Jakob Petsovits 2024-09-23 22:10:42 UTC
Git commit 43ca4f3bf083651c2ac8b803596e3827ed8d5e76 by Jakob Petsovits.
Committed on 23/09/2024 at 21:48.
Pushed by jpetso into branch 'Plasma/6.2'.

components/batterycontrol: React to D-Bus service (un)register events

Previously, the "Power and Battery" applet only checked for the
presence of PowerDevil's D-Bus services once when it starts up.
This appears to (mostly?) work for applets embedded in a panel,
but does not work for applets on the desktop itself.
Likely there's a timing issue and applets on the desktop start
sooner than PowerDevil will advertise its services.

A better way to work is for the applet to monitor the bus for when
the relevant services appear or disappear. When observing a service
registered or unregistered event, the applet gets set up accordingly.

This fixes the race condition for one out of three applet parts
(battery state) but does not fix power profiles & inhibitions;
these were fixed separately in the powerdevil repository
via commit 8e698dbc (master branch) / commit 5e8cd380 (Plasma/6.2).
Related: bug 488915, bug 492859, bug 492945

M  +82   -15   components/batterycontrol/batterycontrol.cpp
M  +6    -1    components/batterycontrol/batterycontrol.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/43ca4f3bf083651c2ac8b803596e3827ed8d5e76