Ejemplo n.º 1
0
def main():
    parser = make_parser("A gateway for accepting button events into OpenHouse.")
    group = parser.add_argument_group("Where to listen for connections.")
    group.add_argument("-a", "--address", default="0.0.0.0", help="The address to listen for REST on.")
    group.add_argument("-p", "--port", default=8090, type=int, help="The port to listen for REST on.")
    args = parser.parse_args()

    enable_logging(args.log_target, args.log_level)

    tree = asyncio.get_event_loop().run_until_complete(make_connection(args))

    app = web.Application()
    post_handler = make_handler(tree)
    paths = app.router.add_resource(r"/event")
    paths.add_route("POST", post_handler)
    log.info("Listening on '{}:{}'".format(args.address, args.port))
    web.run_app(app, host=args.address, port=args.port)
Ejemplo n.º 2
0
def main():
    desc = 'A REST gateway for interacting with OpenHouse over HTTP.'
    parser = argparse.ArgumentParser(description=desc)
    add_common_args(parser)
    group = parser.add_argument_group("REST specific args")
    group.add_argument('-a', '--address', default='0.0.0.0',
                       help="The address to listen for REST on.")
    group.add_argument('-p', '--port', default=8080, type=int,
                       help="The port to listen for REST on.")
    args = parser.parse_args()

    enable_logging(args.log_target, args.log_level)

    tree = asyncio.get_event_loop().run_until_complete(make_connection(args))

    app = web.Application()
    get_handler, post_handler = make_handler(tree)
    paths = app.router.add_resource(r'/{path:[^{}]+}')
    paths.add_route('GET', get_handler)
    paths.add_route('POST', post_handler)
    log.info("Listening on '{}:{}'".format(args.address, args.port))
    web.run_app(app, host=args.address, port=args.port)