[mdns] Conditionally compile extra services to reduce flash usage (#10129)

This commit is contained in:
J. Nick Koston 2025-08-07 14:32:35 -10:00 committed by GitHub
parent c4d1b1317a
commit 76fd104fb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 0 deletions

View File

@ -93,6 +93,9 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
if config[CONF_SERVICES]:
cg.add_define("USE_MDNS_EXTRA_SERVICES")
for service in config[CONF_SERVICES]:
txt = [
cg.StructInitializer(

View File

@ -104,7 +104,9 @@ void MDNSComponent::compile_records_() {
}
#endif
#ifdef USE_MDNS_EXTRA_SERVICES
this->services_.insert(this->services_.end(), this->services_extra_.begin(), this->services_extra_.end());
#endif
if (this->services_.empty()) {
// Publish "http" service if not using native API

View File

@ -35,14 +35,18 @@ class MDNSComponent : public Component {
#endif
float get_setup_priority() const override { return setup_priority::AFTER_CONNECTION; }
#ifdef USE_MDNS_EXTRA_SERVICES
void add_extra_service(MDNSService service) { services_extra_.push_back(std::move(service)); }
#endif
std::vector<MDNSService> get_services();
void on_shutdown() override;
protected:
#ifdef USE_MDNS_EXTRA_SERVICES
std::vector<MDNSService> services_extra_{};
#endif
std::vector<MDNSService> services_{};
std::string hostname_;
void compile_records_();