mirror of
https://github.com/esphome/esphome.git
synced 2025-08-10 12:27:46 +00:00
dry
This commit is contained in:
@@ -80,13 +80,7 @@ class Scheduler {
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
SchedulerItem()
|
SchedulerItem()
|
||||||
: component(nullptr),
|
: component(nullptr), interval(0), next_execution_(0), type(TIMEOUT), remove(false), owns_name(false) {
|
||||||
interval(0),
|
|
||||||
next_execution_(0),
|
|
||||||
callback(nullptr),
|
|
||||||
type(TIMEOUT),
|
|
||||||
remove(false),
|
|
||||||
owns_name(false) {
|
|
||||||
name_.static_name = nullptr;
|
name_.static_name = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,11 +99,11 @@ class Scheduler {
|
|||||||
// Clean up old dynamic name if any
|
// Clean up old dynamic name if any
|
||||||
if (owns_name && name_.dynamic_name) {
|
if (owns_name && name_.dynamic_name) {
|
||||||
delete[] name_.dynamic_name;
|
delete[] name_.dynamic_name;
|
||||||
|
owns_name = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == nullptr || name[0] == '\0') {
|
if (!name || !name[0]) {
|
||||||
name_.static_name = nullptr;
|
name_.static_name = nullptr;
|
||||||
owns_name = false;
|
|
||||||
} else if (make_copy) {
|
} else if (make_copy) {
|
||||||
// Make a copy for dynamic strings
|
// Make a copy for dynamic strings
|
||||||
size_t len = strlen(name);
|
size_t len = strlen(name);
|
||||||
@@ -119,24 +113,12 @@ class Scheduler {
|
|||||||
} else {
|
} else {
|
||||||
// Use static string directly
|
// Use static string directly
|
||||||
name_.static_name = name;
|
name_.static_name = name;
|
||||||
owns_name = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cmp(const std::unique_ptr<SchedulerItem> &a, const std::unique_ptr<SchedulerItem> &b);
|
static bool cmp(const std::unique_ptr<SchedulerItem> &a, const std::unique_ptr<SchedulerItem> &b);
|
||||||
const char *get_type_str() {
|
const char *get_type_str() const { return (type == TIMEOUT) ? "timeout" : "interval"; }
|
||||||
switch (this->type) {
|
const char *get_source() const { return component ? component->get_component_source() : "unknown"; }
|
||||||
case SchedulerItem::INTERVAL:
|
|
||||||
return "interval";
|
|
||||||
case SchedulerItem::TIMEOUT:
|
|
||||||
return "timeout";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const char *get_source() {
|
|
||||||
return this->component != nullptr ? this->component->get_component_source() : "unknown";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Common implementation for both timeout and interval
|
// Common implementation for both timeout and interval
|
||||||
|
Reference in New Issue
Block a user