ESPHome
2024.9.2
esphome
esphome
components
homeassistant
text_sensor
homeassistant_text_sensor.cpp
Go to the documentation of this file.
1
#include "
homeassistant_text_sensor.h
"
2
#include "
esphome/core/log.h
"
3
#include "
esphome/components/api/api_server.h
"
4
5
namespace
esphome
{
6
namespace
homeassistant {
7
8
static
const
char
*
const
TAG =
"homeassistant.text_sensor"
;
9
10
void
HomeassistantTextSensor::setup
() {
11
api::global_api_server
->
subscribe_home_assistant_state
(
12
this->
entity_id_
, this->
attribute_
, [
this
](
const
std::string &
state
) {
13
if
(this->
attribute_
.
has_value
()) {
14
ESP_LOGD(TAG,
"'%s::%s': Got attribute state '%s'"
, this->
entity_id_
.c_str(),
15
this->
attribute_
.
value
().c_str(), state.c_str());
16
}
else
{
17
ESP_LOGD(TAG,
"'%s': Got state '%s'"
, this->
entity_id_
.c_str(), state.c_str());
18
}
19
this->
publish_state
(state);
20
});
21
}
22
void
HomeassistantTextSensor::dump_config
() {
23
LOG_TEXT_SENSOR(
""
,
"Homeassistant Text Sensor"
,
this
);
24
ESP_LOGCONFIG(TAG,
" Entity ID: '%s'"
, this->
entity_id_
.c_str());
25
if
(this->
attribute_
.
has_value
()) {
26
ESP_LOGCONFIG(TAG,
" Attribute: '%s'"
, this->
attribute_
.
value
().c_str());
27
}
28
}
29
float
HomeassistantTextSensor::get_setup_priority
()
const
{
return
setup_priority::AFTER_CONNECTION
; }
30
}
// namespace homeassistant
31
}
// namespace esphome
esphome::optional::value
value_type const & value() const
Definition:
optional.h:89
esphome::homeassistant::HomeassistantTextSensor::entity_id_
std::string entity_id_
Definition:
homeassistant_text_sensor.h:18
esphome::setup_priority::AFTER_CONNECTION
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Definition:
component.cpp:27
homeassistant_text_sensor.h
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition:
text_sensor.cpp:9
esphome::optional::has_value
bool has_value() const
Definition:
optional.h:87
esphome::homeassistant::HomeassistantTextSensor::get_setup_priority
float get_setup_priority() const override
Definition:
homeassistant_text_sensor.cpp:29
esphome::homeassistant::HomeassistantTextSensor::attribute_
optional< std::string > attribute_
Definition:
homeassistant_text_sensor.h:19
esphome::homeassistant::HomeassistantTextSensor::setup
void setup() override
Definition:
homeassistant_text_sensor.cpp:10
esphome::homeassistant::HomeassistantTextSensor::dump_config
void dump_config() override
Definition:
homeassistant_text_sensor.cpp:22
esphome
Implementation of SPI Controller mode.
Definition:
a01nyub.cpp:7
api_server.h
esphome::api::APIServer::subscribe_home_assistant_state
void subscribe_home_assistant_state(std::string entity_id, optional< std::string > attribute, std::function< void(std::string)> f)
Definition:
api_server.cpp:356
esphome::text_sensor::TextSensor::state
std::string state
Definition:
text_sensor.h:59
log.h
esphome::api::global_api_server
APIServer * global_api_server
Definition:
api_server.cpp:346
Generated by
1.8.13