From 2a101832ca5e03d4296a1000282e6e70a401e47c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Feb 2026 22:59:29 -1000 Subject: [PATCH 1/3] Address review feedback - Remove unnecessary uint64_t cast on esp_timer_get_time() (already returns int64_t, always non-negative after boot) - Fix next_schedule_in @param comment: now is only unused on ESP32, used for rollover tracking on other platforms - Use fully-qualified friend declaration (::esphome::millis_64()) --- esphome/components/esp32/core.cpp | 2 +- esphome/core/scheduler.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/esp32/core.cpp b/esphome/components/esp32/core.cpp index b9ae871abf..501dd7d2ea 100644 --- a/esphome/components/esp32/core.cpp +++ b/esphome/components/esp32/core.cpp @@ -23,7 +23,7 @@ namespace esphome { void HOT yield() { vPortYield(); } uint32_t IRAM_ATTR HOT millis() { return (uint32_t) (esp_timer_get_time() / 1000ULL); } -uint64_t HOT millis_64() { return static_cast(esp_timer_get_time()) / 1000ULL; } +uint64_t HOT millis_64() { return esp_timer_get_time() / 1000; } void HOT delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); } uint32_t IRAM_ATTR HOT micros() { return (uint32_t) esp_timer_get_time(); } void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); } diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index fa95484e7f..c61bd40f7c 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -121,7 +121,7 @@ class Scheduler { uint64_t millis_64() { return esphome::millis_64(); } // Calculate when the next scheduled item should run - // @param now Unused, kept for API compatibility + // @param now On ESP32, unused (native 64-bit); on other platforms, extended to 64-bit via rollover tracking // Returns the time in milliseconds until the next scheduled item, or nullopt if no items // This method performs cleanup of removed items before checking the schedule // IMPORTANT: This method should only be called from the main thread (loop task). @@ -299,7 +299,7 @@ class Scheduler { // On non-ESP32 platforms, millis_64() HAL function delegates to this method // which tracks 32-bit millis() rollover using millis_major_ and last_millis_. // On ESP32, millis_64() uses esp_timer_get_time() directly. - friend uint64_t millis_64(); + friend uint64_t ::esphome::millis_64(); uint64_t millis_64_impl_(uint32_t now); #endif // Cleanup logically deleted items from the scheduler From 554e2ac7f153129939d66c08391c316a3e538c60 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Feb 2026 23:03:14 -1000 Subject: [PATCH 2/3] Use 1000ULL for consistency, tighten @param comment - Use 1000ULL divisor in millis_64() to match millis() style and avoid implicit signed-to-unsigned conversion - Clarify next_schedule_in @param: now is unused for 64-bit extension on ESP32, but still used for 32-bit paths in call() --- esphome/components/esp32/core.cpp | 2 +- esphome/core/scheduler.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/esphome/components/esp32/core.cpp b/esphome/components/esp32/core.cpp index 501dd7d2ea..1bb34295cd 100644 --- a/esphome/components/esp32/core.cpp +++ b/esphome/components/esp32/core.cpp @@ -23,7 +23,7 @@ namespace esphome { void HOT yield() { vPortYield(); } uint32_t IRAM_ATTR HOT millis() { return (uint32_t) (esp_timer_get_time() / 1000ULL); } -uint64_t HOT millis_64() { return esp_timer_get_time() / 1000; } +uint64_t HOT millis_64() { return esp_timer_get_time() / 1000ULL; } void HOT delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); } uint32_t IRAM_ATTR HOT micros() { return (uint32_t) esp_timer_get_time(); } void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); } diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index c61bd40f7c..757f60c2ce 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -120,10 +120,10 @@ class Scheduler { /// Get 64-bit millisecond timestamp (handles 32-bit millis() rollover) uint64_t millis_64() { return esphome::millis_64(); } - // Calculate when the next scheduled item should run - // @param now On ESP32, unused (native 64-bit); on other platforms, extended to 64-bit via rollover tracking - // Returns the time in milliseconds until the next scheduled item, or nullopt if no items - // This method performs cleanup of removed items before checking the schedule + // Calculate when the next scheduled item should run. + // @param now On ESP32, unused for 64-bit extension (native); on other platforms, extended to 64-bit via rollover. + // Returns the time in milliseconds until the next scheduled item, or nullopt if no items. + // This method performs cleanup of removed items before checking the schedule. // IMPORTANT: This method should only be called from the main thread (loop task). optional next_schedule_in(uint32_t now); From 33d4f6251053425f62b003f727b9eac119ebf5b1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Feb 2026 23:05:18 -1000 Subject: [PATCH 3/3] Restore explicit cast for -Wsign-conversion consistency millis() on the line above casts esp_timer_get_time() to uint32_t. Match that pattern in millis_64() with static_cast to avoid implicit signed-to-unsigned conversion. --- esphome/components/esp32/core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/esp32/core.cpp b/esphome/components/esp32/core.cpp index 1bb34295cd..b9ae871abf 100644 --- a/esphome/components/esp32/core.cpp +++ b/esphome/components/esp32/core.cpp @@ -23,7 +23,7 @@ namespace esphome { void HOT yield() { vPortYield(); } uint32_t IRAM_ATTR HOT millis() { return (uint32_t) (esp_timer_get_time() / 1000ULL); } -uint64_t HOT millis_64() { return esp_timer_get_time() / 1000ULL; } +uint64_t HOT millis_64() { return static_cast(esp_timer_get_time()) / 1000ULL; } void HOT delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); } uint32_t IRAM_ATTR HOT micros() { return (uint32_t) esp_timer_get_time(); } void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }