ESPHome 2025.5.0
Loading...
Searching...
No Matches
text_call.cpp
Go to the documentation of this file.
1#include "text_call.h"
2#include "esphome/core/log.h"
3#include "text.h"
4
5namespace esphome {
6namespace text {
7
8static const char *const TAG = "text";
9
10TextCall &TextCall::set_value(const std::string &value) {
11 this->value_ = value;
12 return *this;
13}
14
16 const auto *name = this->parent_->get_name().c_str();
17
18 if (!this->value_.has_value()) {
19 ESP_LOGW(TAG, "'%s' - No value set for TextCall", name);
20 return;
21 }
22
23 int sz = this->value_.value().size();
24
25 if (sz > this->parent_->traits.get_max_length()) {
26 ESP_LOGW(TAG, "'%s' - Value set for TextCall is too long", name);
27 this->value_.reset();
28 return;
29 }
30
31 if (sz < this->parent_->traits.get_min_length()) {
32 ESP_LOGW(TAG, "'%s' - Value set for TextCall is too short", name);
33 this->value_.reset();
34 return;
35 }
36}
37
39 this->validate_();
40 if (!this->value_.has_value()) {
41 ESP_LOGW(TAG, "'%s' - No value set for TextCall", this->parent_->get_name().c_str());
42 return;
43 }
44 std::string target_value = this->value_.value();
45
46 if (this->parent_->traits.get_mode() == TEXT_MODE_PASSWORD) {
47 ESP_LOGD(TAG, "'%s' - Setting password value: " LOG_SECRET("'%s'"), this->parent_->get_name().c_str(),
48 target_value.c_str());
49 } else {
50 ESP_LOGD(TAG, "'%s' - Setting text value: %s", this->parent_->get_name().c_str(), target_value.c_str());
51 }
52 this->parent_->control(target_value);
53}
54
55} // namespace text
56} // namespace esphome
const StringRef & get_name() const
constexpr const char * c_str() const
Definition string_ref.h:68
bool has_value() const
Definition optional.h:87
value_type const & value() const
Definition optional.h:89
TextCall & set_value(const std::string &value)
Definition text_call.cpp:10
optional< std::string > value_
Definition text_call.h:20
virtual void control(const std::string &value)=0
Set the value of the text input, this is a virtual method that each text input integration must imple...
TextTraits traits
Definition text.h:27
TextMode get_mode() const
Definition text_traits.h:29
const char *const TAG
Definition spi.cpp:8
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7