mirror of
https://github.com/esphome/esphome.git
synced 2025-08-09 03:47:48 +00:00
[mdns] Conditionally compile extra services to reduce flash usage (#10129)
This commit is contained in:
parent
c4d1b1317a
commit
76fd104fb6
@ -93,6 +93,9 @@ async def to_code(config):
|
|||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
|
if config[CONF_SERVICES]:
|
||||||
|
cg.add_define("USE_MDNS_EXTRA_SERVICES")
|
||||||
|
|
||||||
for service in config[CONF_SERVICES]:
|
for service in config[CONF_SERVICES]:
|
||||||
txt = [
|
txt = [
|
||||||
cg.StructInitializer(
|
cg.StructInitializer(
|
||||||
|
@ -104,7 +104,9 @@ void MDNSComponent::compile_records_() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_MDNS_EXTRA_SERVICES
|
||||||
this->services_.insert(this->services_.end(), this->services_extra_.begin(), this->services_extra_.end());
|
this->services_.insert(this->services_.end(), this->services_extra_.begin(), this->services_extra_.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
if (this->services_.empty()) {
|
if (this->services_.empty()) {
|
||||||
// Publish "http" service if not using native API
|
// Publish "http" service if not using native API
|
||||||
|
@ -35,14 +35,18 @@ class MDNSComponent : public Component {
|
|||||||
#endif
|
#endif
|
||||||
float get_setup_priority() const override { return setup_priority::AFTER_CONNECTION; }
|
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)); }
|
void add_extra_service(MDNSService service) { services_extra_.push_back(std::move(service)); }
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector<MDNSService> get_services();
|
std::vector<MDNSService> get_services();
|
||||||
|
|
||||||
void on_shutdown() override;
|
void on_shutdown() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
#ifdef USE_MDNS_EXTRA_SERVICES
|
||||||
std::vector<MDNSService> services_extra_{};
|
std::vector<MDNSService> services_extra_{};
|
||||||
|
#endif
|
||||||
std::vector<MDNSService> services_{};
|
std::vector<MDNSService> services_{};
|
||||||
std::string hostname_;
|
std::string hostname_;
|
||||||
void compile_records_();
|
void compile_records_();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user