[PR #407] Add D-Bus interface for battery monitoring #393

Open
opened 2026-03-02 12:41:00 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/kavishdevar/librepods/pull/407
Author: @1jehuang
Created: 12/28/2025
Status: 🔄 Open

Base: mainHead: feature/dbus-battery-interface


📝 Commits (4)

  • e87019d Add D-Bus interface for battery monitoring
  • 185fa53 Add AirPods Pro 3 support
  • 939f7ba Add additional Bluetooth model ID (0x2720) for AirPods Pro 3
  • 42bbf3f Add --no-tray option to disable system tray icon

📊 Changes

7 files changed (+165 additions, -11 deletions)

View changed files

📝 linux/CMakeLists.txt (+1 -0)
📝 linux/ble/blemanager.cpp (+3 -1)
linux/dbusadaptor.hpp (+111 -0)
📝 linux/enums.h (+6 -1)
📝 linux/main.cpp (+37 -6)
📝 linux/trayiconmanager.cpp (+5 -2)
📝 linux/trayiconmanager.h (+2 -1)

📄 Description

Summary

This PR implements a D-Bus interface that exposes AirPods battery information, enabling integration with status bars (like waybar) and other system monitoring tools.

Changes

  • Added dbusadaptor.hpp - D-Bus adaptor class that exposes battery properties
  • Implemented initializeDBus() in main.cpp to register the D-Bus service
  • Added dbusadaptor.hpp to CMakeLists.txt

D-Bus Interface

Service: me.kavishdevar.librepods
Object Path: /battery
Interface: me.kavishdevar.librepods.Battery

Properties

  • LeftLevel, RightLevel, CaseLevel, HeadsetLevel (int)
  • LeftCharging, RightCharging, CaseCharging, HeadsetCharging (bool)
  • LeftAvailable, RightAvailable, CaseAvailable, HeadsetAvailable (bool)
  • DeviceName (string)
  • Connected (bool)

Methods

  • GetBatteryInfo() - Returns all battery info as a map

Example Usage

# Query all battery info
dbus-send --session --print-reply --dest=me.kavishdevar.librepods \
    /battery me.kavishdevar.librepods.Battery.GetBatteryInfo

Waybar Integration

Example Python script for waybar:

#!/usr/bin/env python3
import subprocess, json

result = subprocess.run([
    'dbus-send', '--session', '--print-reply', '--type=method_call',
    '--dest=me.kavishdevar.librepods', '/battery',
    'me.kavishdevar.librepods.Battery.GetBatteryInfo'
], capture_output=True, text=True)
# Parse and output JSON for waybar...

Test Plan

  • Build compiles successfully
  • D-Bus service registers on session bus
  • GetBatteryInfo() returns correct battery levels
  • Properties update when battery status changes

Summary by CodeRabbit

  • New Features
    • D-Bus integration exposes real-time battery levels, charging/availability, device name, connection state, and a single-call info retrieval for desktop integrations.
    • Added recognition and correct icon/UI support for AirPods Pro 3 models.
    • New command-line option to start the app without showing a system tray icon.

✏️ Tip: You can customize this high-level summary in your review settings.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/kavishdevar/librepods/pull/407 **Author:** [@1jehuang](https://github.com/1jehuang) **Created:** 12/28/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/dbus-battery-interface` --- ### 📝 Commits (4) - [`e87019d`](https://github.com/kavishdevar/librepods/commit/e87019da41289e33bb7e82568edfec887b36bc97) Add D-Bus interface for battery monitoring - [`185fa53`](https://github.com/kavishdevar/librepods/commit/185fa531ab253d4145c50ba26517d8a5c293fd3b) Add AirPods Pro 3 support - [`939f7ba`](https://github.com/kavishdevar/librepods/commit/939f7bacdcb9ce7cb9e9feaf7489fbc22ce960ed) Add additional Bluetooth model ID (0x2720) for AirPods Pro 3 - [`42bbf3f`](https://github.com/kavishdevar/librepods/commit/42bbf3f663aba006867ebd13b8eb88988dff75a7) Add --no-tray option to disable system tray icon ### 📊 Changes **7 files changed** (+165 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `linux/CMakeLists.txt` (+1 -0) 📝 `linux/ble/blemanager.cpp` (+3 -1) ➕ `linux/dbusadaptor.hpp` (+111 -0) 📝 `linux/enums.h` (+6 -1) 📝 `linux/main.cpp` (+37 -6) 📝 `linux/trayiconmanager.cpp` (+5 -2) 📝 `linux/trayiconmanager.h` (+2 -1) </details> ### 📄 Description ## Summary This PR implements a D-Bus interface that exposes AirPods battery information, enabling integration with status bars (like waybar) and other system monitoring tools. ### Changes - Added `dbusadaptor.hpp` - D-Bus adaptor class that exposes battery properties - Implemented `initializeDBus()` in `main.cpp` to register the D-Bus service - Added `dbusadaptor.hpp` to `CMakeLists.txt` ### D-Bus Interface **Service:** `me.kavishdevar.librepods` **Object Path:** `/battery` **Interface:** `me.kavishdevar.librepods.Battery` #### Properties - `LeftLevel`, `RightLevel`, `CaseLevel`, `HeadsetLevel` (int) - `LeftCharging`, `RightCharging`, `CaseCharging`, `HeadsetCharging` (bool) - `LeftAvailable`, `RightAvailable`, `CaseAvailable`, `HeadsetAvailable` (bool) - `DeviceName` (string) - `Connected` (bool) #### Methods - `GetBatteryInfo()` - Returns all battery info as a map ### Example Usage ```bash # Query all battery info dbus-send --session --print-reply --dest=me.kavishdevar.librepods \ /battery me.kavishdevar.librepods.Battery.GetBatteryInfo ``` ### Waybar Integration Example Python script for waybar: ```python #!/usr/bin/env python3 import subprocess, json result = subprocess.run([ 'dbus-send', '--session', '--print-reply', '--type=method_call', '--dest=me.kavishdevar.librepods', '/battery', 'me.kavishdevar.librepods.Battery.GetBatteryInfo' ], capture_output=True, text=True) # Parse and output JSON for waybar... ``` ## Test Plan - [x] Build compiles successfully - [x] D-Bus service registers on session bus - [x] `GetBatteryInfo()` returns correct battery levels - [x] Properties update when battery status changes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * D-Bus integration exposes real-time battery levels, charging/availability, device name, connection state, and a single-call info retrieval for desktop integrations. * Added recognition and correct icon/UI support for AirPods Pro 3 models. * New command-line option to start the app without showing a system tray icon. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librepods#393
No description provided.