mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
Keep the edit from the point the device accepted the session
This commit is contained in:
@@ -189,9 +189,9 @@ def command_rotate_key(args: argparse.Namespace, config: ConfigType) -> int | No
|
||||
if run_external_process(*ESPHOME_COMMAND, *cli_args) != 0:
|
||||
return fail("Compiling with the new key failed")
|
||||
|
||||
def device_reached() -> None:
|
||||
# The upload may commit from here on; the edited config reaches
|
||||
# the device on either key
|
||||
def image_sent() -> None:
|
||||
# The device accepted the session and may commit from here on;
|
||||
# the edited config reaches it on either key
|
||||
nonlocal uploaded
|
||||
uploaded = True
|
||||
|
||||
@@ -202,7 +202,7 @@ def command_rotate_key(args: argparse.Namespace, config: ConfigType) -> int | No
|
||||
CORE.firmware_bin,
|
||||
noise_psk=old_key,
|
||||
plaintext_fallback=False,
|
||||
on_connect=device_reached,
|
||||
on_upload_start=image_sent,
|
||||
)
|
||||
if rc != 0:
|
||||
return fail(
|
||||
|
||||
@@ -122,7 +122,7 @@ def env(tmp_path: Path) -> Generator[dict[str, Mock]]:
|
||||
def upload_after_connecting(
|
||||
*_args: Any, **kwargs: Any
|
||||
) -> tuple[int, str | None]:
|
||||
kwargs["on_connect"]()
|
||||
kwargs["on_upload_start"]()
|
||||
return upload.return_value
|
||||
|
||||
upload.side_effect = upload_after_connecting
|
||||
@@ -159,7 +159,7 @@ def test_success(env: dict[str, Mock], capfd: pytest.CaptureFixture[str]) -> Non
|
||||
CORE.firmware_bin,
|
||||
noise_psk=OLD_KEY,
|
||||
plaintext_fallback=False,
|
||||
on_connect=ANY,
|
||||
on_upload_start=ANY,
|
||||
)
|
||||
out = capfd.readouterr().out
|
||||
assert NEW_KEY in out
|
||||
|
||||
Reference in New Issue
Block a user