MCPcopy
hub / github.com/ECTO-1A/AppleJuice / toggle_device

Function toggle_device

Pair New Device Notifications/utils/bluetooth_utils.py:79–108  ·  view source on GitHub ↗

Power ON or OFF a bluetooth device. :param dev_id: Device id. :type dev_id: ``int`` :param enable: Whether to enable of disable the device. :type enable: ``bool``

(dev_id, enable)

Source from the content-addressed store, hash-verified

77
78
79def toggle_device(dev_id, enable):
80 """
81 Power ON or OFF a bluetooth device.
82
83 :param dev_id: Device id.
84 :type dev_id: ``int``
85 :param enable: Whether to enable of disable the device.
86 :type enable: ``bool``
87 """
88 hci_sock = socket.socket(socket.AF_BLUETOOTH,
89 socket.SOCK_RAW,
90 socket.BTPROTO_HCI)
91 # print("Power %s bluetooth device %d" % ('ON' if enable else 'OFF', dev_id))
92 # di = struct.pack("HbBIBBIIIHHHH10I", dev_id, *((0,) * 22))
93 # fcntl.ioctl(hci_sock.fileno(), bluez.HCIGETDEVINFO, di)
94 req_str = struct.pack("H", dev_id)
95 request = array.array("b", req_str)
96 try:
97 fcntl.ioctl(hci_sock.fileno(),
98 bluez.HCIDEVUP if enable else bluez.HCIDEVDOWN,
99 request[0])
100 except IOError as e:
101 if e.errno == EALREADY:
102 pass
103 # print("Bluetooth device %d is already %s" % (
104 # dev_id, 'enabled' if enable else 'disabled'))
105 else:
106 raise
107 finally:
108 hci_sock.close()
109
110
111# Types of bluetooth scan

Callers 15

appletv_appleid.pyFile · 0.90
beatssolopro.pyFile · 0.90
beatsx.pyFile · 0.90
tvcolorbalance.pyFile · 0.90
mainFunction · 0.90
setupnewphone.pyFile · 0.90
airpods_pro.pyFile · 0.90
transfernumber.pyFile · 0.90
airpods_max.pyFile · 0.90
homepod.pyFile · 0.90
appletv_homekit.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected