From e3fdea8ce1d49f5236da4e7637dc70c3061d8272 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 29 Apr 2026 11:06:04 -0500 Subject: [PATCH] [scheduler] Address Copilot feedback: %p type, NameType doc, test docstring - Strip const for the %p varargs call (the format spec takes void*, not const void*; same representation everywhere but pedantically correct). - Mention SELF_POINTER in the NameType discriminator comment. - Update test docstring to match the actual const void * signatures. --- esphome/core/scheduler.cpp | 5 +++-- esphome/core/scheduler.h | 3 ++- tests/integration/test_scheduler_self_keyed.py | 9 +++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index e8b8332902..57deeab0da 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -60,8 +60,9 @@ struct SchedulerNameLog { return buffer; } else { // SELF_POINTER // static_name carries the void* key for SELF_POINTER (pointer-width union slot). - // Cast to const void* — %p requires a void* argument. - ESPHOME_snprintf_P(buffer, sizeof(buffer), ESPHOME_PSTR("self:%p"), static_cast(static_name)); + // %p is specified as void* (not const void*), so strip const for the varargs call. + ESPHOME_snprintf_P(buffer, sizeof(buffer), ESPHOME_PSTR("self:%p"), + const_cast(static_cast(static_name))); return buffer; } } diff --git a/esphome/core/scheduler.h b/esphome/core/scheduler.h index a97f45b15f..7a6be6bea9 100644 --- a/esphome/core/scheduler.h +++ b/esphome/core/scheduler.h @@ -146,7 +146,8 @@ class Scheduler { } // Name storage type discriminator for SchedulerItem - // Used to distinguish between static strings, hashed strings, numeric IDs, and internal numeric IDs + // Used to distinguish between static strings, hashed strings, numeric IDs, internal numeric IDs, + // and self-keyed pointers (caller-supplied `void *`, typically `this`). enum class NameType : uint8_t { STATIC_STRING = 0, // const char* pointer to static/flash storage HASHED_STRING = 1, // uint32_t FNV-1a hash of a runtime string diff --git a/tests/integration/test_scheduler_self_keyed.py b/tests/integration/test_scheduler_self_keyed.py index 48c9d98ad6..e0825ea825 100644 --- a/tests/integration/test_scheduler_self_keyed.py +++ b/tests/integration/test_scheduler_self_keyed.py @@ -1,9 +1,10 @@ """Test the self-keyed scheduler API. -Verifies that `Scheduler::set_timeout(void *, ...)` / `set_interval(void *, ...)` and the -matching `cancel_*(void *)` overloads behave correctly: callbacks fire, distinct keys -don't collide, self-keyed and component-keyed namespaces are independent, and -re-registering the same key replaces the existing timer. +Verifies that `Scheduler::set_timeout(const void *, ...)` / +`set_interval(const void *, ...)` and the matching `cancel_*(const void *)` +overloads behave correctly: callbacks fire, distinct keys don't collide, +self-keyed and component-keyed namespaces are independent, and re-registering +the same key replaces the existing timer. """ import asyncio