mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
fix to PR # 3887 MQTT connection not using discovery: false (#5275)
This commit is contained in:
parent
01f6791d1c
commit
3003485dc6
1 changed files with 11 additions and 8 deletions
|
@ -66,6 +66,7 @@ void MQTTClientComponent::setup() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (this->is_discovery_enabled()) {
|
||||||
this->subscribe(
|
this->subscribe(
|
||||||
"esphome/discover", [this](const std::string &topic, const std::string &payload) { this->send_device_info_(); },
|
"esphome/discover", [this](const std::string &topic, const std::string &payload) { this->send_device_info_(); },
|
||||||
2);
|
2);
|
||||||
|
@ -74,17 +75,19 @@ void MQTTClientComponent::setup() {
|
||||||
topic.append(App.get_name());
|
topic.append(App.get_name());
|
||||||
this->subscribe(
|
this->subscribe(
|
||||||
topic, [this](const std::string &topic, const std::string &payload) { this->send_device_info_(); }, 2);
|
topic, [this](const std::string &topic, const std::string &payload) { this->send_device_info_(); }, 2);
|
||||||
|
}
|
||||||
|
|
||||||
this->last_connected_ = millis();
|
this->last_connected_ = millis();
|
||||||
this->start_dnslookup_();
|
this->start_dnslookup_();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MQTTClientComponent::send_device_info_() {
|
void MQTTClientComponent::send_device_info_() {
|
||||||
if (!this->is_connected()) {
|
if (!this->is_connected() or !this->is_discovery_enabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string topic = "esphome/discover/";
|
std::string topic = "esphome/discover/";
|
||||||
topic.append(App.get_name());
|
topic.append(App.get_name());
|
||||||
|
|
||||||
this->publish_json(
|
this->publish_json(
|
||||||
topic,
|
topic,
|
||||||
[](JsonObject root) {
|
[](JsonObject root) {
|
||||||
|
|
Loading…
Reference in a new issue