1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-28 16:12:24 +01:00

Introduce parse_number() helper function (#2659)

This commit is contained in:
Oxan van Leeuwen
2021-11-10 19:15:06 +01:00
committed by GitHub
parent 219b225ac0
commit 15f9677d33
15 changed files with 70 additions and 36 deletions

View File

@@ -13,7 +13,7 @@ void MQTTSubscribeSensor::setup() {
mqtt::global_mqtt_client->subscribe(
this->topic_,
[this](const std::string &topic, const std::string &payload) {
auto val = parse_float(payload);
auto val = parse_number<float>(payload);
if (!val.has_value()) {
ESP_LOGW(TAG, "Can't convert '%s' to number!", payload.c_str());
this->publish_state(NAN);