mirror of
https://github.com/esphome/esphome.git
synced 2024-11-06 09:25:37 +01:00
Stop infinite loop in light on_turn_on (#1219)
Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
parent
949c71dc97
commit
36e4a8b444
@ -103,10 +103,14 @@ class LightTurnOnTrigger : public Trigger<> {
|
||||
LightTurnOnTrigger(LightState *a_light) {
|
||||
a_light->add_new_remote_values_callback([this, a_light]() {
|
||||
auto is_on = a_light->current_values.is_on();
|
||||
if (is_on && !last_on_) {
|
||||
// only trigger when going from off to on
|
||||
auto should_trigger = is_on && !last_on_;
|
||||
// Set new state immediately so that trigger() doesn't devolve
|
||||
// into infinite loop
|
||||
last_on_ = is_on;
|
||||
if (should_trigger) {
|
||||
this->trigger();
|
||||
}
|
||||
last_on_ = is_on;
|
||||
});
|
||||
last_on_ = a_light->current_values.is_on();
|
||||
}
|
||||
@ -120,10 +124,14 @@ class LightTurnOffTrigger : public Trigger<> {
|
||||
LightTurnOffTrigger(LightState *a_light) {
|
||||
a_light->add_new_remote_values_callback([this, a_light]() {
|
||||
auto is_on = a_light->current_values.is_on();
|
||||
if (!is_on && last_on_) {
|
||||
// only trigger when going from on to off
|
||||
auto should_trigger = !is_on && last_on_;
|
||||
// Set new state immediately so that trigger() doesn't devolve
|
||||
// into infinite loop
|
||||
last_on_ = is_on;
|
||||
if (should_trigger) {
|
||||
this->trigger();
|
||||
}
|
||||
last_on_ = is_on;
|
||||
});
|
||||
last_on_ = a_light->current_values.is_on();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user