in smart-mirror-full/extracted/device/script/src/agt/alexa_gadget.py [0:0]
def main(self):
"""
Main entry point.
"""
# Parse the args passed in by the caller.
parser = argparse.ArgumentParser()
parser.add_argument('--pair', action='store_true', required=False,
help='Puts the gadget in pairing/discoverable mode. '
'If you are pairing to a previously paired Echo device, '
'please ensure that you first forget the gadget from the Echo device using the Bluetooth menu in Alexa App or Echo\'s screen.')
parser.add_argument('--clear', action='store_true', required=False,
help='Reset gadget by unpairing bonded Echo device and clear config file. '
'Please also forget the gadget from the Echo device using the Bluetooth menu in Alexa App or Echo\'s screen. '
'To put the gadget in pairing mode again, use --pair')
args = parser.parse_args()
# If --clear is passed in, unpair Raspberry Pi with Echo Device
if args.clear:
# in addition to this, also unpair using bt adapter
if self._peer_device_bt_addr is not None:
try:
self._bluetooth.unpair(self._peer_device_bt_addr)
except Exception:
pass
# delete peer address in memory
self._peer_device_bt_addr = None
# delete peer address in config file
self._write_peer_device_bt_address()
logger.info('Successfully unpaired with Echo device over {}.'
.format(self._transport_mode) +
' Please also forget the gadget from the Echo device using the Bluetooth menu in Alexa App or Echo\'s screen.')
if not args.pair:
logger.info('To put the gadget in pairing mode again, use --pair')
# Start pairing or reconnection only if --clear is not passed in OR if --clear is passed in with --pair argument
if not args.clear or (args.clear and args.pair):
# If --pair is passed in, we will only remove the BT address in memory
if args.pair:
# Do not delete the address in config file, this allows the customer to undo the clear
self._peer_device_bt_addr = None
# start the bluetooth daemon
self.start()
# Set discoverable if bluetooth address is not in the configuration file.
if not self.is_paired():
self.set_discoverable(True)
logger.info('Now in pairing mode over {}. Pair {} in the Alexa App.'
.format(self._transport_mode, self.friendly_name))
# current BT implementation requires event loop on mainthread
# if event loop no longer required, block on signal.pause()
self._bluetooth.run()