summaryrefslogtreecommitdiff
path: root/lib/bluetooth/battery.vala
blob: 9fdd70d31d9462e6e5c7f2bb42444c87593aaaa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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; } }

}