1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-13 07:13:47 +01:00
This commit is contained in:
J. Nick Koston
2025-10-11 13:08:10 -10:00
parent 5a0184cb35
commit 678a93cc56
2 changed files with 10 additions and 3 deletions

View File

@@ -40,9 +40,6 @@ void ESP32ImprovComponent::setup() {
#endif
global_ble_server->on_disconnect([this](uint16_t conn_id) { this->set_error_(improv::ERROR_NONE); });
// Listen for WiFi connections to detect when provisioning happens via captive portal or other means
wifi::global_wifi_component->get_connect_trigger()->add_callback([this]() { this->on_wifi_connected_(); });
// Start with loop disabled - will be enabled by start() when needed
this->disable_loop();
}
@@ -146,6 +143,7 @@ void ESP32ImprovComponent::loop() {
#else
this->set_state_(improv::STATE_AUTHORIZED);
#endif
this->check_wifi_connection_();
break;
}
case improv::STATE_AUTHORIZED: {
@@ -159,10 +157,12 @@ void ESP32ImprovComponent::loop() {
if (!this->check_identify_()) {
this->set_status_indicator_state_((now % 1000) < 500);
}
this->check_wifi_connection_();
break;
}
case improv::STATE_PROVISIONING: {
this->set_status_indicator_state_((now % 200) < 100);
this->check_wifi_connection_();
break;
}
case improv::STATE_PROVISIONED: {
@@ -374,6 +374,12 @@ void ESP32ImprovComponent::on_wifi_connect_timeout_() {
wifi::global_wifi_component->clear_sta();
}
void ESP32ImprovComponent::check_wifi_connection_() {
if (wifi::global_wifi_component->is_connected()) {
this->on_wifi_connected_();
}
}
void ESP32ImprovComponent::on_wifi_connected_() {
// Handle WiFi connection, whether from Improv provisioning or external (e.g., captive portal)
if (this->state_ == improv::STATE_PROVISIONING) {

View File

@@ -112,6 +112,7 @@ class ESP32ImprovComponent : public Component {
void process_incoming_data_();
void on_wifi_connect_timeout_();
void on_wifi_connected_();
void check_wifi_connection_();
bool check_identify_();
void advertise_service_data_();
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG