ESPHome
2024.11.1
esphome
esphome
components
mqtt_subscribe
text_sensor
mqtt_subscribe_text_sensor.cpp
Go to the documentation of this file.
1
#include "
mqtt_subscribe_text_sensor.h
"
2
3
#ifdef USE_MQTT
4
5
#include "
esphome/core/log.h
"
6
#include <utility>
7
8
namespace
esphome
{
9
namespace
mqtt_subscribe {
10
11
static
const
char
*
const
TAG =
"mqtt_subscribe.text_sensor"
;
12
13
void
MQTTSubscribeTextSensor::setup
() {
14
this->
parent_
->
subscribe
(
15
this->
topic_
, [
this
](
const
std::string &topic,
const
std::string &payload) { this->
publish_state
(payload); },
16
this->
qos_
);
17
}
18
float
MQTTSubscribeTextSensor::get_setup_priority
()
const
{
return
setup_priority::AFTER_CONNECTION
; }
19
void
MQTTSubscribeTextSensor::set_qos
(uint8_t qos) { this->
qos_
= qos; }
20
void
MQTTSubscribeTextSensor::dump_config
() {
21
LOG_TEXT_SENSOR(
""
,
"MQTT Subscribe Text Sensor"
,
this
);
22
ESP_LOGCONFIG(TAG,
" Topic: %s"
, this->
topic_
.c_str());
23
}
24
25
}
// namespace mqtt_subscribe
26
}
// namespace esphome
27
28
#endif // USE_MQTT
esphome::mqtt_subscribe::MQTTSubscribeTextSensor::dump_config
void dump_config() override
Definition:
mqtt_subscribe_text_sensor.cpp:20
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
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition:
text_sensor.cpp:9
esphome::mqtt_subscribe::MQTTSubscribeTextSensor::qos_
uint8_t qos_
Definition:
mqtt_subscribe_text_sensor.h:26
esphome::mqtt_subscribe::MQTTSubscribeTextSensor::set_qos
void set_qos(uint8_t qos)
Definition:
mqtt_subscribe_text_sensor.cpp:19
esphome::mqtt_subscribe::MQTTSubscribeTextSensor::setup
void setup() override
Definition:
mqtt_subscribe_text_sensor.cpp:13
mqtt_subscribe_text_sensor.h
esphome::mqtt_subscribe::MQTTSubscribeTextSensor::topic_
std::string topic_
Definition:
mqtt_subscribe_text_sensor.h:25
esphome
Implementation of SPI Controller mode.
Definition:
a01nyub.cpp:7
esphome::mqtt_subscribe::MQTTSubscribeTextSensor::get_setup_priority
float get_setup_priority() const override
Definition:
mqtt_subscribe_text_sensor.cpp:18
log.h
esphome::mqtt::MQTTClientComponent::subscribe
void subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos=0)
Subscribe to an MQTT topic and call callback when a message is received.
esphome::mqtt_subscribe::MQTTSubscribeTextSensor::parent_
mqtt::MQTTClientComponent * parent_
Definition:
mqtt_subscribe_text_sensor.h:24
Generated by
1.8.13