46 : min_length_(min_length), max_length_(max_length) {
49 this->start_time_ =
millis();
51 const uint32_t length =
millis() - this->start_time_;
59 uint32_t start_time_{0};
67 : min_length_(min_length), max_length_(max_length) {
69 const uint32_t now =
millis();
71 if (state && this->start_time_ != 0 && this->end_time_ != 0) {
72 if (
match_interval(this->min_length_, this->max_length_, this->end_time_ - this->start_time_) &&
73 match_interval(this->min_length_, this->max_length_, now - this->end_time_)) {
75 this->start_time_ = 0;
81 this->start_time_ = this->end_time_;
82 this->end_time_ = now;
87 uint32_t start_time_{0};
88 uint32_t end_time_{0};
96 : parent_(parent), timing_(
std::move(timing)) {}
99 this->last_state_ = this->parent_->state;
101 this->parent_->add_on_state_callback(f);
111 void on_state_(
bool state);
112 void schedule_cooldown_();
113 void schedule_is_valid_(uint32_t min_length);
114 void schedule_is_not_valid_(uint32_t max_length);
119 uint32_t invalid_cooldown_{1000};
121 bool last_state_{
false};
122 bool is_in_cooldown_{
false};
123 bool is_valid_{
false};
136 bool check(Ts...
x)
override {
return this->parent_->state == this->state_; }
148 void play(Ts...
x)
override {
149 auto val = this->state_.value(
x...);
150 this->sensor_->publish_state(
val);
ReleaseTrigger(BinarySensor *parent)
bool check(Ts... x) override
DoubleClickTrigger(BinarySensor *parent, uint32_t min_length, uint32_t max_length)
uint32_t max_length_
Minimum length of click. 0 means no minimum.
uint32_t max_length_
Minimum length of click. 0 means no minimum.
float get_setup_priority() const override
MultiClickTrigger(BinarySensor *parent, std::vector< MultiClickTriggerEvent > timing)
bool match_interval(uint32_t min_length, uint32_t max_length, uint32_t length)
std::vector< MultiClickTriggerEvent > timing_
void set_invalid_cooldown(uint32_t invalid_cooldown)
uint32_t IRAM_ATTR HOT millis()
BinarySensorPublishAction(BinarySensor *sensor)
StateTrigger(BinarySensor *parent)
ClickTrigger(BinarySensor *parent, uint32_t min_length, uint32_t max_length)
Base class for all automation conditions.
uint32_t min_length_
The millis() time when the click started.
esphome::binary_sensor::BinarySensor * binary_sensor
void on_state_(bool state)
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
void add_on_state_callback(std::function< void(bool)> &&callback)
Add a callback to be notified of state changes.
PressTrigger(BinarySensor *parent)
Implementation of SPI Controller mode.
BinarySensorCondition(BinarySensor *parent, bool state)
Base class for all binary_sensor-type classes.
TEMPLATABLE_VALUE(bool, state) void play(Ts... x) override
esphome::sensor::Sensor * sensor