Bug 488954 - Current 'Battery protection' state not correctly shown
Summary: Current 'Battery protection' state not correctly shown
Status: RESOLVED FIXED
Alias: None
Product: Powerdevil
Classification: Unmaintained
Component: general (other bugs)
Version First Reported In: 6.1.0
Platform: Arch Linux Linux
: NOR minor
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
: 487745 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-06-22 06:33 UTC by Tim
Modified: 2024-06-25 13:21 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.1.1
Sentry Crash Report:


Attachments
Screenshot of System Settings -> Power Management -> Advanced Power Settings (101.65 KB, image/png)
2024-06-22 06:33 UTC, Tim
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tim 2024-06-22 06:33:03 UTC
Created attachment 170800 [details]
Screenshot of System Settings -> Power Management -> Advanced Power Settings

SUMMARY

When opening System Settings -> Power Management -> Advanced Power Settings the setting 'Battery protection' is shown deactivated even though it is currently activated:

```bash
tim@laptop:~$ cat /sys/bus/platform/drivers/ideapad_acpi/VPC2004\:00/conservation_mode 
1
```

When activating the checkbox 'Limit the maximum battery charge', the Apply button does not become active. Is the view state maybe correct but just not shown?

STEPS TO REPRODUCE

1. Open System Settings -> Power Management -> Advanced Power Settings.
2. Check state of 'Battery protection' shown. (inactive/unselected)
3. Check state of 'Apply' button. (inactive/grey)
4. Activate 'Limit the maximum battery charge'
5. Check state of 'Apply' button. (still inactive/grey)

OBSERVED RESULT

Checkbox 'Limit the maximum battery charge' does not initially reflect system state.

Activating 'Limit the maximum battery charge' does not activate the Apply button.

EXPECTED RESULT

Checkbox 'Limit the maximum battery charge' should be initially shown as activated reflecting the system state of my machine.

SOFTWARE/OS VERSIONS

EndeavourOS/Arch
KDE Plasma Version: 6.1.0
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.1

ADDITIONAL INFORMATION

