fix to PR # 3887 MQTT connection not using discovery: false (#5275)

This commit is contained in:
luka6000 2023-09-01 03:20:21 +02:00 committed by GitHub
parent 01f6791d1c
commit 3003485dc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,6 +66,7 @@ void MQTTClientComponent::setup() {
}
#endif
if (this->is_discovery_enabled()) {
this->subscribe(
"esphome/discover", [this](const std::string &topic, const std::string &payload) { this->send_device_info_(); },
2);
@ -74,17 +75,19 @@ void MQTTClientComponent::setup() {
topic.append(App.get_name());
this->subscribe(
topic, [this](const std::string &topic, const std::string &payload) { this->send_device_info_(); }, 2);
}
this->last_connected_ = millis();
this->start_dnslookup_();
}
void MQTTClientComponent::send_device_info_() {
if (!this->is_connected()) {
if (!this->is_connected() or !this->is_discovery_enabled()) {
return;
}
std::string topic = "esphome/discover/";
topic.append(App.get_name());
this->publish_json(
topic,
[](JsonObject root) {