[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.
This commit is contained in:
J. Nick Koston
2026-04-29 11:06:04 -05:00
parent 17173ba3a3
commit e3fdea8ce1
3 changed files with 10 additions and 7 deletions
+3 -2
View File
@@ -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<const void *>(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<void *>(static_cast<const void *>(static_name)));
return buffer;
}
}
+2 -1
View File
@@ -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
@@ -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