-
Comment 1 Jakob Petsovits 2024-06-23 10:32:06 UTC
Would this be a duplicate of Bug 487745?
Comment 2 Tim 2024-06-23 13:46:54 UTC
(In reply to Jakob Petsovits from comment #1)
> Would this be a duplicate of Bug 487745?

Yes, I think so. I didn't find that one when searching before reporting.

There are slight differences in the descriptions; A reboot is not necessary to trigger the issue and the 'Apply button' behaviour is not mentioned.
Comment 3 Tim 2024-06-23 18:49:06 UTC
Shouldn't the initial value of the batteryConservationMode be set to the value read by the getconservationmode job similar to the line above?

https://github.com/KDE/powerdevil/blob/master/kcmodule/profiles/ExternalServiceSettings.cpp#L105
Comment 4 Jakob Petsovits 2024-06-23 19:17:06 UTC
(In reply to Tim from comment #3)
> Shouldn't the initial value of the batteryConservationMode be set to the
> value read by the getconservationmode job similar to the line above?
> 
> https://github.com/KDE/powerdevil/blob/master/kcmodule/profiles/ExternalServiceSettings.cpp#L105

So that it reads like this:

setBatteryConservationMode(m_savedBatteryConservationMode);

which was just written by setSavedBatteryConservationMode() with the job result, instead of

setBatteryConservationMode(m_batteryConservationMode);

which is merely the pre-existing value as it was initialized earlier? I think that's an extremely promising attempt at a fix.

Fabian, could you test this change and submit an MR if it fixes the bug?
Comment 5 Tim 2024-06-23 20:07:05 UTC
Yep, it seems that change fixes it and gives the expected behaviour:

```
--- a/kcmodule/profiles/ExternalServiceSettings.cpp
+++ b/kcmodule/profiles/ExternalServiceSettings.cpp
@@ -102,7 +102,7 @@ void ExternalServiceSettings::load(QWindow *parentWindowForKAuth)
 
         const auto data = job->data();
         setSavedBatteryConservationMode(data.value(QStringLiteral("batteryConservationModeEnabled")).toBool());
-        setBatteryConservationMode(m_batteryConservationMode);
+        setBatteryConservationMode(m_savedBatteryConservationMode);
         m_isBatteryConservationModeSupported = true;
     });
 }
```
Comment 6 Bug Janitor Service 2024-06-24 17:33:32 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/384
Comment 7 Tim 2024-06-24 19:57:25 UTC
Git commit 43446c371ba62ab2dd939a242affcd1fd97641e9 by Tim Jagenberg.
Committed on 24/06/2024 at 19:48.
Pushed by jpetso into branch 'master'.

Fix initial UI state of Battery protection setting

The setting 'Battery protection' in System Settings -> Power Management
-> Advanced Power Settings was always initially shown deactivated and
did not reflect the actual state of the system as given in
`/sys/bus/platform/drivers/ideapad_acpi/VPC2004\:00/conservation_mode`.
This was fixed so that the initial GUI state reflects the current system
state.

M  +1    -1    kcmodule/profiles/ExternalServiceSettings.cpp

https://invent.kde.org/plasma/powerdevil/-/commit/43446c371ba62ab2dd939a242affcd1fd97641e9
Comment 8 Jakob Petsovits 2024-06-24 20:01:10 UTC
Git commit 7da820f5ba64766b15c1451ad0fbed3b714ed307 by Jakob Petsovits.
Committed on 24/06/2024 at 19:58.
Pushed by jpetso into branch 'Plasma/6.1'.

Fix initial UI state of Battery protection setting

The setting 'Battery protection' in System Settings -> Power Management
-> Advanced Power Settings was always initially shown deactivated and
did not reflect the actual state of the system as given in
`/sys/bus/platform/drivers/ideapad_acpi/VPC2004\:00/conservation_mode`.
This was fixed so that the initial GUI state reflects the current system
state.


(cherry picked from commit 43446c371ba62ab2dd939a242affcd1fd97641e9)

Co-authored-by: Tim Jagenberg <tim@jagenberg.info>

M  +1    -1    kcmodule/profiles/ExternalServiceSettings.cpp

https://invent.kde.org/plasma/powerdevil/-/commit/7da820f5ba64766b15c1451ad0fbed3b714ed307
Comment 9 Jakob Petsovits 2024-06-24 20:05:32 UTC
*** Bug 487745 has been marked as a duplicate of this bug. ***
Comment 10 Vinícius 2024-06-25 12:55:06 UTC
(In reply to Tim from comment #2)
> (In reply to Jakob Petsovits from comment #1)
> > Would this be a duplicate of Bug 487745?
> 
> Yes, I think so. I didn't find that one when searching before reporting.
> 
> There are slight differences in the descriptions; A reboot is not necessary
> to trigger the issue and the 'Apply button' behaviour is not mentioned.

i didn't mentioned, but i get the same behaviour, i didn't mentioned because i though that the checkbox "syncs" with the system that's why the apply button stay greyed out, so intended behavior i guess?
Comment 11 Jakob Petsovits 2024-06-25 13:16:39 UTC
(In reply to Vinícius from comment #10)
> (In reply to Tim from comment #2)
> > (In reply to Jakob Petsovits from comment #1)
> > > Would this be a duplicate of Bug 487745?
> > 
> > Yes, I think so. I didn't find that one when searching before reporting.
> > 
> > There are slight differences in the descriptions; A reboot is not necessary
> > to trigger the issue and the 'Apply button' behaviour is not mentioned.
> 
> i didn't mentioned, but i get the same behaviour, i didn't mentioned because
> i though that the checkbox "syncs" with the system that's why the apply
> button stay greyed out, so intended behavior i guess?

The incorrect "saved state" would also affect whether the Apply button gets enabled or disabled. Not exactly intended behavior but the fix explains why it would behave incorrectly. I would assume (but can't test on my system) that the fix makes both the checkmark and the button work correctly for both of you.
Comment 12 Vinícius 2024-06-25 13:21:07 UTC
(In reply to Jakob Petsovits from comment #11)

> The incorrect "saved state" would also affect whether the Apply button gets
> enabled or disabled. Not exactly intended behavior but the fix explains why
> it would behave incorrectly. I would assume (but can't test on my system)
> that the fix makes both the checkmark and the button work correctly for both
> of you.

make send, thank you!, gonna test when it lands of fedora rawhide