mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 00:48:19 +01:00
Fix Template Switch restore_mode support (#4280)
fixes https://github.com/esphome/issues/issues/4020
This commit is contained in:
parent
fe55f3a43d
commit
75dff1e102
1 changed files with 9 additions and 8 deletions
|
@ -43,15 +43,16 @@ void TemplateSwitch::setup() {
|
||||||
if (!this->restore_state_)
|
if (!this->restore_state_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto restored = this->get_initial_state();
|
optional<bool> initial_state = this->get_initial_state_with_restore_mode();
|
||||||
if (!restored.has_value())
|
|
||||||
return;
|
|
||||||
|
|
||||||
ESP_LOGD(TAG, " Restored state %s", ONOFF(*restored));
|
if (initial_state.has_value()) {
|
||||||
if (*restored) {
|
ESP_LOGD(TAG, " Restored state %s", ONOFF(initial_state.value()));
|
||||||
this->turn_on();
|
// if it has a value, restore_mode is not "DISABLED", therefore act on the switch:
|
||||||
} else {
|
if (initial_state.value()) {
|
||||||
this->turn_off();
|
this->turn_on();
|
||||||
|
} else {
|
||||||
|
this->turn_off();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void TemplateSwitch::dump_config() {
|
void TemplateSwitch::dump_config() {
|
||||||
|
|
Loading…
Reference in a new issue