marioortizmanero / polybar-pulseaudio-control

A feature-full Polybar module to control PulseAudio
MIT License
478 stars 49 forks source link

Ability to view the battery charge of connected Bluetooth devices #74

Open SfyMantissa opened 1 year ago

SfyMantissa commented 1 year ago

Hello!

I have added new base functionality to view the battery charge of a connected Bluetooth device.

E.g. ~/repos/polybar-pulseaudio-control/pulseaudio-control.bash --color-muted "D75F87" --icons-volume ",奔,墳," --icon-muted "ﱝ" --node-nickname "alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink:ﰝ" --node-nickname "bluez_sink.68_D6_ED_8D_E9_D2.a2dp_sink:" **--icons-bluetooth-battery "ﴆ,ﴇ,ﴈ,ﴉ,ﴊ,ﴋ,ﴌ,ﴍ,ﴎ,ﴅ" --hide-bluetooth-battery-level listen**

Produces the following output in my Polybar (I can now see the battery charge of my headphones).

image

This PR is pretty raw (needs additional refactoring and updates to tests). I will make the adjustments, however I want to know whether such functionality would be welcome in this repo.

Thank you very much in advance for your feedback!

marioortizmanero commented 1 year ago

Sounds like a great idea, thanks for the contribution! I would only say that we shouldn't modify the default value for FORMAT, let's add it as opt-in. Let me know when it's ready for a full review.

SfyMantissa commented 1 year ago

Hello!

Ready for review

I have:

Sample polybar module config

...
[module/volume]
type = custom/script

; Temporary path until I finish my pull request and it gets merged.
exec = ~/repos/polybar-pulseaudio-control/pulseaudio-control.bash --color-muted "ffb86c" --icons-volume ",奔,墳," --icon-muted "ﱝ" --node-nickname "alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink:ﰝ" --node-nickname "bluez_sink.04_CB_88_29_72_66.a2dp_sink:" --icons-bluetooth-battery "ﴆ,ﴇ,ﴈ,ﴉ,ﴊ,ﴋ,ﴌ,ﴍ,ﴎ,ﴅ" --hide-bluetooth-battery-level listen
label-margin = 2
label-foreground = ${colors.dracula-orange}
label-underline = ${colors.dracula-orange}
tail = true
...

How it looks in my bar with these settings and headphones connected:

image

Tests

Case 1: Docker image (as suggested).

sfy@neonblaze: ~/repos/polybar-pulseaudio-control ❱❱ docker run -it pulseaudio-control-tests
root@78db65502259:/# bats tests.bats 
 ✓ nextNode() 
 ✓ volUp() 
 ✓ volDown() 
 ✓ volMute() 
 ✓ getNickname() 
 ✓ getCurCharge()

6 tests, 0 failures

Case 2: local machine, headphones disconnected.

sfy@neonblaze: ~/repos/polybar-pulseaudio-control ❱❱ bluetoothctl info '04:CB:88:29:72:66' | grep Connected && bats tests.bats 
    Connected: no
tests.bats
 - nextNode() (skipped)
 ✓ volUp()
 ✓ volDown()
 ✓ volMute()
 ✓ getNickname()
 ✓ getCurCharge()

6 tests, 0 failures, 1 skipped

Case 3: local machine, headphones connected.

sfy@neonblaze: ~/repos/polybar-pulseaudio-control ❱❱ bluetoothctl info '04:CB:88:29:72:66' | grep Connected && bats tests.bats 
    Connected: yes
tests.bats
 - nextNode() (skipped)
 ✓ volUp()
 ✓ volDown()
 ✓ volMute()
 ✓ getNickname()
 ✓ getCurCharge()

6 tests, 0 failures, 1 skipped

Please, let me know if you need anything else and have a happy New Year!