Add text component (#5336)

Co-authored-by: Maurits <maurits@vloop.nl>
Co-authored-by: mauritskorse <mauritskorse@gmail.com>
Co-authored-by: Daniel Dunn <dannydunn@eternityforest.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Daniel Dunn
2023-10-25 03:00:32 -06:00
committed by GitHub
parent cf7df9e360
commit e80bd8ed3d
50 changed files with 1545 additions and 7 deletions
+26
View File
@@ -0,0 +1,26 @@
#include "text.h"
#include "esphome/core/log.h"
namespace esphome {
namespace text {
static const char *const TAG = "text";
void Text::publish_state(const std::string &state) {
this->has_state_ = true;
this->state = state;
if (this->traits.get_mode() == TEXT_MODE_PASSWORD) {
ESP_LOGD(TAG, "'%s': Sending state " LOG_SECRET("'%s'"), this->get_name().c_str(), state.c_str());
} else {
ESP_LOGD(TAG, "'%s': Sending state %s", this->get_name().c_str(), state.c_str());
}
this->state_callback_.call(state);
}
void Text::add_on_state_callback(std::function<void(std::string)> &&callback) {
this->state_callback_.add(std::move(callback));
}
} // namespace text
} // namespace esphome