1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00

Command retain option for MQTT component (#3078)

This commit is contained in:
VitaliyKurokhtin
2022-01-23 00:05:37 -08:00
committed by GitHub
parent 97681d142e
commit 8187a4bce9
7 changed files with 304 additions and 289 deletions

View File

@@ -92,6 +92,8 @@ bool MQTTComponent::send_discovery_() {
root[MQTT_STATE_TOPIC] = this->get_state_topic_();
if (config.command_topic)
root[MQTT_COMMAND_TOPIC] = this->get_command_topic_();
if (this->command_retain_)
root[MQTT_COMMAND_RETAIN] = true;
if (this->availability_ == nullptr) {
if (!global_mqtt_client->get_availability().topic.empty()) {
@@ -165,6 +167,7 @@ void MQTTComponent::set_custom_state_topic(const std::string &custom_state_topic
void MQTTComponent::set_custom_command_topic(const std::string &custom_command_topic) {
this->custom_command_topic_ = custom_command_topic;
}
void MQTTComponent::set_command_retain(bool command_retain) { this->command_retain_ = command_retain; }
void MQTTComponent::set_availability(std::string topic, std::string payload_available,
std::string payload_not_available) {