ESPHome
2024.11.1
esphome
esphome
components
nextion
text_sensor
nextion_textsensor.cpp
Go to the documentation of this file.
1
#include "
nextion_textsensor.h
"
2
#include "
esphome/core/util.h
"
3
#include "
esphome/core/log.h
"
4
5
namespace
esphome
{
6
namespace
nextion {
7
static
const
char
*
const
TAG =
"nextion_textsensor"
;
8
9
void
NextionTextSensor::process_text
(
const
std::string &variable_name,
const
std::string &text_value) {
10
if
(!this->
nextion_
->
is_setup
())
11
return
;
12
if
(this->
variable_name_
== variable_name) {
13
this->
publish_state
(text_value);
14
ESP_LOGD(TAG,
"Processed text_sensor \"%s\" state \"%s\""
, variable_name.c_str(), text_value.c_str());
15
}
16
}
17
18
void
NextionTextSensor::update
() {
19
if
(!this->
nextion_
->
is_setup
() || this->
nextion_
->
is_updating
())
20
return
;
21
this->
nextion_
->
add_to_get_queue
(
this
);
22
}
23
24
void
NextionTextSensor::set_state
(
const
std::string &
state
,
bool
publish,
bool
send_to_nextion) {
25
if
(!this->
nextion_
->
is_setup
() || this->
nextion_
->
is_updating
())
26
return
;
27
28
if
(send_to_nextion) {
29
if
(this->
nextion_
->
is_sleeping
() || !this->
visible_
) {
30
this->
needs_to_send_update_
=
true
;
31
}
else
{
32
this->
nextion_
->
add_no_result_to_queue_with_set
(
this
, state);
33
}
34
}
35
36
if
(publish) {
37
this->
publish_state
(state);
38
}
else
{
39
this->state =
state
;
40
this->
has_state_
=
true
;
41
}
42
43
this->
update_component_settings
();
44
45
ESP_LOGN(TAG,
"Wrote state for text_sensor \"%s\" state \"%s\""
, this->
variable_name_
.c_str(), state.c_str());
46
}
47
48
}
// namespace nextion
49
}
// namespace esphome
esphome::nextion::NextionBase::is_setup
bool is_setup()
Definition:
nextion_base.h:54
esphome::nextion::NextionComponentBase::variable_name_
std::string variable_name_
Definition:
nextion_component_base.h:92
esphome::nextion::NextionTextSensor::update
void update() override
Definition:
nextion_textsensor.cpp:18
esphome::nextion::NextionComponent::update_component_settings
void update_component_settings() override
Definition:
nextion_component.h:12
esphome::nextion::NextionComponent::nextion_
NextionBase * nextion_
Definition:
nextion_component.h:24
nextion_textsensor.h
esphome::text_sensor::TextSensor::has_state_
bool has_state_
Definition:
text_sensor.h:80
esphome::nextion::NextionComponentBase::needs_to_send_update_
bool needs_to_send_update_
Definition:
nextion_component_base.h:100
esphome::nextion::NextionBase::is_sleeping
bool is_sleeping()
Definition:
nextion_base.h:53
esphome::nextion::NextionTextSensor::set_state
void set_state(const std::string &state, bool publish) override
Definition:
nextion_textsensor.h:20
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition:
text_sensor.cpp:9
esphome::nextion::NextionBase::is_updating
virtual bool is_updating()
Definition:
nextion_base.h:51
esphome::nextion::NextionComponent::visible_
bool visible_
Definition:
nextion_component.h:42
esphome::nextion::NextionBase::add_to_get_queue
virtual void add_to_get_queue(NextionComponentBase *component)=0
esphome
Implementation of SPI Controller mode.
Definition:
a01nyub.cpp:7
util.h
esphome::nextion::NextionTextSensor::process_text
void process_text(const std::string &variable_name, const std::string &text_value) override
Definition:
nextion_textsensor.cpp:9
esphome::text_sensor::TextSensor::state
std::string state
Definition:
text_sensor.h:59
log.h
esphome::nextion::NextionBase::add_no_result_to_queue_with_set
virtual void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value)=0
Generated by
1.8.13