Merge pull request #22 from JuanPotato/pairable

Make device pairable before trying to pair to switch
This commit is contained in:
Robert Martin
2020-04-12 05:09:36 +09:00
committed by GitHub
2 changed files with 9 additions and 0 deletions
+6
View File
@@ -47,6 +47,12 @@ class HidDevice:
""" """
self.properties.Set(self.adapter.dbus_interface, 'Discoverable', boolean) self.properties.Set(self.adapter.dbus_interface, 'Discoverable', boolean)
def pairable(self, boolean=True):
"""
Make adapter pairable
"""
self.properties.Set(self.adapter.dbus_interface, 'Pairable', boolean)
async def set_class(self, cls='0x002508'): async def set_class(self, cls='0x002508'):
""" """
Sets Bluetooth device class. Requires hciconfig system command. Sets Bluetooth device class. Requires hciconfig system command.
+3
View File
@@ -75,6 +75,8 @@ async def create_hid_server(protocol_factory, ctl_psm=17, itr_psm=19, device_id=
itr_sock.listen(1) itr_sock.listen(1)
hid.powered(True) hid.powered(True)
hid.pairable(True)
# setting bluetooth adapter name and class to the device we wish to emulate # setting bluetooth adapter name and class to the device we wish to emulate
await hid.set_name(protocol.controller.device_name()) await hid.set_name(protocol.controller.device_name())
await hid.set_class() await hid.set_class()
@@ -100,6 +102,7 @@ async def create_hid_server(protocol_factory, ctl_psm=17, itr_psm=19, device_id=
# stop advertising # stop advertising
hid.discoverable(False) hid.discoverable(False)
hid.pairable(False)
else: else:
# Reconnection to reconnect_bt_addr # Reconnection to reconnect_bt_addr