-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbletools.py
More file actions
33 lines (24 loc) · 943 Bytes
/
bletools.py
File metadata and controls
33 lines (24 loc) · 943 Bytes
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
import dbus
BLUEZ_SERVICE_NAME = "org.bluez"
LE_ADVERTISING_MANAGER_IFACE = "org.bluez.LEAdvertisingManager1"
DBUS_OM_IFACE = "org.freedesktop.DBus.ObjectManager"
class BleTools(object):
@classmethod
def get_bus(self):
bus = dbus.SystemBus()
return bus
@classmethod
def find_adapter(self, bus):
remote_om = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, "/"),
DBUS_OM_IFACE)
objects = remote_om.GetManagedObjects()
for o, props in objects.items():
if LE_ADVERTISING_MANAGER_IFACE in props:
return o
return None
@classmethod
def power_adapter(self):
adapter = self.get_adapter()
adapter_props = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter),
"org.freedesktop.DBus.Properties");
adapter_props.Set("org.bluez.Adapter1", "Powered", dbus.Boolean(1))