maniacx / Battery-Health-Charging

GNU General Public License v3.0
157 stars 14 forks source link

threshold not updated error raised even though the change was successful #91

Open SCV-ready opened 1 month ago

SCV-ready commented 1 month ago

bug:

expected behaviour:

changing the profiles using the widget should change the thresholds and update both icon and panel successfully.

actual behaviour:

icon and BAT0 state successfully changed, but the panel raises an error and doesnt display accurate values (NaN/NaN%). moreover, the panel doesnt update to the current selection.

steps to reproduce:

  1. install directly from gnome extensions
  2. add permissions to polkit
  3. switch states using the panel widget.

relevant system details:

System: 
 Kernel: 6.8.9-200.fc39.x86_64 arch: x86_64
    bits: 64
  Desktop: GNOME v: 45.6 Distro: Fedora Linux 39 (Workstation Edition)
Machine:
  Type: Laptop System: LENOVO product: 20H50070IV v: ThinkPad E570
maniacx commented 1 month ago

Sorry for the late reply.

Could you post the output of the following in console/terminal

echo "---- Disabling extension ----"
gnome-extensions disable Battery-Health-Charging@maniacx.github.com

echo "---- Get Device Type ----"
gsettings --schemadir /home/$USER/.local/share/gnome-shell/extensions/Battery-Health-Charging@maniacx.github.com/schemas get org.gnome.shell.extensions.Battery-Health-Charging device-type

echo "---- Read 1 ----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Change Threshold 55/60 ----"
echo '55' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo '60' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Read 2----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Change Threshold 75/80 ----"
echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold
echo '75' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold

echo "---- Read 3----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

gnome-extensions enable Battery-Health-Charging@maniacx.github.com

Copy the whole list of command and paste in terminal Brief description of the command. It will disable the extension, get the device type form gsettings, read threshold, set threshold to 55/60, read again and change threshold to 75/80 and read again. Post the output in your reply.

SCV-ready commented 1 month ago
---- Disabling extension ----
---- Get Device Type ----
20
---- Read 1 ----
80
75
---- Change Threshold 55/60 ----
55
60
---- Read 2----
60
55
---- Change Threshold 75/80 ----
80
75
---- Read 3----
75
75

edit: setting manually the end threshold to 80 post script does make it read correctly as 75/80, so this is probably a timing issue. edit 2: the device entry for single thinkpad BAT0 already does the await between the threshold settings, so this might not be the exact bug in the actual code.

maniacx commented 1 month ago

Strange. I never owned a thinkpad device, but from what I researched that in most thinkpad firmwares require a condition to be met which is start_threshold < end_threshold when we apply threshold. But in your a case it may be opposite,

In the commands I posted earlier.

May be in your case start_threshold needs to be applied before end_threshold.

Lets try somethings again.

echo "---- Disabling extension ----"
gnome-extensions disable Battery-Health-Charging@maniacx.github.com

echo "---- Read 1 ----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Write 1 Change Threshold 55/60 ----"
echo '55' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo '60' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Read 2----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Write 2 Change Threshold 75/80 ----"
echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold
echo '75' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold

echo "---- Read 3----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "Write 3 Change Threshold 55/60 ----"
echo '55' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo '60' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Read 4----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "Write 4 Change Threshold 55/60 ----"
echo '75' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Read 5----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

gnome-extensions enable Battery-Health-Charging@maniacx.github.com

Post the output. I have posted the same commands as previosly posted, to see if it reads 75/75 again for consistency and added additional commands that set threshold back to 55/60, read again and set threhsold to 75/80 but this time start_threshold will be appied before end threshold.

SCV-ready commented 1 month ago
---- Disabling extension ----
---- Read 1 ----
75
75
---- Write 1 Change Threshold 55/60 ----
55
60
---- Read 2----
60
55
---- Write 2 Change Threshold 75/80 ----
80
75
---- Read 3----
75
75
Write 3 Change Threshold 55/60 ----
55
60
---- Read 4----
60
55
Write 4 Change Threshold 55/60 ----
75
tee: /sys/class/power_supply/BAT0/charge_control_start_threshold: Invalid argument
80
---- Read 5----
80
55
maniacx commented 1 month ago

