ESPHome 2026.1.5
Loading...
Searching...
No Matches
homeassistant_text_sensor.cpp
Go to the documentation of this file.
3#include "esphome/core/log.h"
5
6namespace esphome {
7namespace homeassistant {
8
9static const char *const TAG = "homeassistant.text_sensor";
10
13 if (this->attribute_ != nullptr) {
14 ESP_LOGD(TAG, "'%s::%s': Got attribute state '%s'", this->entity_id_, this->attribute_, state.c_str());
15 } else {
16 ESP_LOGD(TAG, "'%s': Got state '%s'", this->entity_id_, state.c_str());
17 }
18 this->publish_state(state.c_str(), state.size());
19 });
20}
22 LOG_TEXT_SENSOR("", "Homeassistant Text Sensor", this);
23 ESP_LOGCONFIG(TAG, " Entity ID: '%s'", this->entity_id_);
24 if (this->attribute_ != nullptr) {
25 ESP_LOGCONFIG(TAG, " Attribute: '%s'", this->attribute_);
26 }
27}
29} // namespace homeassistant
30} // namespace esphome
StringRef is a reference to a string owned by something else.
Definition string_ref.h:26
constexpr const char * c_str() const
Definition string_ref.h:73
void subscribe_home_assistant_state(const char *entity_id, const char *attribute, std::function< void(StringRef)> f)
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:89
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7