def device_config_callback(self, callback_data): """Handle initial pairing.""" # pylint: disable=import-error import homekit pairing_id = str(uuid.uuid4()) code = callback_data.get('code').strip() try: self.connect() self.pairing_data = homekit.perform_pair_setup( self.conn, code, pairing_id) except homekit.exception.UnavailableError: error_msg = "This accessory is already paired to another device. \ Please reset the accessory and try again." _configurator = self.hass.data[DOMAIN + self.hkid] self.configurator.notify_errors(_configurator, error_msg) return except homekit.exception.AuthenticationError: error_msg = "Incorrect HomeKit code for {}. Please check it and \ try again.".format(self.model) _configurator = self.hass.data[DOMAIN + self.hkid] self.configurator.notify_errors(_configurator, error_msg) return except homekit.exception.UnknownError: error_msg = "Received an unknown error. Please file a bug." _configurator = self.hass.data[DOMAIN + self.hkid] self.configurator.notify_errors(_configurator, error_msg) raise if self.pairing_data is not None: homekit.save_pairing(self.pairing_file, self.pairing_data) _configurator = self.hass.data[DOMAIN + self.hkid] self.configurator.request_done(_configurator) self.accessory_setup() else: error_msg = "Unable to pair, please try again" _configurator = self.hass.data[DOMAIN + self.hkid] self.configurator.notify_errors(_configurator, error_msg)
def device_config_callback(self, callback_data): """Handle initial pairing.""" # pylint: disable=import-error import homekit pairing_id = str(uuid.uuid4()) code = callback_data.get('code').strip() try: self.connect() self.pairing_data = homekit.perform_pair_setup(self.conn, code, pairing_id) except homekit.exception.UnavailableError: error_msg = "This accessory is already paired to another device. \ Please reset the accessory and try again." _configurator = self.hass.data[DOMAIN+self.hkid] self.configurator.notify_errors(_configurator, error_msg) return except homekit.exception.AuthenticationError: error_msg = "Incorrect HomeKit code for {}. Please check it and \ try again.".format(self.model) _configurator = self.hass.data[DOMAIN+self.hkid] self.configurator.notify_errors(_configurator, error_msg) return except homekit.exception.UnknownError: error_msg = "Received an unknown error. Please file a bug." _configurator = self.hass.data[DOMAIN+self.hkid] self.configurator.notify_errors(_configurator, error_msg) raise if self.pairing_data is not None: homekit.save_pairing(self.pairing_file, self.pairing_data) _configurator = self.hass.data[DOMAIN+self.hkid] self.configurator.request_done(_configurator) self.accessory_setup() else: error_msg = "Unable to pair, please try again" _configurator = self.hass.data[DOMAIN+self.hkid] self.configurator.notify_errors(_configurator, error_msg)
return parser.parse_args() iOSPairingId = str(uuid.uuid4()) if __name__ == '__main__': args = setup_args_parser() if os.path.isfile(args.file) and not args.overwrite: print('The pairing data file already exists!') exit(-1) connection_data = find_device_ip_and_port(args.device) if connection_data is None: print('Device {id} not found'.format(id=args.device)) sys.exit(-1) conn = HomeKitHTTPConnection(connection_data['ip'], port=connection_data['port']) try: pairing = perform_pair_setup(conn, args.pin, iOSPairingId) # add ip and port to pairing data pairing['AccessoryIP'] = connection_data['ip'] pairing['AccessoryPort'] = connection_data['port'] save_pairing(args.file, pairing) except UnavailableError: print('The accessory is already paired!') exit(1)