Skip to content

fix: fallback to sysfs for battery percentage on HID devices#137

Open
jamerrq wants to merge 1 commit intopythops:masterfrom
jamerrq:fix/sysfs-battery-fallback
Open

fix: fallback to sysfs for battery percentage on HID devices#137
jamerrq wants to merge 1 commit intopythops:masterfrom
jamerrq:fix/sysfs-battery-fallback

Conversation

@jamerrq
Copy link
Copy Markdown

@jamerrq jamerrq commented Apr 13, 2026

Closes #134

Problem

Devices like PS4/PS5 controllers report battery via the kernel HID driver
(/sys/class/power_supply/ps-controller-battery-XX:XX:XX:XX:XX:XX/capacity)
instead of the Bluetooth Battery Service profile. Since bluer only reads
from org.bluez.Battery1, these devices always show None for battery.

Solution

Added a read_battery_from_sysfs() fallback function that:

  1. Converts the device MAC address to lowercase
  2. Scans /sys/class/power_supply/ for entries containing the MAC address
  3. Reads the capacity file to get the battery percentage
    This is used as a fallback via .or_else() only when bluer returns None.

Testing

Tested with:

  • Sony DualShock 4 (PS4 controller) — reports battery level ok
Image

@jamerrq jamerrq force-pushed the fix/sysfs-battery-fallback branch from 04f9a6c to a4fb7f4 Compare April 17, 2026 14:39
@sermuns sermuns self-assigned this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Battery percentage not shown for devices using kernel HID driver (PS4/PS5 controllers)

2 participants