mirror of
https://github.com/esphome/esphome.git
synced 2026-09-20 11:38:48 +00:00
[mdns] Drop redundant USE_MDNS_EVENT_DRIVEN_POLLING guards in platform .cpp files
The Python validator enforces that wifi or ethernet is configured on ESP8266/ RP2040, so USE_WIFI_IP_STATE_LISTENERS (or the ethernet equivalent) is always requested in production, which always defines USE_MDNS_EVENT_DRIVEN_POLLING via mdns_component.h's derivation. defines.h also declares it unconditionally for static analysis. The #ifdef guards around start_polling_window_, setup()'s listener subscription, and on_ip_state were dead code — a misconfiguration should surface as a compile error, not silently strip out the method bodies.
This commit is contained in:
@@ -38,26 +38,21 @@ static void register_esp8266(MDNSComponent *, StaticVector<MDNSService, MDNS_SER
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MDNS_EVENT_DRIVEN_POLLING
|
||||
void MDNSComponent::start_polling_window_() {
|
||||
// uint32_t-ID set_interval/set_timeout already does atomic cancel-and-add.
|
||||
this->set_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
|
||||
@@ -66,7 +61,6 @@ void MDNSComponent::on_ip_state(const network::IPAddresses &ips, const network::
|
||||
this->start_polling_window_();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void MDNSComponent::on_shutdown() {
|
||||
MDNS.close();
|
||||
|
||||
@@ -38,13 +38,11 @@ static void register_rp2040(MDNSComponent *, StaticVector<MDNSService, MDNS_SERV
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MDNS_EVENT_DRIVEN_POLLING
|
||||
void MDNSComponent::start_polling_window_() {
|
||||
// uint32_t-ID set_interval/set_timeout already does atomic cancel-and-add.
|
||||
this->set_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
|
||||
@@ -74,7 +72,6 @@ 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.
|
||||
@@ -89,7 +86,6 @@ void MDNSComponent::on_ip_state(const network::IPAddresses &ips, const network::
|
||||
}
|
||||
this->start_polling_window_();
|
||||
}
|
||||
#endif
|
||||
|
||||
void MDNSComponent::on_shutdown() {
|
||||
MDNS.close();
|
||||
|
||||
Reference in New Issue
Block a user