Don't fall back to the global availability topic if it is empty (#553)

Fixes esphome/issues#320
This commit is contained in:
Brandon Davidson 2019-05-27 08:21:01 -07:00 committed by Otto Winter
parent 72a80f559a
commit 72218171b3

View File

@ -72,11 +72,13 @@ bool MQTTComponent::send_discovery_() {
root["command_topic"] = this->get_command_topic_(); root["command_topic"] = this->get_command_topic_();
if (this->availability_ == nullptr) { if (this->availability_ == nullptr) {
root["availability_topic"] = global_mqtt_client->get_availability().topic; if (!global_mqtt_client->get_availability().topic.empty()) {
if (global_mqtt_client->get_availability().payload_available != "online") root["availability_topic"] = global_mqtt_client->get_availability().topic;
root["payload_available"] = global_mqtt_client->get_availability().payload_available; if (global_mqtt_client->get_availability().payload_available != "online")
if (global_mqtt_client->get_availability().payload_not_available != "offline") root["payload_available"] = global_mqtt_client->get_availability().payload_available;
root["payload_not_available"] = global_mqtt_client->get_availability().payload_not_available; if (global_mqtt_client->get_availability().payload_not_available != "offline")
root["payload_not_available"] = global_mqtt_client->get_availability().payload_not_available;
}
} else if (!this->availability_->topic.empty()) { } else if (!this->availability_->topic.empty()) {
root["availability_topic"] = this->availability_->topic; root["availability_topic"] = this->availability_->topic;
if (this->availability_->payload_available != "online") if (this->availability_->payload_available != "online")