mirror of
https://github.com/esphome/esphome.git
synced 2026-03-23 19:09:53 +08:00
[core] Replace std::bind with lambdas across 13 components (#14961)
This commit is contained in:
@@ -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_(); });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
@@ -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_() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
@@ -59,7 +59,7 @@ template<typename T> 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);
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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_(); });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user