mirror of
https://github.com/esphome/esphome.git
synced 2026-09-03 19:46:02 +00:00
[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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user