mirror of
https://github.com/esphome/esphome.git
synced 2025-10-15 16:23:48 +01:00
Add mDNS config dump (#2576)
This commit is contained in:
@@ -13,13 +13,16 @@
|
||||
namespace esphome {
|
||||
namespace mdns {
|
||||
|
||||
static const char *const TAG = "mdns";
|
||||
|
||||
#ifndef WEBSERVER_PORT
|
||||
#define WEBSERVER_PORT 80 // NOLINT
|
||||
#endif
|
||||
|
||||
std::vector<MDNSService> MDNSComponent::compile_services_() {
|
||||
std::vector<MDNSService> res;
|
||||
void MDNSComponent::compile_records_() {
|
||||
this->hostname_ = App.get_name();
|
||||
|
||||
this->services_.clear();
|
||||
#ifdef USE_API
|
||||
if (api::global_api_server != nullptr) {
|
||||
MDNSService service{};
|
||||
@@ -50,7 +53,7 @@ std::vector<MDNSService> MDNSComponent::compile_services_() {
|
||||
service.txt_records.push_back({"package_import_url", dashboard_import::get_package_import_url()});
|
||||
#endif
|
||||
|
||||
res.push_back(service);
|
||||
this->services_.push_back(service);
|
||||
}
|
||||
#endif // USE_API
|
||||
|
||||
@@ -60,11 +63,11 @@ std::vector<MDNSService> MDNSComponent::compile_services_() {
|
||||
service.service_type = "_prometheus-http";
|
||||
service.proto = "_tcp";
|
||||
service.port = WEBSERVER_PORT;
|
||||
res.push_back(service);
|
||||
this->services_.push_back(service);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (res.empty()) {
|
||||
if (this->services_.empty()) {
|
||||
// Publish "http" service if not using native API
|
||||
// This is just to have *some* mDNS service so that .local resolution works
|
||||
MDNSService service{};
|
||||
@@ -72,11 +75,21 @@ std::vector<MDNSService> MDNSComponent::compile_services_() {
|
||||
service.proto = "_tcp";
|
||||
service.port = WEBSERVER_PORT;
|
||||
service.txt_records.push_back({"version", ESPHOME_VERSION});
|
||||
res.push_back(service);
|
||||
this->services_.push_back(service);
|
||||
}
|
||||
}
|
||||
|
||||
void MDNSComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "mDNS:");
|
||||
ESP_LOGCONFIG(TAG, " Hostname: %s", this->hostname_.c_str());
|
||||
ESP_LOGV(TAG, " Services:");
|
||||
for (const auto &service : this->services_) {
|
||||
ESP_LOGV(TAG, " - %s, %s, %d", service.service_type.c_str(), service.proto.c_str(), service.port);
|
||||
for (const auto &record : service.txt_records) {
|
||||
ESP_LOGV(TAG, " TXT: %s = %s", record.key.c_str(), record.value.c_str());
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
std::string MDNSComponent::compile_hostname_() { return App.get_name(); }
|
||||
|
||||
} // namespace mdns
|
||||
} // namespace esphome
|
||||
|
Reference in New Issue
Block a user