def run(args): """Handle Safegate Pro auth provider script.""" parser = argparse.ArgumentParser(description="Manage Safegate Pro users") parser.add_argument("--script", choices=["auth"]) parser.add_argument( "-c", "--config", default=get_default_config_dir(), help="Directory that contains the Safegate Pro configuration", ) subparsers = parser.add_subparsers(dest="func") subparsers.required = True parser_list = subparsers.add_parser("list") parser_list.set_defaults(func=list_users) parser_add = subparsers.add_parser("add") parser_add.add_argument("username", type=str) parser_add.add_argument("password", type=str) parser_add.set_defaults(func=add_user) parser_validate_login = subparsers.add_parser("validate") parser_validate_login.add_argument("username", type=str) parser_validate_login.add_argument("password", type=str) parser_validate_login.set_defaults(func=validate_login) parser_change_pw = subparsers.add_parser("change_password") parser_change_pw.add_argument("username", type=str) parser_change_pw.add_argument("new_password", type=str) parser_change_pw.set_defaults(func=change_password) asyncio.set_event_loop_policy(runner.HassEventLoopPolicy(False)) asyncio.run(run_command(parser.parse_args(args)))
def run(args: List) -> int: """Run a script.""" scripts = [] path = os.path.dirname(__file__) for fil in os.listdir(path): if fil == "__pycache__": continue if os.path.isdir(os.path.join(path, fil)): scripts.append(fil) elif fil != "__init__.py" and fil.endswith(".py"): scripts.append(fil[:-3]) if not args: print("Please specify a script to run.") print("Available scripts:", ", ".join(scripts)) return 1 if args[0] not in scripts: print("Invalid script specified.") print("Available scripts:", ", ".join(scripts)) return 1 script = importlib.import_module(f"homeassistant.scripts.{args[0]}") config_dir = extract_config_dir() loop = asyncio.get_event_loop() if not is_virtual_env(): loop.run_until_complete(async_mount_local_lib_path(config_dir)) _pip_kwargs = pip_kwargs(config_dir) logging.basicConfig(stream=sys.stdout, level=logging.INFO) for req in getattr(script, "REQUIREMENTS", []): if is_installed(req): continue if not install_package(req, **_pip_kwargs): print("Aborting script, could not install dependency", req) return 1 asyncio.set_event_loop_policy(runner.HassEventLoopPolicy(False)) return script.run(args[1:]) # type: ignore
from tests.ignore_uncaught_exceptions import IGNORE_UNCAUGHT_EXCEPTIONS pytest.register_assert_rewrite("tests.common") from tests.common import ( # noqa: E402, isort:skip CLIENT_ID, INSTANCES, MockConfigEntry, MockUser, async_fire_mqtt_message, async_init_recorder_component, async_test_home_assistant, get_test_home_assistant, init_recorder_component, mock_storage as mock_storage, ) from tests.test_util.aiohttp import mock_aiohttp_client # noqa: E402, isort:skip logging.basicConfig(level=logging.DEBUG) logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO) asyncio.set_event_loop_policy(runner.HassEventLoopPolicy(False)) # Disable fixtures overriding our beautiful policy asyncio.set_event_loop_policy = lambda policy: None def pytest_configure(config): """Register marker for tests that log exceptions.""" config.addinivalue_line( "markers", "no_fail_on_log_exception: mark test to not fail on logged exception") def pytest_runtest_setup(): """Prepare pytest_socket and freezegun. pytest_socket: