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_();
if (this->availability_ == nullptr) {
root["availability_topic"] = global_mqtt_client->get_availability().topic;
if (global_mqtt_client->get_availability().payload_available != "online")
root["payload_available"] = global_mqtt_client->get_availability().payload_available;
if (global_mqtt_client->get_availability().payload_not_available != "offline")
root["payload_not_available"] = global_mqtt_client->get_availability().payload_not_available;
if (!global_mqtt_client->get_availability().topic.empty()) {
root["availability_topic"] = global_mqtt_client->get_availability().topic;
if (global_mqtt_client->get_availability().payload_available != "online")
root["payload_available"] = global_mqtt_client->get_availability().payload_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()) {
root["availability_topic"] = this->availability_->topic;
if (this->availability_->payload_available != "online")