def profile_ws( username: str = OPTION_USERNAME, password: str = OPTION_PASSWORD, address: str = OPTION_ADDRESS, port: int = OPTION_PORT, verify: bool = OPTION_VERIFY, wait_time: int = OPTION_WAIT, output_path: Optional[Path] = OPTION_OUTPUT, ) -> None: protect = ProtectApiClient(address, port, username, password, verify_ssl=verify, debug=True) async def callback() -> None: await protect.update() await profile_ws_job(protect, wait_time, output_path=output_path, ws_progress=_progress_bar) _setup_logger() loop = asyncio.get_event_loop() loop.run_until_complete(callback())
def shell( username: str = OPTION_USERNAME, password: str = OPTION_PASSWORD, address: str = OPTION_ADDRESS, port: int = OPTION_PORT, verify: bool = OPTION_VERIFY, ) -> None: if embed is None or colored is None: typer.echo("ipython and termcolor required for shell subcommand") sys.exit(1) protect = ProtectApiClient(address, port, username, password, verify_ssl=verify) loop = asyncio.get_event_loop() loop.run_until_complete(protect.update(True)) _setup_logger(show_level=True) c = get_config() c.InteractiveShellEmbed.colors = "Linux" embed(header=colored("protect = ProtectApiClient(*args)", "green"), config=c, using="asyncio")
def shell( username: str = OPTION_USERNAME, password: str = OPTION_PASSWORD, address: str = OPTION_ADDRESS, port: int = OPTION_PORT, verify: bool = OPTION_VERIFY, new: bool = OPTION_NEW, ) -> None: if embed is None or colored is None: typer.echo("ipython and termcolor required for shell subcommand") sys.exit(1) if new: protect: Union[UpvServer, ProtectApiClient] = ProtectApiClient( address, port, username, password, verify_ssl=verify ) else: protect = UpvServer(None, address, port, username, password, verify_ssl=verify) loop = asyncio.get_event_loop() loop.run_until_complete(protect.update(True)) console_handler = logging.StreamHandler() console_handler.setLevel(logging.DEBUG) _LOGGER.setLevel(logging.DEBUG) _LOGGER.addHandler(console_handler) klass = "UpvServer" if new: klass = "ProtectApiClient" c = get_config() c.InteractiveShellEmbed.colors = "Linux" embed(header=colored(f"protect = {klass}(*args)", "green"), config=c, using="asyncio")
def test_early_bootstrap(): client = ProtectApiClient("127.0.0.1", 0, "username", "password", debug=True) with pytest.raises(BadRequest): client.bootstrap
def test_api_client_creation(): """Test we can create the object.""" client = ProtectApiClient("127.0.0.1", 0, "username", "password", debug=True) assert client
async def test_bootstrap_fix_record_mode(bootstrap): expected_updates = 1 orig_bootstrap = deepcopy(bootstrap) bootstrap["cameras"][0]["recordingSettings"]["mode"] = "motion" if len(bootstrap["cameras"]) > 1: expected_updates = 2 bootstrap["cameras"][1]["recordingSettings"]["mode"] = "smartDetect" client = ProtectApiClient("127.0.0.1", 0, "username", "password", debug=True) client.api_request_obj = AsyncMock(side_effect=[bootstrap, orig_bootstrap]) client.update_device = AsyncMock() await client.get_bootstrap() assert client.api_request_obj.call_count == 2 assert client.update_device.call_count == expected_updates
def generate_sample_data( username: str = OPTION_USERNAME, password: str = OPTION_PASSWORD, address: str = OPTION_ADDRESS, port: int = OPTION_PORT, verify: bool = OPTION_VERIFY, anonymize: bool = OPTION_ANON, wait_time: int = OPTION_WAIT, output_folder: Optional[Path] = OPTION_OUTPUT, do_zip: bool = OPTION_ZIP, ) -> None: if output_folder is None: tests_folder = Path(__file__).parent.parent / "tests" if not tests_folder.exists(): typer.secho("Output folder required when not in dev-mode", fg="red") sys.exit(1) output_folder = (tests_folder / "sample_data").absolute() protect = ProtectApiClient(address, port, username, password, verify_ssl=verify, debug=True) def log(msg: str) -> None: typer.echo(msg) def log_warning(msg: str) -> None: typer.secho(msg, fg="yellow") SampleDataGenerator( protect, output_folder, anonymize, wait_time, log=log, log_warning=log_warning, ws_progress=_progress_bar, do_zip=do_zip, ).generate()
def test_connection_host_override(): protect = ProtectApiClient("127.0.0.1", 443, "test", "test", override_connection_host=True) expected = IPv4Address("127.0.0.1") assert protect._connection_host == expected