mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Fix Template Switch restore_mode support (#4280)
fixes https://github.com/esphome/issues/issues/4020
This commit is contained in:
		| @@ -43,17 +43,18 @@ 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())); | ||||||
|  |     // if it has a value, restore_mode is not "DISABLED", therefore act on the switch: | ||||||
|  |     if (initial_state.value()) { | ||||||
|       this->turn_on(); |       this->turn_on(); | ||||||
|     } else { |     } else { | ||||||
|       this->turn_off(); |       this->turn_off(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | } | ||||||
| void TemplateSwitch::dump_config() { | void TemplateSwitch::dump_config() { | ||||||
|   LOG_SWITCH("", "Template Switch", this); |   LOG_SWITCH("", "Template Switch", this); | ||||||
|   ESP_LOGCONFIG(TAG, "  Restore State: %s", YESNO(this->restore_state_)); |   ESP_LOGCONFIG(TAG, "  Restore State: %s", YESNO(this->restore_state_)); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user