Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    for characteristic in args.characteristics:
        # extract aid, iid and value from cli params
        tmp = characteristic[0].split('.')
        aid = int(tmp[0])
        iid = int(tmp[1])
        value = characteristic[1]

        # first check if the accessories data is in the paring data
        characteristic_type = None
        if 'accessories' not in pairing_data or not get_format(
                pairing_data, aid, iid):
            # nope, so get it via /accessories and save it
            response = sec_http.get('/accessories')
            data = json.loads(response.read().decode())
            pairing_data['accessories'] = data['accessories']
            save_pairing(args.file, pairing_data)
        # after loading the accessories data the aid.iid should be there...
        characteristic_type = get_format(pairing_data, aid, iid)
        if not characteristic_type:
            print('Characteristic {aid}.{iid} not found'.format(aid=aid,
                                                                iid=iid))
            sys.exit(-1)

        # reformat the value to fit the required format
        if characteristic_type == CharacteristicFormats.bool:
            try:
                value = strtobool(value)
            except ValueError:
                print('{v} is no valid boolean!'.format(v=value))
                sys.exit(-1)
        if characteristic_type in [