1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-06 20:03:46 +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

@@ -71,7 +71,7 @@ void MQTTFanComponent::setup() {
if (this->state_->get_traits().supports_speed()) {
this->subscribe(this->get_speed_level_command_topic(),
[this](const std::string &topic, const std::string &payload) {
optional<int> speed_level_opt = parse_int(payload);
optional<int> speed_level_opt = parse_number<int>(payload);
if (speed_level_opt.has_value()) {
const int speed_level = speed_level_opt.value();
if (speed_level >= 0 && speed_level <= this->state_->get_traits().supported_speed_count()) {