From fad39129975c70329d9f0cb18238d6df5c7061b9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 23 Apr 2026 21:20:03 -0500 Subject: [PATCH] [mdns] Restore USE_MDNS_EVENT_DRIVEN_POLLING guards around listener definitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit clang-tidy CI compiles with the raw esp8266-arduino-tidy env's flags — no Python codegen, and it doesn't pick up the feature defines from defines.h in the same way a real IDE does. USE_WIFI_IP_STATE_LISTENERS ends up undefined, the derivation in mdns_component.h doesn't fire, and the class doesn't declare start_polling_window_ / on_ip_state / the MDNS_POLL_* constants. Removing the guards in the platform cpps made those definitions dangle. Keep the listener-specific definitions under #ifdef USE_MDNS_EVENT_DRIVEN_POLLING. The Python validator still enforces the runtime invariant (wifi or ethernet must be present on ESP8266/RP2040), so production builds always fire through the listener path; this is purely about what the tidy compiler sees. --- esphome/components/mdns/mdns_esp8266.cpp | 6 ++++++ esphome/components/mdns/mdns_rp2040.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/esphome/components/mdns/mdns_esp8266.cpp b/esphome/components/mdns/mdns_esp8266.cpp index 3b9cfc65ff..95137ea116 100644 --- a/esphome/components/mdns/mdns_esp8266.cpp +++ b/esphome/components/mdns/mdns_esp8266.cpp @@ -38,21 +38,26 @@ static void register_esp8266(MDNSComponent *, StaticVectorset_interval(MDNS_POLL_ID, MDNS_UPDATE_INTERVAL_MS, []() { MDNS.update(); }); this->set_timeout(MDNS_POLL_STOP_ID, MDNS_POLL_WINDOW_MS, [this]() { this->cancel_interval(MDNS_POLL_ID); }); } +#endif void MDNSComponent::setup() { this->setup_buffers_and_register_(register_esp8266); +#ifdef USE_MDNS_EVENT_DRIVEN_POLLING // LEAmDNS's own LwipIntf::statusChangeCB drives _restart() on netif changes; we just // arm the window around the initial probe/announce and each reconnect. Unconditional // here is safe: setup_priority::AFTER_CONNECTION guarantees the network is up. 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 @@ -61,6 +66,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 ece2bc5ace..f5848893a3 100644 --- a/esphome/components/mdns/mdns_rp2040.cpp +++ b/esphome/components/mdns/mdns_rp2040.cpp @@ -38,11 +38,13 @@ static void register_rp2040(MDNSComponent *, StaticVectorset_interval(MDNS_POLL_ID, MDNS_UPDATE_INTERVAL_MS, []() { MDNS.update(); }); this->set_timeout(MDNS_POLL_STOP_ID, MDNS_POLL_WINDOW_MS, [this]() { this->cancel_interval(MDNS_POLL_ID); }); } +#endif void MDNSComponent::setup() { // arduino-pico stubs out LwipIntf::stateUpCB (the netif status callback LEAmDNS uses @@ -72,6 +74,7 @@ void MDNSComponent::setup() { #endif } +#ifdef USE_MDNS_EVENT_DRIVEN_POLLING void MDNSComponent::on_ip_state(const network::IPAddresses &ips, const network::IPAddress &, const network::IPAddress &) { // Listener only fires on IP acquisition (not loss); every event is a fresh IP. @@ -86,6 +89,7 @@ void MDNSComponent::on_ip_state(const network::IPAddresses &ips, const network:: } this->start_polling_window_(); } +#endif void MDNSComponent::on_shutdown() { MDNS.close();