1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-17 23:35:47 +00:00

Reduce memory usage with StringRef in MQTT Components (#5719)

This commit is contained in:
kahrendt
2023-12-21 02:19:15 -05:00
committed by GitHub
parent 222bb9b495
commit 74281b93c4
3 changed files with 15 additions and 12 deletions

View File

@@ -34,13 +34,13 @@ std::string MQTTComponent::get_default_topic_for_(const std::string &suffix) con
std::string MQTTComponent::get_state_topic_() const {
if (this->has_custom_state_topic_)
return this->custom_state_topic_;
return this->custom_state_topic_.str();
return this->get_default_topic_for_("state");
}
std::string MQTTComponent::get_command_topic_() const {
if (this->has_custom_command_topic_)
return this->custom_command_topic_;
return this->custom_command_topic_.str();
return this->get_default_topic_for_("command");
}
@@ -180,12 +180,12 @@ MQTTComponent::MQTTComponent() = default;
float MQTTComponent::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; }
void MQTTComponent::disable_discovery() { this->discovery_enabled_ = false; }
void MQTTComponent::set_custom_state_topic(const std::string &custom_state_topic) {
this->custom_state_topic_ = custom_state_topic;
void MQTTComponent::set_custom_state_topic(const char *custom_state_topic) {
this->custom_state_topic_ = StringRef(custom_state_topic);
this->has_custom_state_topic_ = true;
}
void MQTTComponent::set_custom_command_topic(const std::string &custom_command_topic) {
this->custom_command_topic_ = custom_command_topic;
void MQTTComponent::set_custom_command_topic(const char *custom_command_topic) {
this->custom_command_topic_ = StringRef(custom_command_topic);
this->has_custom_command_topic_ = true;
}
void MQTTComponent::set_command_retain(bool command_retain) { this->command_retain_ = command_retain; }