diff --git a/esphome/components/mdns/mdns_esp8266.cpp b/esphome/components/mdns/mdns_esp8266.cpp index d1ffee6e61a..bc121542583 100644 --- a/esphome/components/mdns/mdns_esp8266.cpp +++ b/esphome/components/mdns/mdns_esp8266.cpp @@ -8,7 +8,9 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" #include "mdns_component.h" +#ifdef USE_MDNS_EVENT_DRIVEN_POLLING #include "esphome/components/wifi/wifi_component.h" +#endif namespace esphome::mdns { @@ -37,16 +39,21 @@ static void register_esp8266(MDNSComponent *, StaticVectorsetup_buffers_and_register_(register_esp8266); +#ifdef USE_MDNS_EVENT_DRIVEN_POLLING // LEAmDNS's own LwipIntf::statusChangeCB drives _restart() on netif changes; we only // need to arm the polling window around the initial probe/announce and each reconnect. wifi::global_wifi_component->add_ip_state_listener(this); this->start_polling_window_(); +#endif } +#ifdef USE_MDNS_EVENT_DRIVEN_POLLING void MDNSComponent::on_ip_state(const network::IPAddresses &ips, const network::IPAddress &, const network::IPAddress &) { // IP listener only fires on acquisition (not loss), so any notification is a fresh @@ -55,6 +62,7 @@ void MDNSComponent::on_ip_state(const network::IPAddresses &ips, const network:: this->start_polling_window_(); } } +#endif void MDNSComponent::on_shutdown() { MDNS.close(); diff --git a/esphome/components/mdns/mdns_rp2040.cpp b/esphome/components/mdns/mdns_rp2040.cpp index 1ecadea36e6..1b3c13178d7 100644 --- a/esphome/components/mdns/mdns_rp2040.cpp +++ b/esphome/components/mdns/mdns_rp2040.cpp @@ -42,7 +42,9 @@ static void register_rp2040(MDNSComponent *, StaticVectorstart_polling_window_(); } +#endif void MDNSComponent::on_shutdown() { MDNS.close();