From ffbbf37fc28ef1d736c18e2c52ba3a3779ed25d3 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Mon, 15 Dec 2025 23:12:21 +0000 Subject: [PATCH] Revert "Revert API compilation_time to old locale-dependent format" This reverts commit d2b5398fadf6e09d2d1b6e04b91b8940e4425ea8. --- esphome/components/api/api_connection.cpp | 5 ++++- tests/integration/test_build_info.py | 14 +++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 5186e5afda..85f4566f3c 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1472,7 +1472,10 @@ bool APIConnection::send_device_info_response(const DeviceInfoRequest &msg) { resp.set_esphome_version(ESPHOME_VERSION_REF); - resp.set_compilation_time(App.get_compilation_time_ref()); + // Stack buffer for build time string + char build_time_str[Application::BUILD_TIME_STR_SIZE]; + App.get_build_time_string(build_time_str); + resp.set_compilation_time(StringRef(build_time_str)); // Manufacturer string - define once, handle ESP8266 PROGMEM separately #if defined(USE_ESP8266) || defined(USE_ESP32) diff --git a/tests/integration/test_build_info.py b/tests/integration/test_build_info.py index 7934472b12..7079594471 100644 --- a/tests/integration/test_build_info.py +++ b/tests/integration/test_build_info.py @@ -26,12 +26,13 @@ async def test_build_info( assert device_info.name == "build-info-test" # Verify compilation_time from device_info is present and parseable - # The format is locale-dependent: "Dec 15 2025, 17:44:16" + # The format is ISO 8601 with timezone: "YYYY-MM-DD HH:MM:SS +ZZZZ" compilation_time = device_info.compilation_time assert compilation_time is not None - # Validate the format (locale-dependent, so just check it's not empty) - assert len(compilation_time) > 0 + # Validate the ISO format: "YYYY-MM-DD HH:MM:SS +ZZZZ" + parsed = datetime.strptime(compilation_time, "%Y-%m-%d %H:%M:%S %z") + assert parsed.year >= time.localtime().tm_year # Get entities entities, _ = await client.list_entities_services() @@ -109,5 +110,8 @@ async def test_build_info( f"build_time_str '{build_time_str}' should match timestamp '{expected_str}'" ) - # Note: compilation_time (from API) uses old locale-dependent format, - # while build_time_str (text sensor) uses new ISO format + # Verify compilation_time matches build_time_str (they should be the same) + assert compilation_time == build_time_str, ( + f"compilation_time '{compilation_time}' should match " + f"build_time_str '{build_time_str}'" + )