mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
[sprinkler] Fix scheduler deprecation warnings and heap churn with FixedVector (#13251)
This commit is contained in:
@@ -332,6 +332,7 @@ Sprinkler::Sprinkler(const std::string &name) {
|
||||
// The `name` is needed to set timers up, hence non-default constructor
|
||||
// replaces `set_name()` method previously existed
|
||||
this->name_ = name;
|
||||
this->timer_.init(2);
|
||||
this->timer_.push_back({this->name_ + "sm", false, 0, 0, std::bind(&Sprinkler::sm_timer_callback_, this)});
|
||||
this->timer_.push_back({this->name_ + "vs", false, 0, 0, std::bind(&Sprinkler::valve_selection_callback_, this)});
|
||||
}
|
||||
@@ -1574,7 +1575,8 @@ const LogString *Sprinkler::state_as_str_(SprinklerState state) {
|
||||
|
||||
void Sprinkler::start_timer_(const SprinklerTimerIndex timer_index) {
|
||||
if (this->timer_duration_(timer_index) > 0) {
|
||||
this->set_timeout(this->timer_[timer_index].name, this->timer_duration_(timer_index),
|
||||
// FixedVector ensures timer_ can't be resized, so .c_str() pointers remain valid
|
||||
this->set_timeout(this->timer_[timer_index].name.c_str(), this->timer_duration_(timer_index),
|
||||
this->timer_cbf_(timer_index));
|
||||
this->timer_[timer_index].start_time = millis();
|
||||
this->timer_[timer_index].active = true;
|
||||
@@ -1585,7 +1587,7 @@ void Sprinkler::start_timer_(const SprinklerTimerIndex timer_index) {
|
||||
|
||||
bool Sprinkler::cancel_timer_(const SprinklerTimerIndex timer_index) {
|
||||
this->timer_[timer_index].active = false;
|
||||
return this->cancel_timeout(this->timer_[timer_index].name);
|
||||
return this->cancel_timeout(this->timer_[timer_index].name.c_str());
|
||||
}
|
||||
|
||||
bool Sprinkler::timer_active_(const SprinklerTimerIndex timer_index) { return this->timer_[timer_index].active; }
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "esphome/components/switch/switch.h"
|
||||
|
||||
@@ -553,8 +554,8 @@ class Sprinkler : public Component {
|
||||
/// Sprinkler valve operator objects
|
||||
std::vector<SprinklerValveOperator> valve_op_{2};
|
||||
|
||||
/// Valve control timers
|
||||
std::vector<SprinklerTimer> timer_{};
|
||||
/// Valve control timers - FixedVector enforces that this can never grow beyond init() size
|
||||
FixedVector<SprinklerTimer> timer_;
|
||||
|
||||
/// Other Sprinkler instances we should be aware of (used to check if pumps are in use)
|
||||
std::vector<Sprinkler *> other_controllers_;
|
||||
|
||||
Reference in New Issue
Block a user