There is some battery code here, that can likely be adapted. I’m using it on my Tufty. That being said, I “think” there are some complications when you try to run it on a Pico W based device.
pimoroni-pico/micropython/examples/pimoroni_pico_lipo at main · pimoroni/pimoroni-pico (github.com)