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_)
48 char ssid_buf[SSID_BUFFER_SIZE];
56 this->
new_sta_.set_password(password);
62 this->connecting_ =
true;
66 if (this->save_.value(
x...)) {
74 this->
set_timeout(
"wifi-connect-timeout", this->connection_timeout_.value(
x...), [
this,
x...]() {
76 global_wifi_component->disable();
77 global_wifi_component->save_wifi_sta(old_sta_.get_ssid(), old_sta_.get_password());
78 global_wifi_component->enable();
80 this->set_timeout(
"wifi-fallback-timeout", this->connection_timeout_.value(x...), [this]() {
81 this->connecting_ = false;
82 this->error_trigger_->trigger();
87 Trigger<> *get_connect_trigger()
const {
return this->connect_trigger_; }
88 Trigger<> *get_error_trigger()
const {
return this->error_trigger_; }
90 void loop()
override {
91 if (!this->connecting_)
95 this->cancel_timeout(
"wifi-connect-timeout");
96 this->cancel_timeout(
"wifi-fallback-timeout");
97 this->connecting_ =
false;
98 char ssid_buf[SSID_BUFFER_SIZE];
101 this->connect_trigger_->trigger();
104 this->error_trigger_->trigger();
110 bool connecting_{
false};