mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
Handle on_disconnect when Wi-Fi is disabled (#5691)
This commit is contained in:
parent
ccffbfd3ae
commit
9bd4b229e3
1 changed files with 9 additions and 10 deletions
|
@ -109,6 +109,15 @@ void WiFiComponent::loop() {
|
||||||
const uint32_t now = millis();
|
const uint32_t now = millis();
|
||||||
|
|
||||||
if (this->has_sta()) {
|
if (this->has_sta()) {
|
||||||
|
if (this->is_connected() != this->handled_connected_state_) {
|
||||||
|
if (this->handled_connected_state_) {
|
||||||
|
this->disconnect_trigger_->trigger();
|
||||||
|
} else {
|
||||||
|
this->connect_trigger_->trigger();
|
||||||
|
}
|
||||||
|
this->handled_connected_state_ = this->is_connected();
|
||||||
|
}
|
||||||
|
|
||||||
switch (this->state_) {
|
switch (this->state_) {
|
||||||
case WIFI_COMPONENT_STATE_COOLDOWN: {
|
case WIFI_COMPONENT_STATE_COOLDOWN: {
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
|
@ -138,19 +147,9 @@ void WiFiComponent::loop() {
|
||||||
ESP_LOGW(TAG, "WiFi Connection lost... Reconnecting...");
|
ESP_LOGW(TAG, "WiFi Connection lost... Reconnecting...");
|
||||||
this->state_ = WIFI_COMPONENT_STATE_STA_CONNECTING;
|
this->state_ = WIFI_COMPONENT_STATE_STA_CONNECTING;
|
||||||
this->retry_connect();
|
this->retry_connect();
|
||||||
|
|
||||||
if (this->handled_connected_state_) {
|
|
||||||
this->disconnect_trigger_->trigger();
|
|
||||||
this->handled_connected_state_ = false;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this->status_clear_warning();
|
this->status_clear_warning();
|
||||||
this->last_connected_ = now;
|
this->last_connected_ = now;
|
||||||
|
|
||||||
if (!this->handled_connected_state_) {
|
|
||||||
this->connect_trigger_->trigger();
|
|
||||||
this->handled_connected_state_ = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue