-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
...from ConnectionNotifier
- Loading branch information
Showing
4 changed files
with
50 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
from blueman.bluez.AnyBase import AnyBase | ||
|
||
from blueman.bluez.Base import Base | ||
|
||
_INTERFACE = "org.bluez.Battery1" | ||
|
||
|
||
class Battery(Base): | ||
_interface_name = "org.bluez.Battery1" | ||
_interface_name = _INTERFACE | ||
|
||
|
||
class AnyBattery(AnyBase): | ||
def __init__(self) -> None: | ||
super().__init__(_INTERFACE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import weakref | ||
from typing import Callable | ||
|
||
from blueman.bluez.Battery import Battery, AnyBattery | ||
from blueman.bluez.Manager import Manager | ||
|
||
|
||
class BatteryWatcher: | ||
def __init__(self, callback: Callable[[str, int], None]) -> None: | ||
super().__init__() | ||
manager = Manager() | ||
weakref.finalize( | ||
self, | ||
manager.disconnect_signal, | ||
manager.connect_signal( | ||
"battery-created", | ||
lambda _manager, obj_path: callback(obj_path, Battery(obj_path=obj_path)["Percentage"]) | ||
) | ||
) | ||
|
||
any_battery = AnyBattery() | ||
weakref.finalize( | ||
self, | ||
any_battery.disconnect_signal, | ||
any_battery.connect_signal( | ||
"property-changed", | ||
lambda _any_battery, key, value, path: callback(path, value) if key == "Percentage" else None | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters