mirror of
https://github.com/esphome/esphome.git
synced 2024-12-26 17:17:46 +01:00
mDNS updates (#4399)
This commit is contained in:
parent
c6742117d3
commit
ac6693f177
@ -35,6 +35,8 @@ class MDNSComponent : public Component {
|
||||
|
||||
void add_extra_service(MDNSService service) { services_extra_.push_back(std::move(service)); }
|
||||
|
||||
void on_shutdown() override;
|
||||
|
||||
protected:
|
||||
std::vector<MDNSService> services_extra_{};
|
||||
std::vector<MDNSService> services_{};
|
||||
|
@ -1,9 +1,10 @@
|
||||
#ifdef USE_ESP_IDF
|
||||
#ifdef USE_ESP32
|
||||
|
||||
#include "mdns_component.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <mdns.h>
|
||||
#include <cstring>
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "mdns_component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace mdns {
|
||||
@ -47,7 +48,12 @@ void MDNSComponent::setup() {
|
||||
}
|
||||
}
|
||||
|
||||
void MDNSComponent::on_shutdown() {
|
||||
mdns_free();
|
||||
delay(40); // Allow the mdns packets announcing service removal to be sent
|
||||
}
|
||||
|
||||
} // namespace mdns
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
||||
#endif // USE_ESP32
|
@ -1,26 +0,0 @@
|
||||
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
||||
|
||||
#include "mdns_component.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <ESPmDNS.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace mdns {
|
||||
|
||||
void MDNSComponent::setup() {
|
||||
this->compile_records_();
|
||||
|
||||
MDNS.begin(this->hostname_.c_str());
|
||||
|
||||
for (const auto &service : this->services_) {
|
||||
MDNS.addService(service.service_type.c_str(), service.proto.c_str(), service.port);
|
||||
for (const auto &record : service.txt_records) {
|
||||
MDNS.addServiceTxt(service.service_type.c_str(), service.proto.c_str(), record.key.c_str(), record.value.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mdns
|
||||
} // namespace esphome
|
||||
|
||||
#endif // USE_ESP32_FRAMEWORK_ARDUINO
|
@ -1,10 +1,11 @@
|
||||
#if defined(USE_ESP8266) && defined(USE_ARDUINO)
|
||||
|
||||
#include "mdns_component.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include <ESP8266mDNS.h>
|
||||
#include "esphome/components/network/ip_address.h"
|
||||
#include "esphome/components/network/util.h"
|
||||
#include <ESP8266mDNS.h>
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "mdns_component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace mdns {
|
||||
@ -37,6 +38,11 @@ void MDNSComponent::setup() {
|
||||
|
||||
void MDNSComponent::loop() { MDNS.update(); }
|
||||
|
||||
void MDNSComponent::on_shutdown() {
|
||||
MDNS.close();
|
||||
delay(10);
|
||||
}
|
||||
|
||||
} // namespace mdns
|
||||
} // namespace esphome
|
||||
|
||||
|
@ -38,6 +38,11 @@ void MDNSComponent::setup() {
|
||||
|
||||
void MDNSComponent::loop() { MDNS.update(); }
|
||||
|
||||
void MDNSComponent::on_shutdown() {
|
||||
MDNS.close();
|
||||
delay(40);
|
||||
}
|
||||
|
||||
} // namespace mdns
|
||||
} // namespace esphome
|
||||
|
||||
|
@ -157,6 +157,11 @@ class DashboardImportDiscovery:
|
||||
return
|
||||
if state_change == ServiceStateChange.Removed:
|
||||
self.import_state.pop(name, None)
|
||||
return
|
||||
|
||||
if state_change == ServiceStateChange.Updated and name not in self.import_state:
|
||||
# Ignore updates for devices that are not in the import state
|
||||
return
|
||||
|
||||
info = zeroconf.get_service_info(service_type, name)
|
||||
_LOGGER.debug("-> resolved info: %s", info)
|
||||
|
Loading…
Reference in New Issue
Block a user