36 TEMPLATABLE_VALUE(std::string, ssid)
37 TEMPLATABLE_VALUE(std::string, password)
38 TEMPLATABLE_VALUE(
bool, save)
39 TEMPLATABLE_VALUE(uint32_t, connection_timeout)
41 void play(
const Ts &...
x)
override {
42 auto ssid = this->ssid_.value(
x...);
43 auto password = this->password_.value(
x...);
45 if (this->connecting_)
55 this->
new_sta_.set_password(password);
61 this->connecting_ =
true;
65 if (this->save_.value(
x...)) {
73 this->
set_timeout(
"wifi-connect-timeout", this->connection_timeout_.value(
x...), [
this,
x...]() {
75 global_wifi_component->disable();
76 global_wifi_component->save_wifi_sta(old_sta_.get_ssid(), old_sta_.get_password());
77 global_wifi_component->enable();
79 this->set_timeout(
"wifi-fallback-timeout", this->connection_timeout_.value(x...), [this]() {
80 this->connecting_ = false;
81 this->error_trigger_->trigger();
86 Trigger<> *get_connect_trigger()
const {
return this->connect_trigger_; }
87 Trigger<> *get_error_trigger()
const {
return this->error_trigger_; }
89 void loop()
override {
90 if (!this->connecting_)
94 this->cancel_timeout(
"wifi-connect-timeout");
95 this->cancel_timeout(
"wifi-fallback-timeout");
96 this->connecting_ =
false;
99 this->connect_trigger_->trigger();
102 this->error_trigger_->trigger();
108 bool connecting_{
false};