ESPHome 2025.5.0
Loading...
Searching...
No Matches
homeassistant_text_sensor.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
4
5namespace esphome {
6namespace homeassistant {
7
8static const char *const TAG = "homeassistant.text_sensor";
9
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}
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}
30} // namespace homeassistant
31} // namespace esphome
void subscribe_home_assistant_state(std::string entity_id, optional< std::string > attribute, std::function< void(std::string)> f)
bool has_value() const
Definition optional.h:87
value_type const & value() const
Definition optional.h:89
void publish_state(const std::string &state)
APIServer * global_api_server
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Definition component.cpp:27
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7