From e0b7a84957b4780eca4af17bc3842d1b7cda5108 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 12 Oct 2026 15:11:13 -1000 Subject: [PATCH] Keep the edit from the point the device accepted the session --- esphome/cli/rotate_key.py | 8 ++++---- tests/unit_tests/cli/test_rotate_key.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/cli/rotate_key.py b/esphome/cli/rotate_key.py index 34d1ae1497f..88adc2271cc 100644 --- a/esphome/cli/rotate_key.py +++ b/esphome/cli/rotate_key.py @@ -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( diff --git a/tests/unit_tests/cli/test_rotate_key.py b/tests/unit_tests/cli/test_rotate_key.py index 4007065302b..f44d63f6645 100644 --- a/tests/unit_tests/cli/test_rotate_key.py +++ b/tests/unit_tests/cli/test_rotate_key.py @@ -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