def __init__(self, adapter_addr=None):
"""Default initialiser.
Creates the interface to the local Bluetooth adapter device.
If address is not given then first device is list is used.
:param adapter_addr: Address of Bluetooth adapter to use.
"""
self.bus = dbus.SystemBus()
if adapter_addr is None:
adapters = list_adapters()
if len(adapters) > 0:
adapter_addr = adapters[0]
self.path = dbus_tools.get_dbus_path(adapter=adapter_addr)
self.adapter_object = self.bus.get_object(
constants.BLUEZ_SERVICE_NAME,
self.path)
self.adapter_methods = dbus.Interface(self.adapter_object,
constants.ADAPTER_INTERFACE)
self.adapter_props = dbus.Interface(self.adapter_object,
dbus.PROPERTIES_IFACE)
self._nearby_timeout = 10
self._nearby_count = 0
self.mainloop = async_tools.EventLoop()
self.bus.add_signal_receiver(dbus_tools.interfaces_added,
dbus_interface=constants.DBUS_OM_IFACE,
signal_name='InterfacesAdded')
self.bus.add_signal_receiver(dbus_tools.properties_changed,
dbus_interface=dbus.PROPERTIES_IFACE,
signal_name='PropertiesChanged',
arg0=constants.DEVICE_INTERFACE,
path_keyword='path')
评论列表
文章目录