mirror of
https://github.com/esphome/esphome.git
synced 2026-02-25 21:43:14 -07:00
adjust
This commit is contained in:
@@ -1474,9 +1474,7 @@ void WiFiComponent::check_connecting_finished(uint32_t now) {
|
||||
// On ESP8266, GOT_IP event may not fire for static IP configurations,
|
||||
// so notify IP state listeners here as a fallback.
|
||||
if (const WiFiAP *config = this->get_selected_sta_(); config && config->get_manual_ip().has_value()) {
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2218,6 +2216,14 @@ void WiFiComponent::notify_connect_state_listeners_() {
|
||||
}
|
||||
#endif // USE_WIFI_CONNECT_STATE_LISTENERS
|
||||
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
void WiFiComponent::notify_ip_state_listeners_() {
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
}
|
||||
#endif // USE_WIFI_IP_STATE_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_();
|
||||
|
||||
@@ -645,6 +645,10 @@ class WiFiComponent : public Component {
|
||||
/// Notify connect state listeners (called after state machine reaches STA_CONNECTED)
|
||||
void notify_connect_state_listeners_();
|
||||
#endif
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
/// Notify IP state listeners with current addresses
|
||||
void notify_ip_state_listeners_();
|
||||
#endif
|
||||
|
||||
#ifdef USE_ESP8266
|
||||
static void wifi_event_callback(System_Event_t *event);
|
||||
@@ -726,6 +730,7 @@ class WiFiComponent : public Component {
|
||||
// This serves as both the error flag and stores the reason for deferred logging
|
||||
uint8_t error_from_callback_{0};
|
||||
|
||||
#if defined(USE_WIFI_CONNECT_STATE_LISTENERS) || defined(USE_ESP8266)
|
||||
// Pending listener callbacks deferred from platform callbacks to main loop.
|
||||
struct {
|
||||
#ifdef USE_WIFI_CONNECT_STATE_LISTENERS
|
||||
@@ -742,6 +747,7 @@ class WiFiComponent : public Component {
|
||||
bool scan_complete : 1; // Scan complete, notify listeners
|
||||
#endif
|
||||
} pending_{};
|
||||
#endif
|
||||
|
||||
// Group all boolean values together
|
||||
bool has_ap_{false};
|
||||
|
||||
@@ -981,9 +981,7 @@ void WiFiComponent::process_pending_callbacks_() {
|
||||
if (this->pending_.got_ip) {
|
||||
this->pending_.got_ip = false;
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -753,9 +753,7 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
||||
// For static IP configurations, GOT_IP event may not fire, so notify IP listeners here
|
||||
#if defined(USE_WIFI_IP_STATE_LISTENERS) && defined(USE_WIFI_MANUAL_IP)
|
||||
if (const WiFiAP *config = this->get_selected_sta_(); config && config->get_manual_ip().has_value()) {
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -793,9 +791,7 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
||||
ESP_LOGV(TAG, "static_ip=" IPSTR " gateway=" IPSTR, IP2STR(&it.ip_info.ip), IP2STR(&it.ip_info.gw));
|
||||
this->got_ipv4_address_ = true;
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
#endif
|
||||
|
||||
#if USE_NETWORK_IPV6
|
||||
@@ -804,9 +800,7 @@ void WiFiComponent::wifi_process_event_(IDFWiFiEvent *data) {
|
||||
ESP_LOGV(TAG, "IPv6 address=" IPV6STR, IPV62STR(it.ip6_info.ip));
|
||||
this->num_ipv6_addresses_++;
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
#endif
|
||||
#endif /* USE_NETWORK_IPV6 */
|
||||
|
||||
|
||||
@@ -468,9 +468,7 @@ void WiFiComponent::wifi_process_event_(LTWiFiEvent *event) {
|
||||
if (const WiFiAP *config = this->get_selected_sta_(); config && config->get_manual_ip().has_value()) {
|
||||
s_sta_state = LTWiFiSTAState::CONNECTED;
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -553,18 +551,14 @@ void WiFiComponent::wifi_process_event_(LTWiFiEvent *event) {
|
||||
network::IPAddress(WiFi.gatewayIP()).str_to(gw_buf));
|
||||
s_sta_state = LTWiFiSTAState::CONNECTED;
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case ESPHOME_EVENT_ID_WIFI_STA_GOT_IP6: {
|
||||
ESP_LOGV(TAG, "Got IPv6");
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -290,9 +290,7 @@ void WiFiComponent::wifi_loop_() {
|
||||
#if defined(USE_WIFI_IP_STATE_LISTENERS) && defined(USE_WIFI_MANUAL_IP)
|
||||
if (const WiFiAP *config = this->get_selected_sta_(); config && config->get_manual_ip().has_value()) {
|
||||
s_sta_had_ip = true;
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
}
|
||||
#endif
|
||||
} else if (!is_connected && s_sta_was_connected) {
|
||||
@@ -322,9 +320,7 @@ void WiFiComponent::wifi_loop_() {
|
||||
s_sta_had_ip = true;
|
||||
ESP_LOGV(TAG, "Got IP address");
|
||||
#ifdef USE_WIFI_IP_STATE_LISTENERS
|
||||
for (auto *listener : this->ip_state_listeners_) {
|
||||
listener->on_ip_state(this->wifi_sta_ip_addresses(), this->get_dns_address(0), this->get_dns_address(1));
|
||||
}
|
||||
this->notify_ip_state_listeners_();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user