Hmm. Seems like it rejects threshold if start_threshold > end_threshold.

Not sure why the end_threshold wont update when raising threshold with start_threshold > end_threshold conditions met. Guess some issues with firmware.

Since you have mentioned that applying end_threshold again changes value to 80, lets try these command again.

echo "---- Disabling extension ----"
gnome-extensions disable Battery-Health-Charging@maniacx.github.com

echo "---- Read 1 ----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Write 1 Change Threshold 55/60 ----"
echo '55' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo '60' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Read 2----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Write 2 Change Threshold 75/80 ----"
echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold
echo '75' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold

echo "---- Read 3----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "Write 3 Change Threshold 75/80 second attempt ----"
echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold
echo '75' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold

echo "---- Read 4----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "Write 4 Change Threshold 55/60 ----"
echo '55' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo '60' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Read 5----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Write 5 Change Threshold 75/80 ----"
echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold
echo '75' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold

echo "---- Read 6----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "Write 6 Change Threshold end only 80 second attempt ----"
echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo "---- Read 7----"
cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat  /sys/class/power_supply/BAT0/charge_control_end_threshold

gnome-extensions enable Battery-Health-Charging@maniacx.github.com
SCV-ready commented 1 month ago
---- Disabling extension ----
---- Read 1 ----
75
75
---- Write 1 Change Threshold 55/60 ----
55
60
---- Read 2----
60
55
---- Write 2 Change Threshold 75/80 ----
80
75
---- Read 3----
75
75
Write 3 Change Threshold 75/80 second attempt ----
80
75
---- Read 4----
75
75
Write 4 Change Threshold 55/60 ----
55
60
---- Read 5----
60
55
---- Write 5 Change Threshold 75/80 ----
80
75
---- Read 6----
75
75
Write 6 Change Threshold end only 80 second attempt ----
80
---- Read 7----
80
75

i think i saw on the source code on the devices that the firmware takes a while to update, so an await command is used somewhere between the two in the gnome extension (or is supposed to). i also tested applying the changes from the panel and pasting the cat commands after each one. it seems that the first time only registers the lower bound and applies it to both limits, and the second try places the top threshold correctly.

gnome-extensions enablegnome-extensions disable Battery-Health-Charging@maniacx.github.com

echo '55' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo '60' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo 'post 60/55'

cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat /sys/class/power_supply/BAT0/charge_control_end_threshold

echo 'switch'

echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold
echo '75' | sudo tee /sys/class/power_supply/BAT0/charge_control_start_threshold
echo '80' | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

echo 'post 80/75/80'

cat  /sys/class/power_supply/BAT0/charge_control_start_threshold
cat /sys/class/power_supply/BAT0/charge_control_end_threshold

gnome-extensions enablegnome-extensions enable Battery-Health-Charging@maniacx.github.com

running this yielded this output:

55
60
post 60/55
60
55
switch
80
75
80
post 80/75/80
80
75

so when raising thresholds applying upper -> lower -> upper happens to work.

maniacx commented 1 month ago

In this case I can check each threshold and apply threshold again to the one that is not updated.

I will send you a test version later, once I have some free time.

maniacx commented 1 month ago

I have modified the extension and uploaded the new branch https://github.com/maniacx/Battery-Health-Charging/tree/thinkpad_quirky_firmware

Please install by running ./install.sh and test it.

I have Asus laptop, but can usually simulate the different devices such as thinkpads, huawei by just changing the threshold paths to fake once. But this kind of quirky behaviour is difficult to simulate and I cannot test it. So please test it and if there are any issue/bugs, please check the logs.

To check logs, disable extension

Open terminal and run

journalctl -f -o cat /usr/bin/gnome-shell

keep terminal window open and enable extension, check the logs in the terminal window.

Similiarly if you cannot open prefs/settings for this extension. Open another terminal window and check gjs logs

journalctl -f -o cat /usr/bin/gjs

and post them here

SCV-ready commented 1 month ago

testing the new branch now. i enabled the thinkpad option on the device section. looks good from initial tests, will update if it behaves weirdly.

maniacx commented 1 month ago

Oh. For your device, I have added it is a different fix. I am assuming you enabled "Skip threshold verification" in extension prefs. You do not need to Enable "Skip threshold verification" in extension preference. Kindly disable it and test and let me know. If the fix works, I will merge it in the main branch. If it doesn't work, we will see what is the issue and if it gets to complex, I might just discard the fix and you can use it by enabling "Skip threshold verification".

Just help we with the feedback by testing it with "Skip threshold verification" disabled.

SCV-ready commented 1 month ago

these are all the logs.

> journalctf -f -o cat /usr/bin/gnome-shell

JS ERROR: TypeError: this.actor is null
_syncEnabled@resource:///org/gnome/shell/ui/windowManager.js:145:25
onStopped@resource:///org/gnome/shell/ui/windowManager.js:157:35
_makeEaseCallback/<@resource:///org/gnome/shell/ui/environment.js:84:22
_easeActorProperty/<@resource:///org/gnome/shell/ui/environment.js:250:60
_destroyWindowDone@resource:///org/gnome/shell/ui/windowManager.js:1538:21
onStopped@resource:///org/gnome/shell/ui/windowManager.js:1506:39
_makeEaseCallback/<@resource:///org/gnome/shell/ui/environment.js:84:22
_easeActor/<@resource:///org/gnome/shell/ui/environment.js:173:64
@resource:///org/gnome/shell/ui/init.js:21:20

libinput error: event4  - SynPS/2 Synaptics TouchPad: kernel bug: Touch jump detected and discarded.
See https://wayland.freedesktop.org/libinput/doc/1.25.0/touchpad-jumping-cursors.html for details
libinput error: event4  - SynPS/2 Synaptics TouchPad: kernel bug: Touch jump detected and discarded.
See https://wayland.freedesktop.org/libinput/doc/1.25.0/touchpad-jumping-cursors.html for details
libinput error: event4  - SynPS/2 Synaptics TouchPad: kernel bug: Touch jump detected and discarded.
See https://wayland.freedesktop.org/libinput/doc/1.25.0/touchpad-jumping-cursors.html for details
libinput error: event4  - SynPS/2 Synaptics TouchPad: kernel bug: Touch jump detected and discarded.
See https://wayland.freedesktop.org/libinput/doc/1.25.0/touchpad-jumping-cursors.html for details
libinput error: event4  - SynPS/2 Synaptics TouchPad: WARNING: log rate limit exceeded (5 msgs per 24h). Discarding future messages.

> journalctl -f -o cat /usr/bin/gjs 

(empty)

keeping both journalctl terminals open didnt show new messages after using the extension. however the behaviour is the same as from before - end threshold doesnt get updated on a single switch, panel cant get current state + percentages , and an error is raised as a notification.

EDIT: after some time open, with sleep off and on again, more logs:

