def main(): """ the main function. :return: none """ args = setup_args_parser() setup_logging(args.loglevel) controller = Controller(ble_adapter=args.adapter) try: controller.load_data(args.file) except HomeKitException as exception: print(exception) logging.debug(exception, exc_info=True) sys.exit(-1) if args.alias not in controller.get_pairings(): print('"{a}" is no known alias'.format(a=args.alias)) sys.exit(-1) try: pairing = controller.get_pairings()[args.alias] pairing.add_pairing(args.pairing_id, args.key, args.permission) if pairing.pairing_data['Connection'] == 'IP': text = 'Please add this to homekit.finish_add_remote_pairing:\n' \ ' -c {c} -i {id} -k {pk}' \ .format(c=pairing.pairing_data['Connection'], id=pairing.pairing_data['AccessoryPairingID'], pk=pairing.pairing_data['AccessoryLTPK'] ) print(text) elif pairing.pairing_data['Connection'] == 'BLE': text = 'Please add this to homekit.finish_add_remote_pairing:\n' \ ' -c {c} -i {id} -m {mac} -k {pk}' \ .format(c=pairing.pairing_data['Connection'], id=pairing.pairing_data['AccessoryPairingID'], mac=pairing.pairing_data['AccessoryMAC'], pk=pairing.pairing_data['AccessoryLTPK'] ) print(text) else: print('Not known') except HomeKitException as exception: print(exception) logging.debug(exception, exc_info=True) sys.exit(-1)
parser = argparse.ArgumentParser(description='HomeKit list pairings app') parser.add_argument('-f', action='store', required=True, dest='file', help='File with the pairing data') parser.add_argument('-a', action='store', required=True, dest='alias', help='alias for the pairing') return parser.parse_args() if __name__ == '__main__': args = setup_args_parser() controller = Controller() controller.load_data(args.file) if args.alias not in controller.get_pairings(): print('"{a}" is no known alias'.format(a=args.alias)) exit(-1) pairing = controller.get_pairings()[args.alias] pairings = pairing.list_pairings() for pairing in pairings: print('Pairing Id: {id}'.format(id=pairing['pairingId'])) print('\tPublic Key: 0x{key}'.format(key=pairing['publicKey'])) print('\tPermissions: {perm} ({type})'.format( perm=pairing['permissions'], type=pairing['controllerType']))
import argparse from homekit.controller import Controller from homekit.log_support import setup_logging, add_log_arguments def setup_args_parser(): parser = argparse.ArgumentParser(description='HomeKit remove pairing app') parser.add_argument('-f', action='store', required=True, dest='file', help='File with the pairing data') parser.add_argument('-a', action='store', required=True, dest='alias', help='alias for the pairing') parser.add_argument('--adapter', action='store', dest='adapter', default='hci0', help='the bluetooth adapter to be used (defaults to hci0)') add_log_arguments(parser) return parser.parse_args() if __name__ == '__main__': args = setup_args_parser() setup_logging(args.loglevel) controller = Controller(args.adapter) controller.load_data(args.file) if args.alias not in controller.get_pairings(): print('"{a}" is no known alias'.format(a=args.alias)) exit(-1) controller.remove_pairing(args.alias) controller.save_data(args.file) print('Pairing for "{a}" was removed.'.format(a=args.alias))
parser.add_argument('-f', action='store', required=True, dest='file', help='HomeKit pairing data file') parser.add_argument('-a', action='store', required=True, dest='alias', help='alias for the pairing') parser.add_argument('--adapter', action='store', dest='adapter', default='hci0', help='the bluetooth adapter to be used (defaults to hci0)') add_log_arguments(parser) return parser.parse_args() if __name__ == '__main__': args = setup_args_parser() setup_logging(args.loglevel) logging.debug('Using adapter "%s".', args.adapter) controller = Controller(args.adapter) try: controller.load_data(args.file) except Exception as e: print(e) logging.debug(e, exc_info=True) sys.exit(-1) if args.alias in controller.get_pairings(): print('"{a}" is a already known alias'.format(a=args.alias)) sys.exit(-1) if args.pin: pin_function = pin_from_parameter(args.pin) else: pin_function = pin_from_keyboard()
help='accessory ID for the pairing') parser.add_argument('-m', action='store', required=False, dest='mac', help='accessory MAC for the pairing') add_log_arguments(parser) return parser.parse_args() if __name__ == '__main__': args = setup_args_parser() setup_logging(args.loglevel) controller = Controller() try: controller.load_data(args.file) except Exception as e: print(e) logging.debug(e, exc_info=True) sys.exit(-1) try: pairings = controller.get_pairings() if args.alias not in pairings: print('"{a}" is no known alias'.format(a=args.alias)) sys.exit(-1) pairing_data = pairings[args.alias]._get_pairing_data() pairing_data['Connection'] = args.connection
description= 'HomeKit discover app - list all HomeKit devices on the same network') parser.add_argument('-t', action='store', required=False, dest='timeout', type=int, default=10, help='Number of seconds to wait') return parser.parse_args() if __name__ == '__main__': args = setup_args_parser() results = Controller.discover() for info in results: # TODO wait for result of https://github.com/jlusiardi/homekit_python/issues/40 print('Name: {name}'.format(name=info['name'])) print('Url: http_impl://{ip}:{port}'.format(ip=info['address'], port=info['port'])) print('Configuration number (c#): {conf}'.format(conf=info['c#'])) print('Feature Flags (ff): {f} (Flag: {flags})'.format( f=info['flags'], flags=info['ff'])) print('Device ID (id): {id}'.format(id=info['id'])) print('Model Name (md): {md}'.format(md=info['md'])) print('Protocol Version (pv): {pv}'.format(pv=info['pv'])) print('State Number (s#): {sn}'.format(sn=info['s#'])) print('Status Flags (sf): {sf} (Flag: {flags})'.format( sf=info['statusflags'], flags=info['sf'])) print('Category Identifier (ci): {c} (Id: {ci})'.format(
def pin_from_keyboard(): def tmp(): read_pin = '' while re.match(r'^\d{3}-\d{2}-\d{3}$', read_pin) is None: read_pin = input('Enter device pin (XXX-YY-ZZZ): ') return read_pin return tmp if __name__ == '__main__': args = setup_args_parser() setup_logging(args.loglevel) controller = Controller() try: controller.load_data(args.file) except Exception as e: print(e) logging.debug(e, exc_info=True) sys.exit(-1) if args.alias in controller.get_pairings(): print('"{a}" is a already known alias'.format(a=args.alias)) sys.exit(-1) if args.pin: pin_function = pin_from_parameter(args.pin) else: pin_function = pin_from_keyboard()
action='store_true', required=False, dest='unpaired_only', help= 'If activated, this option will show only unpaired HomeKit BLE Devices' ) add_log_arguments(parser) return parser.parse_args() if __name__ == '__main__': args = setup_args_parser() setup_logging(args.loglevel) try: devices = Controller.discover_ble(args.timeout, args.adapter) except Exception as e: print(e) logging.debug(e, exc_info=True) sys.exit(-1) print() for device in devices: if args.unpaired_only and device['sf'] == 0: continue print('Name: {name}'.format(name=device['name'])) print('MAC: {mac}'.format(mac=device['mac'])) print('Configuration number (cn): {conf}'.format(conf=device['cn'])) print('Device ID (id): {id}'.format(id=device['device_id'])) print('Compatible Version (cv): {cv}'.format(cv=device['cv'])) print('Global State Number (s#): {sn}'.format(sn=device['gsn']))
dest='device', help='HomeKit Device ID (use discover to get it)') # parser.add_argument('-p', action='store', required=False, dest='pin', help='HomeKit configuration code') parser.add_argument('-f', action='store', required=False, dest='file', help='HomeKit pairing data file') parser.add_argument('-a', action='store', required=False, dest='alias', help='alias for the pairing') return parser.parse_args() if __name__ == '__main__': args = setup_args_parser() controller = Controller() try: controller.request_pin(args.alias, args.device) # pairing = controller.get_pairings()[args.alias] # pairing.list_accessories_and_characteristics() # controller.save_data(args.file) print('Pin request started check device'.format(a=args.alias)) except Exception as e: print(e) sys.exit(-1)
def prepare_string(input_string): """ Make a string save for printing in a terminal. The string get recoded using the terminals preferred locale and replacing the characters that cannot be encoded. :param input_string: the input string :return: the output string which is save for printing """ return '{t}'.format(t=input_string.encode(locale.getpreferredencoding(), errors='replace').decode()) if __name__ == '__main__': args = setup_args_parser() setup_logging(args.loglevel) results = Controller.discover(args.timeout) for info in results: if args.unpaired_only and info['sf'] == '0': continue print('Name: {name}'.format(name=prepare_string(info['name']))) print('Url: http_impl://{ip}:{port}'.format(ip=info['address'], port=info['port'])) print('Configuration number (c#): {conf}'.format(conf=info['c#'])) print('Feature Flags (ff): {f} (Flag: {flags})'.format( f=info['flags'], flags=info['ff'])) print('Device ID (id): {id}'.format(id=info['id'])) print('Model Name (md): {md}'.format(md=prepare_string(info['md']))) print('Protocol Version (pv): {pv}'.format(pv=info['pv'])) print('State Number (s#): {sn}'.format(sn=info['s#'])) print('Status Flags (sf): {sf} (Flag: {flags})'.format( sf=info['statusflags'], flags=info['sf']))
# unpaired BLE return parsed_args elif parsed_args.device is None and parsed_args.mac is None and parsed_args.file and parsed_args.alias: # paired return parsed_args else: parser.print_help() sys.exit(-1) if __name__ == '__main__': args = setup_args_parser() setup_logging(args.loglevel) controller = Controller(args.adapter) if args.device: try: controller.identify(args.device) except Exception as e: print(e) logging.debug(e, exc_info=True) sys.exit(-1) elif args.mac: try: controller.identify_ble(args.mac, args.adapter) except Exception as e: print(e) logging.debug(e, exc_info=True) sys.exit(-1) else: