try: pairing = controller.get_pairings()[args.alias] data = pairing.list_accessories_and_characteristics() except Exception as e: logging.error(e, exc_info=True) sys.exit(-1) proxy_accessories = create_proxy(data) # create a server and an accessory an run it unless ctrl+c was hit try: httpd = AccessoryServer( server_config_file, logging.getLogger(), request_handler_class=generate_proxy_accessory_request_handler( pairing)) for proxy_accessory in proxy_accessories: httpd.add_accessory(proxy_accessory) httpd.publish_device() logging.info('published device and start serving') httpd.serve_forever() except KeyboardInterrupt: pass # unpublish the device and shut down logging.info('unpublish device') httpd.unpublish_device() httpd.shutdown()
# setup logger logger = logging.getLogger('accessory') logger.setLevel(logging.INFO) ch = logging.StreamHandler() ch.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(ch) logger.info('starting') try: httpd = AccessoryServer(os.path.expanduser('./demoserver.json'), logger) httpd.set_identify_callback(lambda) accessory = Accessory('Light', 'PheonixFi', 'Demoserver', '0001', '0.1') lightService = LightBulbService() # lightService.set_get_value_callback(); lightService.append_characteristic(BrightnessCharacteristic(12345678901)) # lightService.append_characteristic(HueCharacteristic(12345678902)) accessory.services.append(lightService) httpd.add_accessory(accessory) httpd.publish_device() print('published device and start serving') httpd.serve_forever() except KeyboardInterrupt: print('unpublish device') httpd.unpublish_device()