mirror of
https://github.com/esphome/esphome.git
synced 2026-02-20 16:35:37 -07:00
de-dupe
This commit is contained in:
@@ -2214,6 +2214,13 @@ void WiFiComponent::notify_connect_state_listeners_() {
|
||||
listener->on_wifi_connect_state(StringRef(ssid, strlen(ssid)), bssid);
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiComponent::notify_disconnect_state_listeners_() {
|
||||
static constexpr uint8_t EMPTY_BSSID[6] = {};
|
||||
for (auto *listener : this->connect_state_listeners_) {
|
||||
listener->on_wifi_connect_state(StringRef(), EMPTY_BSSID);
|
||||
}
|
||||
}
|
||||
#endif // USE_WIFI_CONNECT_STATE_LISTENERS
|
||||
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
@@ -2224,6 +2231,14 @@ void WiFiComponent::notify_ip_state_listeners_() {
|
||||
}
|
||||
#endif // USE_WIFI_IP_STATE_LISTENERS
|
||||
|
||||
#ifdef USE_WIFI_SCAN_RESULTS_LISTENERS
|
||||
void WiFiComponent::notify_scan_results_listeners_() {
|
||||
for (auto *listener : this->scan_results_listeners_) {
|
||||
listener->on_wifi_scan_results(this->scan_result_);
|
||||
}
|
||||
}
|
||||
#endif // USE_WIFI_SCAN_RESULTS_LISTENERS
|
||||
|
||||
void WiFiComponent::check_roaming_(uint32_t now) {
|
||||
// Guard: not for hidden networks (may not appear in scan)
|
||||
const WiFiAP *selected = this->get_selected_sta_();
|
||||
|
||||
@@ -644,11 +644,17 @@ class WiFiComponent : public Component {
|
||||
#ifdef USE_WIFI_CONNECT_STATE_LISTENERS
|
||||
/// Notify connect state listeners (called after state machine reaches STA_CONNECTED)
|
||||
void notify_connect_state_listeners_();
|
||||
/// Notify connect state listeners of disconnection
|
||||
void notify_disconnect_state_listeners_();
|
||||
#endif
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
/// Notify IP state listeners with current addresses
|
||||
void notify_ip_state_listeners_();
|
||||
#endif
|
||||
#ifdef USE_WIFI_SCAN_RESULTS_LISTENERS
|
||||
/// Notify scan results listeners with current scan results
|
||||
void notify_scan_results_listeners_();
|
||||
#endif
|
||||
|
||||
#ifdef USE_ESP8266
|
||||
static void wifi_event_callback(System_Event_t *event);
|
||||
|
||||
@@ -970,10 +970,7 @@ void WiFiComponent::process_pending_callbacks_() {
|
||||
if (this->pending_.disconnect) {
|
||||
this->pending_.disconnect = false;
|
||||
#ifdef USE_WIFI_CONNECT_STATE_LISTENERS
|
||||
static constexpr uint8_t EMPTY_BSSID[6] = {};
|
||||
for (auto *listener : this->connect_state_listeners_) {
|
||||
listener->on_wifi_connect_state(StringRef(), EMPTY_BSSID);
|
||||
}
|
||||
this->notify_disconnect_state_listeners_();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -989,9 +986,7 @@ void WiFiComponent::process_pending_callbacks_() {
|
||||
if (this->pending_.scan_complete) {
|
||||
this->pending_.scan_complete = false;
|
||||
#ifdef USE_WIFI_SCAN_RESULTS_LISTENERS
|
||||
for (auto *listener : this->scan_results_listeners_) {
|
||||
listener->on_wifi_scan_results(this->scan_result_);
|
||||
}
|
||||
this->notify_scan_results_listeners_();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -777,10 +777,7 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
||||
s_sta_connecting = false;
|
||||
error_from_callback_ = 1;
|
||||
#ifdef USE_WIFI_CONNECT_STATE_LISTENERS
|
||||
static constexpr uint8_t EMPTY_BSSID[6] = {};
|
||||
for (auto *listener : this->connect_state_listeners_) {
|
||||
listener->on_wifi_connect_state(StringRef(), EMPTY_BSSID);
|
||||
}
|
||||
this->notify_disconnect_state_listeners_();
|
||||
#endif
|
||||
|
||||
} else if (data->event_base == IP_EVENT && data->event_id == IP_EVENT_STA_GOT_IP) {
|
||||
@@ -877,9 +874,7 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
||||
ESP_LOGV(TAG, "Scan complete: %u found, %zu stored%s", number, this->scan_result_.size(),
|
||||
needs_full ? "" : " (filtered)");
|
||||
#ifdef USE_WIFI_SCAN_RESULTS_LISTENERS
|
||||
for (auto *listener : this->scan_results_listeners_) {
|
||||
listener->on_wifi_scan_results(this->scan_result_);
|
||||
}
|
||||
this->notify_scan_results_listeners_();
|
||||
#endif
|
||||
|
||||
} else if (data->event_base == WIFI_EVENT && data->event_id == WIFI_EVENT_AP_START) {
|
||||
|
||||
@@ -525,10 +525,7 @@ void WiFiComponent::wifi_process_event_(LTWiFiEvent *event) {
|
||||
}
|
||||
|
||||
#ifdef USE_WIFI_CONNECT_STATE_LISTENERS
|
||||
static constexpr uint8_t EMPTY_BSSID[6] = {};
|
||||
for (auto *listener : this->connect_state_listeners_) {
|
||||
listener->on_wifi_connect_state(StringRef(), EMPTY_BSSID);
|
||||
}
|
||||
this->notify_disconnect_state_listeners_();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
@@ -702,9 +699,7 @@ void WiFiComponent::wifi_scan_done_callback_() {
|
||||
needs_full ? "" : " (filtered)");
|
||||
WiFi.scanDelete();
|
||||
#ifdef USE_WIFI_SCAN_RESULTS_LISTENERS
|
||||
for (auto *listener : this->scan_results_listeners_) {
|
||||
listener->on_wifi_scan_results(this->scan_result_);
|
||||
}
|
||||
this->notify_scan_results_listeners_();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -264,9 +264,7 @@ void WiFiComponent::wifi_loop_() {
|
||||
ESP_LOGV(TAG, "Scan complete: %zu found, %zu stored%s", s_scan_result_count, this->scan_result_.size(),
|
||||
needs_full ? "" : " (filtered)");
|
||||
#ifdef USE_WIFI_SCAN_RESULTS_LISTENERS
|
||||
for (auto *listener : this->scan_results_listeners_) {
|
||||
listener->on_wifi_scan_results(this->scan_result_);
|
||||
}
|
||||
this->notify_scan_results_listeners_();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -299,10 +297,7 @@ void WiFiComponent::wifi_loop_() {
|
||||
s_sta_had_ip = false;
|
||||
ESP_LOGV(TAG, "Disconnected");
|
||||
#ifdef USE_WIFI_CONNECT_STATE_LISTENERS
|
||||
static constexpr uint8_t EMPTY_BSSID[6] = {};
|
||||
for (auto *listener : this->connect_state_listeners_) {
|
||||
listener->on_wifi_connect_state(StringRef(), EMPTY_BSSID);
|
||||
}
|
||||
this->notify_disconnect_state_listeners_();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user