Object .Gjs_ui_AttachedToBatteryView_AttachedToBatteryView (0x55cfddb3e650), has been already disposed — impossible to access it. This might be caused by the object having been destroyed from C code using something such as destroy(), dispose(), or remove() vfuncs.
== Stack trace for context 0x55cfdb693aa0 ==
#0   55cfdb75ed38 i   file:///home/{USER}/.local/share/gnome-shell/extensions/GPU_profile_selector@lorenzo9904.gmail.com/extension.js:32 (2b362e757d80 @ 42)
#1   7ffdf7f5f5a0 b   resource:///org/gnome/shell/ui/extensionSystem.js:202 (dc0b4c1ec40 @ 511)
#2   55cfdb75ebb0 i   resource:///org/gnome/shell/ui/extensionSystem.js:619 (dc0b4c244c0 @ 381)
#3   55cfdb75eb20 i   resource:///org/gnome/shell/ui/extensionSystem.js:799 (dc0b4c24b50 @ 25)
#4   55cfdb75eaa0 i   resource:///org/gnome/shell/ui/extensionSystem.js:44 (dc0b4c1e830 @ 13)
#5   7ffdf7f5ff10 b   resource:///org/gnome/gjs/modules/core/_signals.js:130 (33f4855968d0 @ 126)
#6   7ffdf7f5fff0 b   resource:///org/gnome/gjs/modules/core/_signals.js:119 (33f4855967e0 @ 286)
#7   7ffdf7f60770 b   resource:///org/gnome/shell/ui/sessionMode.js:212 (2785d1c6ac40 @ 304)
#8   55cfdb75e948 i   resource:///org/gnome/shell/ui/sessionMode.js:170 (2785d1c6ab00 @ 66)
#9   55cfdb75e898 i   resource:///org/gnome/shell/ui/screenShield.js:617 (2785d1c63a10 @ 211)
#10   55cfdb75e808 i   resource:///org/gnome/shell/ui/screenShield.js:340 (2785d1c63240 @ 36)
#11   55cfdb75e780 i   resource:///org/gnome/shell/ui/lightbox.js:202 (33f4855f8c40 @ 29)
#12   7ffdf7f62900 b   resource:///org/gnome/shell/ui/environment.js:86 (2b362e7543d0 @ 98)
#13   55cfdb75e6f8 i   resource:///org/gnome/shell/ui/environment.js:173 (33f4855e7060 @ 14)
#14   55cfdb75e668 i   resource:///org/gnome/shell/ui/init.js:21 (33f485570ba0 @ 48)
Object .Gjs_ui_AttachedToBatteryView_AttachedToBatteryView (0x55cfdd7e0af0), has been already disposed — impossible to access it. This might be caused by the object having been destroyed from C code using something such as destroy(), dispose(), or remove() vfuncs.
== Stack trace for context 0x55cfdb693aa0 ==
#0   55cfdb75ebc0 i   file:///home/{USER}/.local/share/gnome-shell/extensions/GPU_profile_selector@lorenzo9904.gmail.com/extension.js:32 (2b362e757d80 @ 42)
#1   55cfdb75eaf0 i   resource:///org/gnome/shell/ui/extensionSystem.js:195 (dc0b4c1ec40 @ 396)
#2   55cfdb75ea38 i   resource:///org/gnome/shell/ui/extensionSystem.js:619 (dc0b4c244c0 @ 381)
#3   55cfdb75e9b8 i   resource:///org/gnome/shell/ui/extensionSystem.js:705 (dc0b4c24830 @ 12)
#4   7ffdf7f61bd0 b   resource:///org/gnome/gjs/modules/core/overrides/Gio.js:730 (33f485591c40 @ 169)
#5   55cfdb75e910 i   resource:///org/gnome/shell/ui/extensionSystem.js:292 (dc0b4c1ed80 @ 217)
#6   55cfdb75e888 i   resource:///org/gnome/shell/ui/shellDBus.js:457 (2785d1c69a60 @ 25)
#7   55cfdb75e7a8 i   resource:///org/gnome/gjs/modules/core/overrides/Gio.js:329 (33f48558aec0 @ 185)
#8   55cfdb75e6f8 i   resource:///org/gnome/gjs/modules/core/overrides/Gio.js:408 (33f485591060 @ 34)
#9   55cfdb75e668 i   resource:///org/gnome/shell/ui/init.js:21 (33f485570ba0 @ 48)

EDIT 2: the skip threshold verification also doesn't apply limits correctly, specifically upper bound again after going from 100/95 to 80/75 returns 100/75 eventually.

something interesting though(and bizarre): it seems that there is a quirk with polling the battery that is related to the update of the values.

after using watch -n 5 "cat /sys/class/power_supply/BAT0/charge_control_start_threshold; cat /sys/class/power_supply/BAT0/charge_control_end_threshold" and watch -n 0.01 "cat /sys/class/power_supply/BAT0/charge_control_start_threshold; cat /sys/class/power_supply/BAT0/charge_control_end_threshold" and switching states without the skip verification, the values only switched in the speed in which they were polled. after each switch, while the error notification popped up, the thresholds wound up stabilising on the correct values. as if all of the changes were queued and only applied on a poll to the value. (there is an initial delay of about half a second which i assume is code related, but then it updates almost instantly on faster poll rates)

maniacx commented 1 month ago

Since skip threshold verification wont work for your case in future test leave is DISABLED

I have added some logs to get a better idea of what going on.

Install the updated branch and start logging using

journalctf -f -o cat /usr/bin/gnome-shell

Enable the extension.

Make changes to threshold and post result. I made changes using github editor, so there might be some syntax error (No eslint to verify and no time to boot my linux so just using github web editor), hopefully not silly syntax error. try it and let me know

SCV-ready commented 4 weeks ago

just installed the new branch, rebooted my machine, disabled the extension, ran this and re-enabled it and ran a bunch of changes to the limits.

$ journalctl -f -o cat /usr/bin/gnome-shell 
---- Battery Health Charging : Pre-write this._startValue = 75
---- Battery Health Charging : Pre-write this._oldEndValue = 80
---- Battery Health Charging : Pre-write this._oldStartValue = 80
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 80
---- Battery Health Charging : Post-write this._startValue = 75
---- Battery Health Charging : Post-write this._oldEndValue = 80
---- Battery Health Charging : Post-write this._oldStartValue = 80
---- Battery Health Charging : Updated START threshold with this._status = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 80
---- Battery Health Charging : Pre-write this._startValue = 75
---- Battery Health Charging : Pre-write this._oldEndValue = 75
---- Battery Health Charging : Pre-write this._oldStartValue = 80
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 80
---- Battery Health Charging : Post-write this._startValue = 75
---- Battery Health Charging : Post-write this._oldEndValue = 75
---- Battery Health Charging : Post-write this._oldStartValue = 80
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 100
---- Battery Health Charging : Pre-write this._startValue = 95
---- Battery Health Charging : Pre-write this._oldEndValue = 75
---- Battery Health Charging : Pre-write this._oldStartValue = 80
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 100
---- Battery Health Charging : Post-write this._startValue = 95
---- Battery Health Charging : Post-write this._oldEndValue = 95
---- Battery Health Charging : Post-write this._oldStartValue = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 60
---- Battery Health Charging : Pre-write this._startValue = 55
---- Battery Health Charging : Pre-write this._oldEndValue = 95
---- Battery Health Charging : Pre-write this._oldStartValue = 0
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 60
---- Battery Health Charging : Post-write this._startValue = 55
---- Battery Health Charging : Post-write this._oldEndValue = 60
---- Battery Health Charging : Post-write this._oldStartValue = 60
---- Battery Health Charging : Updated START threshold with this._status = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 80
---- Battery Health Charging : Pre-write this._startValue = 75
---- Battery Health Charging : Pre-write this._oldEndValue = 55
---- Battery Health Charging : Pre-write this._oldStartValue = 60
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 80
---- Battery Health Charging : Post-write this._startValue = 75
---- Battery Health Charging : Post-write this._oldEndValue = 75
---- Battery Health Charging : Post-write this._oldStartValue = 80
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 60
---- Battery Health Charging : Pre-write this._startValue = 55
---- Battery Health Charging : Pre-write this._oldEndValue = 75
---- Battery Health Charging : Pre-write this._oldStartValue = 80
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 60
---- Battery Health Charging : Post-write this._startValue = 55
---- Battery Health Charging : Post-write this._oldEndValue = 60
---- Battery Health Charging : Post-write this._oldStartValue = 60
---- Battery Health Charging : Updated START threshold with this._status = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 100
---- Battery Health Charging : Pre-write this._startValue = 95
---- Battery Health Charging : Pre-write this._oldEndValue = 55
---- Battery Health Charging : Pre-write this._oldStartValue = 60
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 100
---- Battery Health Charging : Post-write this._startValue = 95
---- Battery Health Charging : Post-write this._oldEndValue = 95
---- Battery Health Charging : Post-write this._oldStartValue = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 80
---- Battery Health Charging : Pre-write this._startValue = 75
---- Battery Health Charging : Pre-write this._oldEndValue = 95
---- Battery Health Charging : Pre-write this._oldStartValue = 0
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 80
---- Battery Health Charging : Post-write this._startValue = 75
---- Battery Health Charging : Post-write this._oldEndValue = 80
---- Battery Health Charging : Post-write this._oldStartValue = 80
---- Battery Health Charging : Updated START threshold with this._status = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 100
---- Battery Health Charging : Pre-write this._startValue = 95
---- Battery Health Charging : Pre-write this._oldEndValue = 75
---- Battery Health Charging : Pre-write this._oldStartValue = 80
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 100
---- Battery Health Charging : Post-write this._startValue = 95
---- Battery Health Charging : Post-write this._oldEndValue = 95
---- Battery Health Charging : Post-write this._oldStartValue = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 60
---- Battery Health Charging : Pre-write this._startValue = 55
---- Battery Health Charging : Pre-write this._oldEndValue = 95
---- Battery Health Charging : Pre-write this._oldStartValue = 0
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 60
---- Battery Health Charging : Post-write this._startValue = 55
---- Battery Health Charging : Post-write this._oldEndValue = 60
---- Battery Health Charging : Post-write this._oldStartValue = 60
---- Battery Health Charging : Updated START threshold with this._status = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
---- Battery Health Charging : ----- Start set threshold
---- Battery Health Charging : Pre-write this._endValue = 100
---- Battery Health Charging : Pre-write this._startValue = 95
---- Battery Health Charging : Pre-write this._oldEndValue = 55
---- Battery Health Charging : Pre-write this._oldStartValue = 60
---- Battery Health Charging : Post-write this._status = 0
---- Battery Health Charging : Post-write this._endValue = 100
---- Battery Health Charging : Post-write this._startValue = 95
---- Battery Health Charging : Post-write this._oldEndValue = 95
---- Battery Health Charging : Post-write this._oldStartValue = 0
---- Battery Health Charging : _reVerifyThreshold with this._status = 0
maniacx commented 4 weeks ago

That is quite strange.

It is so random, Sometimes applied start threshold is read on both charge_control_end_threshold and charge_control_start_threshold. Sometime applied end threshold value is read on both charge_control_end_threshold and charge_control_start_threshold,. on both charge_control_end_threshold and charge_control_start_threshold, Sometimes applied start threshold is read in charge_control_end_threshold and end threshold is read in charge_control_start_threshold.

I cannot find any pattern here on how the threshold values are applied and read. So i do not know what logic to apply, to fix this issue.

This is something, I should have asked first before trying to fix the extension, but it forgot to ask. Did you try to reset the Embedded controller? You can do this by 1) Resettting Bios settings to factory defaults (Note/Save all information regarding booting order or any changes you have made to the bios so that you can reapply them after doing resetting your BIOS to factory defaults. 2) Some thinkpads have a reset hold, where you can use a pin to push the button for 5 to 10 seconds to clear the embedded controller when laptop is of 3) Some models, (that do not have reset hold) you need to press power and hold button for 10+ seconds to reset emebedded controller when laptop is off/

or 4) Also are you using the latest BIOS firmware, Although you are on your own if you decide to update BIOS firmware, as crash or power loss during BIOS update can completely break down making laptop unrepairable if BIOS firmware update get interrupted, and I do not want to be blamed for this.

Point 1, 2 and 3 have fixed these kinda off issue on some thinkpads whilst on other thinkpads point 4 (BIOS update) has seems to have fixed these kinda off issue. I would recommend point 1, 2 or 3. .

For bios updates would be last resort and do it if, only if it is not using the latest vesion and if you are comfortable updating firmware.

SCV-ready commented 4 weeks ago

i am hesitant on resetting the bios settings due to remembering that some of them i changed on purpose (mostly due to stability with nvidia drivers, which is an unrelated issue), but i don't quite remember all the changes, and i would rather not tinker with it too much for stability reasons. however, the battery/power section is default already as far as i remember.

i did an EC reset, no change. bios is latest for this model.

there is something odd going on with the timing of things and reading the values from the device. weirdly enough things work out correctly when i run without skip verification, and with a constant polling of the hardware values.

i might try and tinker with the extension on my machine as well since its easier to debug locally(especially with random behaviour like this), maybe it will narrow it down a bit. it is sufficient to change the devices/thinkpad.js file for this, right?

maniacx commented 4 weeks ago

Yeah I think it is best if you can try and debug a little more.

Thinkpad.js is sufficient, unless just for reading and writing threshold. I try to explain a little bit.

In thinkpad.js Your section would be Line 10 to 18 that is related to BAT0

And the class ThinkpadSingleBatteryBAT0 Line 205 to 425, although the force discharge part is not related to you so Line 205 to 343.


Writing threshold runCommandCtl is what is used to write threshold. example

[this._status] = await runCommandCtl(this._ctlPath, 'BAT0_END_START', `${this._endValue}`, `${this._startValue}`, null)

BAT0_END_START Can be found here in batteryhealthchargingctl. it is bash script uses command like echo) https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/resources/batteryhealthchargingctl#L63-L67 where it will apply end threshold first before start threshold later


Reading threshold this._oldEndValue = readFileInt(BAT0_END_PATH) Basically reads threshold from '/sys/class/power_supply/BAT0/charge_control_end_threshold' where BAT0_END_PATH is defined here https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/devices/Thinkpad.js#L11


Verify threshold Reads the threshold, if read value (this._oldEndValue) is equal to applied threshold value by extension (this._endValue) (aslo same ccheck for start threshold). then it updates UI, by emitting a signal. this.emit('threshold-applied', 'success'); when signal is emitted, the UI part of extension will read this.endLimitValue and this.startLimitValue and this value will be display in QS Panel and Notifcation.

If signal emitted is this.emit('threshold-applied', 'failed'); the UI will give a notification that error has occurred. https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/devices/Thinkpad.js#L318-L328


In summary 1. first the extension verifies, https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/devices/Thinkpad.js#L270-L271 if read threshold is equal to threshold applied, this is to prevent the extension for writing threshold again if the new threshold to be applied is already applied, so no point of writing. when extension in enabled by user, resuming from sleep, or hibernation or loggin in. If equal it updates UI and exits class

2. if not equal it will write new threshold. https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/devices/Thinkpad.js#L276-L279

3. Verifies again https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/devices/Thinkpad.js#L289-L292 if correctly applied updates UI and exit class. If incorrectly update continue with step4

4. This is what I added as a fix for your model. https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/devices/Thinkpad.js#L298-L304 As i thought with earlier testing that end threshold doesnt get updated and need to be applied again. but seems like this isnt the case. The original extension doesnt contain step 4

5. After verification fails at step3 create a delay, wait for 200ms and call reverifyThreshold() https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/devices/Thinkpad.js#L310-L316

6.reverifyThreshold() which calls verifythreshold() again to check if threshold are applied correctly, it is still fails to update after 200ms, it emit signal informing UI threshold-applied has failed https://github.com/maniacx/Battery-Health-Charging/blob/834eaef54c45f41f08a95820674211fc8d3b3899/devices/Thinkpad.js#L330-L342

Happy debugging