def __init__()

in smart-mirror-full/extracted/device/script/src/agt/alexa_gadget.py [0:0]


    def __init__(self, gadget_config_path=None):
        """
        Initialize gadget.

        :param gadget_config_path: (Optional) Path to your Alexa Gadget Configuration .ini file. If you don't pass this in
        then make sure you have created a file with the same prefix as your .py file and '.ini' as the suffix.
        """

        # Load the configuration file into configparser object
        self._load_gadget_config(gadget_config_path)

        # load the agt config
        self._peer_device_bt_addr = None
        self._read_peer_device_bt_address()

        # Get the radio address
        self._read_transport_mode()
        if self._transport_mode == BT:
            self.radio_address = BluetoothAdapter.get_address()
        elif self._transport_mode == BLE:
            self.radio_address = BluetoothLEAdapter.get_address()
        else:
            raise Exception('Invalid transport mode found in the config.'
                            'Please run the launch.py script with the --setup flag again '
                            'to re-configure the transport mode.')

        # Check to make sure deviceType (amazonId) and deviceTypeSecret (alexaGadgetSecret) have been configured
        self.device_type = self._get_value_from_config(_GADGET_SETTINGS, _AMAZON_ID)
        if not self.device_type:
            # if 'amazonId' is not specified, check for presence of 'deviceType' instead
            self.device_type = self._get_value_from_config(_GADGET_SETTINGS, 'deviceType')
            if self.device_type:
                logger.info('Using deprecated deviceType in configuration. Please update your .ini to use ' + _AMAZON_ID)
        if not self.device_type or self.device_type == 'YOUR_GADGET_AMAZON_ID':
            raise Exception('Please specify your ' + _AMAZON_ID + ' in ' + self.gadget_config_path)

        self.device_type_secret = self._get_value_from_config(_GADGET_SETTINGS, _ALEXA_GADGET_SECRET)
        if not self.device_type_secret:
            # if 'alexaGadgetSecret' is not specified, check for presence of 'deviceTypeSecret' instead 
            self.device_type_secret = self._get_value_from_config(_GADGET_SETTINGS, 'deviceTypeSecret')
            if self.device_type_secret:
                logger.info('Using deprecated deviceTypeSecret in configuration. Please update your .ini to use ' + _ALEXA_GADGET_SECRET)
        if not self.device_type_secret or self.device_type_secret == 'YOUR_GADGET_SECRET':
            raise Exception('Please specify your ' + _ALEXA_GADGET_SECRET + ' in ' + self.gadget_config_path)

        # Get endpoint_id from the Gadget config
        self.endpoint_id = self._get_value_from_config(_GADGET_SETTINGS, _ENDPOINT_ID)
        if not self.endpoint_id:
            self.endpoint_id = ('AGT' + self.radio_address)[:16]

        # Get friendly_name from the Gadget config
        self.friendly_name = self._get_value_from_config(_GADGET_SETTINGS, _FRIENDLY_NAME)
        if not self.friendly_name:
            self.friendly_name = 'Gadget' + self.endpoint_id[-3:]

        # Get vendor_id from the Gadget config
        vendor_id = self._get_value_from_config(_GADGET_SETTINGS, _VENDOR_ID)
        if not vendor_id:
            vendor_id = _DEFAULT_VENDOR_ID
        elif vendor_id == '0000':
            raise Exception('0000 is an invalid Vendor ID. Please use FFFF as a default, or your actual Vendor ID.')

        # Get product_id from the Gadget config
        product_id = self._get_value_from_config(_GADGET_SETTINGS, _PRODUCT_ID)
        if not product_id:
            product_id = _DEFAULT_VENDOR_ID

        # Initialize the Transport Adapter object
        if self._transport_mode == BT:
            self._bluetooth = BluetoothAdapter(self.friendly_name, vendor_id, product_id,
                                                      self._on_bluetooth_data_received,
                                                      self._on_bluetooth_connected,
                                                      self._on_bluetooth_disconnected)
        elif self._transport_mode == BLE:
            self._bluetooth = BluetoothLEAdapter(self.endpoint_id, self.friendly_name, self.device_type,
                                                 vendor_id, product_id, self._on_bluetooth_data_received,
                                                 self._on_bluetooth_connected,
                                                 self._on_bluetooth_disconnected)

        # enable auto reconnect, by default
        self._reconnect_status = (0, time.time())

        # flag for ensuring keyboard interrupt is only handled once
        self._keyboard_interrupt_being_handled = False
        # register an interrupt handler to catch 'CTRL + C'
        signal.signal(signal.SIGINT, self._keyboard_interrupt_handler)