8 namespace mqtt_subscribe {
10 static const char *
const TAG =
"mqtt_subscribe.sensor";
15 [
this](
const std::string &topic,
const std::string &payload) {
16 auto val = parse_number<float>(payload);
17 if (!
val.has_value()) {
18 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
31 LOG_SENSOR(
"",
"MQTT Subscribe",
this);
32 ESP_LOGCONFIG(TAG,
" Topic: %s", this->
topic_.c_str());
float get_setup_priority() const override
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
void dump_config() override
MQTTClientComponent * global_mqtt_client
void publish_state(float state)
Publish a new state to the front-end.
void set_qos(uint8_t qos)
Implementation of SPI Controller mode.
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.