1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00:00

Use Clang 11 (#1846)

This commit is contained in:
Stefan Agner
2021-06-08 22:16:17 +02:00
committed by GitHub
parent 4711f36a1f
commit 13fe9e83fa
7 changed files with 74 additions and 32 deletions

View File

@@ -7,18 +7,19 @@ namespace mqtt_subscribe {
static const char *TAG = "mqtt_subscribe.sensor";
void MQTTSubscribeSensor::setup() {
mqtt::global_mqtt_client->subscribe(this->topic_,
[this](const std::string &topic, std::string payload) {
auto val = parse_float(payload);
if (!val.has_value()) {
ESP_LOGW(TAG, "Can't convert '%s' to number!", payload.c_str());
this->publish_state(NAN);
return;
}
mqtt::global_mqtt_client->subscribe(
this->topic_,
[this](const std::string &topic, std::string payload) {
auto val = parse_float(payload);
if (!val.has_value()) {
ESP_LOGW(TAG, "Can't convert '%s' to number!", payload.c_str());
this->publish_state(NAN);
return;
}
this->publish_state(*val);
},
this->qos_);
this->publish_state(*val);
},
this->qos_);
}
float MQTTSubscribeSensor::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; }

View File

@@ -7,9 +7,9 @@ namespace mqtt_subscribe {
static const char *TAG = "mqtt_subscribe.text_sensor";
void MQTTSubscribeTextSensor::setup() {
this->parent_->subscribe(this->topic_,
[this](const std::string &topic, std::string payload) { this->publish_state(payload); },
this->qos_);
this->parent_->subscribe(
this->topic_, [this](const std::string &topic, std::string payload) { this->publish_state(payload); },
this->qos_);
}
float MQTTSubscribeTextSensor::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; }
void MQTTSubscribeTextSensor::set_qos(uint8_t qos) { this->qos_ = qos; }