16 void play(
const Ts &...
x)
override {
17 auto ssid = this->ssid_.value(
x...);
18 auto password = this->password_.value(
x...);
23 char ssid_buf[SSID_BUFFER_SIZE];
41 if (this->save_.value(
x...)) {
51 global_wifi_component->disable();
52 global_wifi_component->save_wifi_sta(old_sta_.get_ssid(), old_sta_.get_password());
53 global_wifi_component->enable();
55 this->set_timeout(FALLBACK_TIMEOUT_ID, this->connection_timeout_.value(x...), [this]() {
56 this->connecting_ = false;
57 this->error_trigger_.trigger();
62 Trigger<> *get_connect_trigger() {
return &this->connect_trigger_; }
66 if (!this->connecting_)
70 this->cancel_timeout(CONNECT_TIMEOUT_ID);
71 this->cancel_timeout(FALLBACK_TIMEOUT_ID);
72 this->connecting_ =
false;
73 char ssid_buf[SSID_BUFFER_SIZE];
76 this->connect_trigger_.trigger();
79 this->error_trigger_.trigger();
85 static constexpr uint32_t CONNECT_TIMEOUT_ID = 0;
86 static constexpr uint32_t FALLBACK_TIMEOUT_ID = 1;
88 bool connecting_{
false};
virtual void play(const Ts &...x)=0
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
StringRef get_ssid() const
void set_ssid(const std::string &ssid)
StringRef get_password() const
void set_password(const std::string &password)
void set_sta(const WiFiAP &ap)
void save_wifi_sta(const std::string &ssid, const std::string &password)
const char * wifi_ssid_to(std::span< char, SSID_BUFFER_SIZE > buffer)
Write SSID to buffer without heap allocation.
bool is_connected() const
WiFiComponent * global_wifi_component