diff options
author | Aylur <[email protected]> | 2025-01-28 11:41:33 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2025-01-28 11:41:33 +0100 |
commit | a23ef6a6c0bd9da6c68f8bc5e6d8e1efd9210e09 (patch) | |
tree | 1acc45b813a844440d494e05de8dcf34085ab9d8 /lib/bluetooth/battery.vala | |
parent | d0de56e715cc1982d2eb0097b687c61133a0ff75 (diff) | |
parent | 5418f29bf1c8e3c2ce53add5d0a54b1cd003c13f (diff) |
Merge pull request #141 from ojaskavathe/main
feat: add battery_percentage to bluetooth devices
Diffstat (limited to 'lib/bluetooth/battery.vala')
-rw-r--r-- | lib/bluetooth/battery.vala | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/bluetooth/battery.vala b/lib/bluetooth/battery.vala new file mode 100644 index 0000000..9fdd70d --- /dev/null +++ b/lib/bluetooth/battery.vala @@ -0,0 +1,33 @@ +/** + * Object representing a [[https://github.com/bluez/bluez/blob/master/doc/org.bluez.Battery.rst|battery]]. + */ +internal class AstalBluetooth.Battery : Object { + private IBattery proxy; + + internal ObjectPath object_path { owned get; private set; } + + internal Battery(IBattery proxy) { + this.proxy = proxy; + this.object_path = (ObjectPath)proxy.g_object_path; + proxy.g_properties_changed.connect((props) => { + var map = (HashTable<string, Variant>)props; + foreach (var key in map.get_keys()) { + var prop = kebab_case(key); + if (get_class().find_property(prop) != null) { + notify_property(prop); + } + } + }); + } + + /** + * The percentage of battery left as an unsigned 8-bit integer. + */ + public uint percentage { get { return proxy.percentage; } } + + /** + * Describes where the battery information comes from. + */ + public string source { owned get { return proxy.source; } } + +} |