From d1aa1881bba7744ababf24cc7b773f1e08209ef7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 19 Mar 2026 08:42:26 -1000 Subject: [PATCH] [core] Replace std::bind with lambdas across 13 components (#14961) --- esphome/components/dps310/dps310.cpp | 3 +-- .../components/esp32_improv/esp32_improv_component.cpp | 3 +-- .../components/improv_serial/improv_serial_component.cpp | 3 +-- esphome/components/max31855/max31855.cpp | 3 +-- esphome/components/max31856/max31856.cpp | 4 ++-- esphome/components/max31865/max31865.cpp | 3 +-- esphome/components/max6675/max6675.cpp | 3 +-- esphome/components/midea/appliance_base.h | 2 +- esphome/components/ms5611/ms5611.cpp | 6 ++---- esphome/components/ms8607/ms8607.cpp | 9 +++------ esphome/components/sht4x/sht4x.cpp | 2 +- esphome/components/sprinkler/sprinkler.cpp | 4 ++-- 12 files changed, 17 insertions(+), 28 deletions(-) diff --git a/esphome/components/dps310/dps310.cpp b/esphome/components/dps310/dps310.cpp index aa0a77cdd8..b1366cd069 100644 --- a/esphome/components/dps310/dps310.cpp +++ b/esphome/components/dps310/dps310.cpp @@ -127,8 +127,7 @@ void DPS310Component::read_() { this->update_in_progress_ = false; this->status_clear_warning(); } else { - auto f = std::bind(&DPS310Component::read_, this); - this->set_timeout("dps310", 10, f); + this->set_timeout("dps310", 10, [this]() { this->read_(); }); } } diff --git a/esphome/components/esp32_improv/esp32_improv_component.cpp b/esphome/components/esp32_improv/esp32_improv_component.cpp index e4ae49f235..c24b08b06f 100644 --- a/esphome/components/esp32_improv/esp32_improv_component.cpp +++ b/esphome/components/esp32_improv/esp32_improv_component.cpp @@ -350,8 +350,7 @@ void ESP32ImprovComponent::process_incoming_data_() { ESP_LOGD(TAG, "Received Improv Wi-Fi settings ssid=%s, password=" LOG_SECRET("%s"), command.ssid.c_str(), command.password.c_str()); - auto f = std::bind(&ESP32ImprovComponent::on_wifi_connect_timeout_, this); - this->set_timeout("wifi-connect-timeout", 30000, f); + this->set_timeout("wifi-connect-timeout", 30000, [this]() { this->on_wifi_connect_timeout_(); }); this->incoming_data_.clear(); break; } diff --git a/esphome/components/improv_serial/improv_serial_component.cpp b/esphome/components/improv_serial/improv_serial_component.cpp index edceb9a3b1..003328d535 100644 --- a/esphome/components/improv_serial/improv_serial_component.cpp +++ b/esphome/components/improv_serial/improv_serial_component.cpp @@ -245,8 +245,7 @@ bool ImprovSerialComponent::parse_improv_payload_(improv::ImprovCommand &command ESP_LOGD(TAG, "Received settings: SSID=%s, password=" LOG_SECRET("%s"), command.ssid.c_str(), command.password.c_str()); - auto f = std::bind(&ImprovSerialComponent::on_wifi_connect_timeout_, this); - this->set_timeout("wifi-connect-timeout", 30000, f); + this->set_timeout("wifi-connect-timeout", 30000, [this]() { this->on_wifi_connect_timeout_(); }); return true; } case improv::GET_CURRENT_STATE: diff --git a/esphome/components/max31855/max31855.cpp b/esphome/components/max31855/max31855.cpp index 99129880f4..8370977ce2 100644 --- a/esphome/components/max31855/max31855.cpp +++ b/esphome/components/max31855/max31855.cpp @@ -15,8 +15,7 @@ void MAX31855Sensor::update() { this->disable(); // Conversion time typ: 170ms, max: 220ms - auto f = std::bind(&MAX31855Sensor::read_data_, this); - this->set_timeout("value", 220, f); + this->set_timeout("value", 220, [this]() { this->read_data_(); }); } void MAX31855Sensor::setup() { this->spi_setup(); } diff --git a/esphome/components/max31856/max31856.cpp b/esphome/components/max31856/max31856.cpp index ff65c8c5c9..35e12309ba 100644 --- a/esphome/components/max31856/max31856.cpp +++ b/esphome/components/max31856/max31856.cpp @@ -41,8 +41,8 @@ void MAX31856Sensor::update() { this->one_shot_temperature_(); // Datasheet max conversion time for 1 shot is 155ms for 60Hz / 185ms for 50Hz - auto f = std::bind(&MAX31856Sensor::read_thermocouple_temperature_, this); - this->set_timeout("MAX31856Sensor::read_thermocouple_temperature_", filter_ == FILTER_60HZ ? 155 : 185, f); + this->set_timeout("MAX31856Sensor::read_thermocouple_temperature_", filter_ == FILTER_60HZ ? 155 : 185, + [this]() { this->read_thermocouple_temperature_(); }); } void MAX31856Sensor::read_thermocouple_temperature_() { diff --git a/esphome/components/max31865/max31865.cpp b/esphome/components/max31865/max31865.cpp index 09b8368d07..8b06a01166 100644 --- a/esphome/components/max31865/max31865.cpp +++ b/esphome/components/max31865/max31865.cpp @@ -60,8 +60,7 @@ void MAX31865Sensor::update() { this->write_config_(0b11100000, 0b10100000); // Datasheet max conversion time is 55ms for 60Hz / 66ms for 50Hz - auto f = std::bind(&MAX31865Sensor::read_data_, this); - this->set_timeout("value", filter_ == FILTER_60HZ ? 55 : 66, f); + this->set_timeout("value", filter_ == FILTER_60HZ ? 55 : 66, [this]() { this->read_data_(); }); } void MAX31865Sensor::setup() { diff --git a/esphome/components/max6675/max6675.cpp b/esphome/components/max6675/max6675.cpp index c329cdfd42..b8527c6b1d 100644 --- a/esphome/components/max6675/max6675.cpp +++ b/esphome/components/max6675/max6675.cpp @@ -13,8 +13,7 @@ void MAX6675Sensor::update() { this->disable(); // Conversion time typ: 170ms, max: 220ms - auto f = std::bind(&MAX6675Sensor::read_data_, this); - this->set_timeout("value", 250, f); + this->set_timeout("value", 250, [this]() { this->read_data_(); }); } void MAX6675Sensor::setup() { this->spi_setup(); } diff --git a/esphome/components/midea/appliance_base.h b/esphome/components/midea/appliance_base.h index 660d185b49..c7737ba7d6 100644 --- a/esphome/components/midea/appliance_base.h +++ b/esphome/components/midea/appliance_base.h @@ -59,7 +59,7 @@ template class ApplianceBase : public Component { public: ApplianceBase() { this->base_.setStream(&this->stream_); - this->base_.addOnStateCallback(std::bind(&ApplianceBase::on_status_change, this)); + this->base_.addOnStateCallback([this]() { this->on_status_change(); }); dudanov::midea::ApplianceBase::setLogger( [](int level, const char *tag, int line, const String &format, va_list args) { esp_log_vprintf_(level, tag, line, format.c_str(), args); diff --git a/esphome/components/ms5611/ms5611.cpp b/esphome/components/ms5611/ms5611.cpp index 7ed73400c8..d47ca245b8 100644 --- a/esphome/components/ms5611/ms5611.cpp +++ b/esphome/components/ms5611/ms5611.cpp @@ -45,8 +45,7 @@ void MS5611Component::update() { return; } - auto f = std::bind(&MS5611Component::read_temperature_, this); - this->set_timeout("temperature", 10, f); + this->set_timeout("temperature", 10, [this]() { this->read_temperature_(); }); } void MS5611Component::read_temperature_() { uint8_t bytes[3]; @@ -62,8 +61,7 @@ void MS5611Component::read_temperature_() { return; } - auto f = std::bind(&MS5611Component::read_pressure_, this, raw_temperature); - this->set_timeout("pressure", 10, f); + this->set_timeout("pressure", 10, [this, raw_temperature]() { this->read_pressure_(raw_temperature); }); } void MS5611Component::read_pressure_(uint32_t raw_temperature) { uint8_t bytes[3]; diff --git a/esphome/components/ms8607/ms8607.cpp b/esphome/components/ms8607/ms8607.cpp index 88a3e6d7dc..d141dcb191 100644 --- a/esphome/components/ms8607/ms8607.cpp +++ b/esphome/components/ms8607/ms8607.cpp @@ -281,9 +281,8 @@ void MS8607Component::request_read_temperature_() { return; } - auto f = std::bind(&MS8607Component::read_temperature_, this); // datasheet says 17.2ms max conversion time at OSR 8192 - this->set_timeout("temperature", 20, f); + this->set_timeout("temperature", 20, [this]() { this->read_temperature_(); }); } void MS8607Component::read_temperature_() { @@ -303,9 +302,8 @@ void MS8607Component::request_read_pressure_(uint32_t d2_raw_temperature) { return; } - auto f = std::bind(&MS8607Component::read_pressure_, this, d2_raw_temperature); // datasheet says 17.2ms max conversion time at OSR 8192 - this->set_timeout("pressure", 20, f); + this->set_timeout("pressure", 20, [this, d2_raw_temperature]() { this->read_pressure_(d2_raw_temperature); }); } void MS8607Component::read_pressure_(uint32_t d2_raw_temperature) { @@ -325,9 +323,8 @@ void MS8607Component::request_read_humidity_(float temperature_float) { return; } - auto f = std::bind(&MS8607Component::read_humidity_, this, temperature_float); // datasheet says 15.89ms max conversion time at OSR 8192 - this->set_timeout("humidity", 20, f); + this->set_timeout("humidity", 20, [this, temperature_float]() { this->read_humidity_(temperature_float); }); } void MS8607Component::read_humidity_(float temperature_float) { diff --git a/esphome/components/sht4x/sht4x.cpp b/esphome/components/sht4x/sht4x.cpp index 42be326202..bf23e42e66 100644 --- a/esphome/components/sht4x/sht4x.cpp +++ b/esphome/components/sht4x/sht4x.cpp @@ -63,7 +63,7 @@ void SHT4XComponent::setup() { } ESP_LOGD(TAG, "Heater command: %x", this->heater_command_); - this->set_interval(heater_interval, std::bind(&SHT4XComponent::start_heater_, this)); + this->set_interval(heater_interval, [this]() { this->start_heater_(); }); } } diff --git a/esphome/components/sprinkler/sprinkler.cpp b/esphome/components/sprinkler/sprinkler.cpp index d1f7452054..0802cdec8e 100644 --- a/esphome/components/sprinkler/sprinkler.cpp +++ b/esphome/components/sprinkler/sprinkler.cpp @@ -335,8 +335,8 @@ Sprinkler::Sprinkler(const char *name) : name_(name) { // The `name` is stored for dump_config logging this->timer_.init(2); // Timer names only need to be unique within this component instance - this->timer_.push_back({"sm", false, 0, 0, std::bind(&Sprinkler::sm_timer_callback_, this)}); - this->timer_.push_back({"vs", false, 0, 0, std::bind(&Sprinkler::valve_selection_callback_, this)}); + this->timer_.push_back({"sm", false, 0, 0, [this]() { this->sm_timer_callback_(); }}); + this->timer_.push_back({"vs", false, 0, 0, [this]() { this->valve_selection_callback_(); }}); } void Sprinkler::setup() {