async def main(): parser = make_parser("A gateway for accepting zwave events into OpenHouse.") args = parser.parse_args() enable_logging(args.log_target, args.log_level) tree = await make_connection(args) target_by_id = await build_id_map(tree) device = await tree.get_file("/global/zwave-local-controller/device") if not os.path.isfile("./src/oh_zwave.cpp") and os.path.isfile("./oh_zwave/src/oh_zwave.cpp"): os.chdir("oh_zwave") await watch_devices(device, tree, target_by_id)
async def main(): parser = argparse.ArgumentParser(description="Expose the OH DB as a filesystem.") add_common_args(parser) parser.add_argument("--mountpoint", '-m', type=str, metavar="DIR", help="Where to mount the filesystem.") args = parser.parse_args() enable_logging(args.log_target, args.log_level) tree = await Tree.connect((args.home_address, args.home_port), args.ca_chain, args.certificate, args.private_key) th = Thread(target=lambda mp, t, l: FileSystem(mp, t, l).run(True), args=(args.mountpoint, tree, asyncio.get_event_loop())) th.start()
async def main(): args = parse_default_args('Map light style changes to hue commands.') enable_logging(args.log_target, args.log_level) tree = await make_connection(args) # Create the bridge. bridge = await Bridge.create(tree) # Subscribe to all light changes. async def on_color_changed(changes: {str: [str]}): for context, paths in changes.items(): names = names_from_color_paths(paths) await bridge.set_lights_to_color(names, context) await tree.watch_matching_files("/room/*/hue-*/*/color", on_color_changed) return tree, bridge.task
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)
async def main(): parser = make_parser("Inject configuration into a pristine database.") parser.add_argument("--config", type=str, metavar="FILE", help="The configuration to load.") args = parser.parse_args() if not args.config: raise Exception("A configuration file is required!") enable_logging(args.log_target, args.log_level) async with Connection.from_args(args) as tree: assert await tree.list_directory("/") == [], "tree must be empty when starting" with open(args.config, "r", encoding="utf-8") as fp: assert args.config.endswith("yaml") config = yaml.load(fp) formulas = await slurp_config(tree, "/", config) await create_formulas(tree, formulas)
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)
async def main(): parser = make_parser("Map room colors into light colors.") args = parser.parse_args() enable_logging(args.log_target, args.log_level) async with Connection.from_args(args) as tree: palette = defaultdict(dict) # {color_name: {light_kind: Color}} colors = await tree.get_matching_files("/global/palette/*/*light/color") for path, value in colors.items(): color_name = Path(path).parent.parent.name log.info("Learning about color: {}".format(color_name)) color = await Color.create(Path(path), value, tree) palette[color_name][color.light_kind] = color await tree.watch_matching_files("/room/*/color", make_room_color_handler(palette, tree)) while True: try: await asyncio.sleep(500) except KeyboardInterrupt: return