[mdns] Gate listener code under USE_MDNS_EVENT_DRIVEN_POLLING for clang-tidy

clang-tidy compiles mdns_esp8266.cpp / mdns_rp2040.cpp with only the tidy env's
raw build flags, without the Python codegen defines (USE_WIFI_IP_STATE_LISTENERS,
USE_ETHERNET_IP_STATE_LISTENERS, USE_MDNS_EVENT_DRIVEN_POLLING). Wrap all
listener-specific code paths under USE_MDNS_EVENT_DRIVEN_POLLING so tidy sees a
compilable translation unit with an empty setup() instead of unresolved members
on WiFiComponent / MDNSComponent.

Production builds always have the listener defines via the mdns Python
to_code()'s wifi.request_wifi_ip_state_listener() /
ethernet.request_ethernet_ip_state_listener() calls, so this is tidy-only dead
code at runtime.
This commit is contained in:
J. Nick Koston
2026-04-23 20:06:14 -05:00
parent 09fe59c5cc
commit 6938f2b400
2 changed files with 12 additions and 0 deletions
+8
View File
@@ -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 *, StaticVector<MDNSService, MDNS_SER
}
}
#ifdef USE_MDNS_EVENT_DRIVEN_POLLING
void mdns_pump_update() { MDNS.update(); }
#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 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();
+4
View File
@@ -42,7 +42,9 @@ static void register_rp2040(MDNSComponent *, StaticVector<MDNSService, MDNS_SERV
}
}
#ifdef USE_MDNS_EVENT_DRIVEN_POLLING
void mdns_pump_update() { MDNS.update(); }
#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();