예제 #1
0
def main() -> int:
    """Start Home Assistant."""
    validate_python()

    args = get_arguments()

    if args.script is not None:
        from homeassistant import scripts
        return scripts.run(args.script)

    config_dir = os.path.join(os.getcwd(), args.config)
    ensure_config_path(config_dir)

    # Daemon functions
    if args.pid_file:
        check_pid(args.pid_file)
    if args.daemon:
        daemonize()
    if args.pid_file:
        write_pid(args.pid_file)

    exit_code = setup_and_run_hass(config_dir, args)
    if exit_code == RESTART_EXIT_CODE and not args.runner:
        try_to_restart()

    return exit_code
예제 #2
0
def main() -> int:
    """Start Home Assistant."""
    validate_python()

    args = get_arguments()

    if args.script is not None:
        from homeassistant import scripts
        return scripts.run(args.script)

    config_dir = os.path.join(os.getcwd(), args.config)
    ensure_config_path(config_dir)

    # Daemon functions
    if args.pid_file:
        check_pid(args.pid_file)
    if args.daemon:
        daemonize()
    if args.pid_file:
        write_pid(args.pid_file)

    exit_code = setup_and_run_hass(config_dir, args)
    if exit_code == RESTART_EXIT_CODE and not args.runner:
        try_to_restart()

    return exit_code
예제 #3
0
def main() -> int:
    """Start Home Assistant."""
    validate_python()

    if os.environ.get('HASS_NO_MONKEY') != '1':
        if sys.version_info[:2] >= (3, 6):
            monkey_patch.disable_c_asyncio()
        monkey_patch.patch_weakref_tasks()

    attempt_use_uvloop()

    args = get_arguments()

    if args.script is not None:
        from homeassistant import scripts
        return scripts.run(args.script)

    config_dir = os.path.join(os.getcwd(), args.config)
    ensure_config_path(config_dir)

    # Daemon functions
    if args.pid_file:
        check_pid(args.pid_file)
    if args.daemon:
        daemonize()
    if args.pid_file:
        write_pid(args.pid_file)

    exit_code = setup_and_run_hass(config_dir, args)
    if exit_code == RESTART_EXIT_CODE and not args.runner:
        try_to_restart()

    return exit_code
예제 #4
0
def main() -> int:
    """Start Home Assistant."""
    validate_python()

    if os.environ.get('HASS_NO_MONKEY') != '1':
        if sys.version_info[:2] >= (3, 6):
            monkey_patch.disable_c_asyncio()
        monkey_patch.patch_weakref_tasks()

    attempt_use_uvloop()

    args = get_arguments()

    if args.script is not None:
        from homeassistant import scripts
        return scripts.run(args.script)

    config_dir = os.path.join(os.getcwd(), args.config)
    ensure_config_path(config_dir)

    # Daemon functions
    if args.pid_file:
        check_pid(args.pid_file)
    if args.daemon:
        daemonize()
    if args.pid_file:
        write_pid(args.pid_file)

    exit_code = setup_and_run_hass(config_dir, args)
    if exit_code == RESTART_EXIT_CODE and not args.runner:
        try_to_restart()

    return exit_code
예제 #5
0
def main() -> int:
    """Start Home Assistant."""
    validate_python()

    # Run a simple daemon runner process on Windows to handle restarts
    if os.name == "nt" and "--runner" not in sys.argv:
        nt_args = cmdline() + ["--runner"]
        while True:
            try:
                subprocess.check_call(nt_args)
                sys.exit(0)
            except KeyboardInterrupt:
                sys.exit(0)
            except subprocess.CalledProcessError as exc:
                if exc.returncode != RESTART_EXIT_CODE:
                    sys.exit(exc.returncode)

    args = get_arguments()

    if args.script is not None:
        # pylint: disable=import-outside-toplevel
        from homeassistant import scripts

        return scripts.run(args.script)

    config_dir = os.path.abspath(os.path.join(os.getcwd(), args.config))
    ensure_config_path(config_dir)

    # Daemon functions
    if args.pid_file:
        check_pid(args.pid_file)
    if args.daemon:
        daemonize()
    if args.pid_file:
        write_pid(args.pid_file)

    # pylint: disable=import-outside-toplevel
    from homeassistant import runner

    runtime_conf = runner.RuntimeConfig(
        config_dir=config_dir,
        verbose=args.verbose,
        log_rotate_days=args.log_rotate_days,
        log_file=args.log_file,
        log_no_color=args.log_no_color,
        skip_pip=args.skip_pip,
        safe_mode=args.safe_mode,
        debug=args.debug,
        open_ui=args.open_ui,
    )

    exit_code = runner.run(runtime_conf)
    if exit_code == RESTART_EXIT_CODE and not args.runner:
        try_to_restart()

    return exit_code
예제 #6
0
def main() -> int:
    """Start Home Assistant."""
    validate_python()

    monkey_patch_needed = sys.version_info[:3] < (3, 6, 3)
    if monkey_patch_needed and os.environ.get("HASS_NO_MONKEY") != "1":
        monkey_patch.disable_c_asyncio()
        monkey_patch.patch_weakref_tasks()

    set_loop()

    # Run a simple daemon runner process on Windows to handle restarts
    if os.name == "nt" and "--runner" not in sys.argv:
        nt_args = cmdline() + ["--runner"]
        while True:
            try:
                subprocess.check_call(nt_args)
                sys.exit(0)
            except KeyboardInterrupt:
                sys.exit(0)
            except subprocess.CalledProcessError as exc:
                if exc.returncode != RESTART_EXIT_CODE:
                    sys.exit(exc.returncode)

    args = get_arguments()

    if args.script is not None:
        from homeassistant import scripts

        return scripts.run(args.script)

    config_dir = os.path.join(os.getcwd(), args.config)
    ensure_config_path(config_dir)

    # Daemon functions
    if args.pid_file:
        check_pid(args.pid_file)
    if args.daemon:
        daemonize()
    if args.pid_file:
        write_pid(args.pid_file)

    from homeassistant.util.async_ import asyncio_run

    exit_code = asyncio_run(setup_and_run_hass(config_dir, args))
    if exit_code == RESTART_EXIT_CODE and not args.runner:
        try_to_restart()

    return exit_code  # type: ignore
예제 #7
0
def main() -> int:
    """Start Home Assistant."""
    validate_python()

    monkey_patch_needed = sys.version_info[:3] < (3, 6, 3)
    if monkey_patch_needed and os.environ.get('HASS_NO_MONKEY') != '1':
        if sys.version_info[:2] >= (3, 6):
            monkey_patch.disable_c_asyncio()
        monkey_patch.patch_weakref_tasks()

    set_loop()

    # Run a simple daemon runner process on Windows to handle restarts
    if os.name == 'nt' and '--runner' not in sys.argv:
        nt_args = cmdline() + ['--runner']
        while True:
            try:
                subprocess.check_call(nt_args)
                sys.exit(0)
            except KeyboardInterrupt:
                sys.exit(0)
            except subprocess.CalledProcessError as exc:
                if exc.returncode != RESTART_EXIT_CODE:
                    sys.exit(exc.returncode)

    args = get_arguments()

    if args.script is not None:
        from homeassistant import scripts
        return scripts.run(args.script)

    config_dir = os.path.join(os.getcwd(), args.config)
    ensure_config_path(config_dir)

    # Daemon functions
    if args.pid_file:
        check_pid(args.pid_file)
    if args.daemon:
        daemonize()
    if args.pid_file:
        write_pid(args.pid_file)

    from homeassistant.util.async_ import asyncio_run
    exit_code = asyncio_run(setup_and_run_hass(config_dir, args))
    if exit_code == RESTART_EXIT_CODE and not args.runner:
        try_to_restart()

    return exit_code  # type: ignore # mypy cannot yet infer it
예제 #8
0
def main() -> int:
    """Start Home Assistant."""
    validate_python()

    set_loop()

    # Run a simple daemon runner process on Windows to handle restarts
    if os.name == "nt" and "--runner" not in sys.argv:
        nt_args = cmdline() + ["--runner"]
        while True:
            try:
                subprocess.check_call(nt_args)
                sys.exit(0)
            except KeyboardInterrupt:
                sys.exit(0)
            except subprocess.CalledProcessError as exc:
                if exc.returncode != RESTART_EXIT_CODE:
                    sys.exit(exc.returncode)

    args = get_arguments()

    if args.script is not None:
        from homeassistant import scripts

        return scripts.run(args.script)

    config_dir = os.path.abspath(os.path.join(os.getcwd(), args.config))


    # 获取配置目录
    curPath = os.path.dirname(__file__)
    config_dir = config_info.config_path(curPath, config_dir, "--config" not in sys.argv)

    ensure_config_path(config_dir)

    # Daemon functions
    if args.pid_file:
        check_pid(args.pid_file)
    if args.daemon:
        daemonize()
    if args.pid_file:
        write_pid(args.pid_file)

    exit_code = asyncio.run(setup_and_run_hass(config_dir, args), debug=args.debug)
    if exit_code == RESTART_EXIT_CODE and not args.runner:
        try_to_restart()

    return exit_code