From ba48151e923fed66d88921b00e7031c433e9bf26 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 21 Aug 2026 01:11:20 -0500 Subject: [PATCH] Make timing total the sum of its named windows --- esphome/espota2.py | 6 +++--- tests/unit_tests/test_espota2.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/espota2.py b/esphome/espota2.py index f354115a4e..ca833f1816 100644 --- a/esphome/espota2.py +++ b/esphome/espota2.py @@ -542,11 +542,11 @@ def perform_ota( raise _committed_error(err) from err commit_duration = time.perf_counter() - commit_start - # Spans the binary size send through the commit ack; connect, handshake, - # and auth are not included + # Sum of the named windows so the breakdown is self consistent; connect, + # handshake, auth, and the one MD5 round trip are not included _LOGGER.info( "Update took %.2f seconds (prepare %.2f, upload %.2f, commit %.2f)", - time.perf_counter() - prepare_start, + prepare_duration + duration + commit_duration, prepare_duration, duration, commit_duration, diff --git a/tests/unit_tests/test_espota2.py b/tests/unit_tests/test_espota2.py index ab138a3f3c..e0e9185e1c 100644 --- a/tests/unit_tests/test_espota2.py +++ b/tests/unit_tests/test_espota2.py @@ -392,9 +392,9 @@ def test_perform_ota_no_auth( mock_socket.recv.side_effect = recv_responses - # Distinct window lengths pin each duration to its label; exactly the 7 + # Distinct window lengths pin each duration to its label; exactly the 6 # expected perf_counter calls, so an unaccounted timing window raises - timings = [0.0, 2.0, 10.0, 15.0, 20.0, 27.0, 30.0] + timings = [0.0, 2.0, 10.0, 15.0, 20.0, 27.0] with ( patch("time.perf_counter", side_effect=timings), caplog.at_level(logging.INFO), @@ -413,7 +413,7 @@ def test_perform_ota_no_auth( # pin each duration to its label assert "Preparing for upload took 2.00 seconds" in caplog.text assert ( - "Update took 30.00 seconds (prepare 2.00, upload 5.00, commit 7.00)" + "Update took 14.00 seconds (prepare 2.00, upload 5.00, commit 7.00)" in caplog.text )