mirror of
https://github.com/esphome/esphome.git
synced 2026-03-23 05:13:03 +08:00
[core] Replace std::bind with placeholders to lambdas (#14962)
This commit is contained in:
@@ -242,7 +242,7 @@ void HaierClimateBase::setup() {
|
||||
this->last_request_timestamp_ = std::chrono::steady_clock::now();
|
||||
this->set_phase(ProtocolPhases::SENDING_INIT_1);
|
||||
this->haier_protocol_.set_default_timeout_handler(
|
||||
std::bind(&esphome::haier::HaierClimateBase::timeout_default_handler_, this, std::placeholders::_1));
|
||||
[this](haier_protocol::FrameType type) { return this->timeout_default_handler_(type); });
|
||||
this->set_handlers();
|
||||
this->initialization();
|
||||
}
|
||||
|
||||
@@ -301,32 +301,38 @@ void HonClimate::set_handlers() {
|
||||
// Set handlers
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::GET_DEVICE_VERSION,
|
||||
std::bind(&HonClimate::get_device_version_answer_handler_, this, std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3, std::placeholders::_4));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->get_device_version_answer_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::GET_DEVICE_ID,
|
||||
std::bind(&HonClimate::get_device_id_answer_handler_, this, std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3, std::placeholders::_4));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->get_device_id_answer_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::CONTROL,
|
||||
std::bind(&HonClimate::status_handler_, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
|
||||
std::placeholders::_4));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->status_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::GET_MANAGEMENT_INFORMATION,
|
||||
std::bind(&HonClimate::get_management_information_answer_handler_, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->get_management_information_answer_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::GET_ALARM_STATUS,
|
||||
std::bind(&HonClimate::get_alarm_status_answer_handler_, this, std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3, std::placeholders::_4));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->get_alarm_status_answer_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::REPORT_NETWORK_STATUS,
|
||||
std::bind(&HonClimate::report_network_status_answer_handler_, this, std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3, std::placeholders::_4));
|
||||
this->haier_protocol_.set_message_handler(
|
||||
haier_protocol::FrameType::ALARM_STATUS,
|
||||
std::bind(&HonClimate::alarm_status_message_handler_, this, std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->report_network_status_answer_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_message_handler(haier_protocol::FrameType::ALARM_STATUS,
|
||||
[this](haier_protocol::FrameType type, const uint8_t *data, size_t size) {
|
||||
return this->alarm_status_message_handler_(type, data, size);
|
||||
});
|
||||
}
|
||||
|
||||
void HonClimate::dump_config() {
|
||||
|
||||
@@ -106,18 +106,21 @@ void Smartair2Climate::set_handlers() {
|
||||
// Set handlers
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::GET_DEVICE_VERSION,
|
||||
std::bind(&Smartair2Climate::get_device_version_answer_handler_, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->get_device_version_answer_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::CONTROL,
|
||||
std::bind(&Smartair2Climate::status_handler_, this, std::placeholders::_1, std::placeholders::_2,
|
||||
std::placeholders::_3, std::placeholders::_4));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->status_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_answer_handler(
|
||||
haier_protocol::FrameType::REPORT_NETWORK_STATUS,
|
||||
std::bind(&Smartair2Climate::report_network_status_answer_handler_, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||
[this](haier_protocol::FrameType req, haier_protocol::FrameType msg, const uint8_t *data, size_t size) {
|
||||
return this->report_network_status_answer_handler_(req, msg, data, size);
|
||||
});
|
||||
this->haier_protocol_.set_default_timeout_handler(
|
||||
std::bind(&Smartair2Climate::messages_timeout_handler_with_cycle_for_init_, this, std::placeholders::_1));
|
||||
[this](haier_protocol::FrameType type) { return this->messages_timeout_handler_with_cycle_for_init_(type); });
|
||||
}
|
||||
|
||||
void Smartair2Climate::dump_config() {
|
||||
|
||||
@@ -55,15 +55,15 @@ void HomeassistantNumber::step_retrieved_(StringRef step) {
|
||||
}
|
||||
|
||||
void HomeassistantNumber::setup() {
|
||||
api::global_api_server->subscribe_home_assistant_state(
|
||||
this->entity_id_, nullptr, std::bind(&HomeassistantNumber::state_changed_, this, std::placeholders::_1));
|
||||
api::global_api_server->subscribe_home_assistant_state(this->entity_id_, nullptr,
|
||||
[this](StringRef state) { this->state_changed_(state); });
|
||||
|
||||
api::global_api_server->get_home_assistant_state(
|
||||
this->entity_id_, "min", std::bind(&HomeassistantNumber::min_retrieved_, this, std::placeholders::_1));
|
||||
api::global_api_server->get_home_assistant_state(
|
||||
this->entity_id_, "max", std::bind(&HomeassistantNumber::max_retrieved_, this, std::placeholders::_1));
|
||||
api::global_api_server->get_home_assistant_state(
|
||||
this->entity_id_, "step", std::bind(&HomeassistantNumber::step_retrieved_, this, std::placeholders::_1));
|
||||
api::global_api_server->get_home_assistant_state(this->entity_id_, "min",
|
||||
[this](StringRef min) { this->min_retrieved_(min); });
|
||||
api::global_api_server->get_home_assistant_state(this->entity_id_, "max",
|
||||
[this](StringRef max) { this->max_retrieved_(max); });
|
||||
api::global_api_server->get_home_assistant_state(this->entity_id_, "step",
|
||||
[this](StringRef step) { this->step_retrieved_(step); });
|
||||
}
|
||||
|
||||
void HomeassistantNumber::dump_config() {
|
||||
|
||||
@@ -629,8 +629,8 @@ void WiFiComponent::wifi_pre_setup_() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto f = std::bind(&WiFiComponent::wifi_event_callback_, this, std::placeholders::_1, std::placeholders::_2);
|
||||
WiFi.onEvent(f);
|
||||
WiFi.onEvent(
|
||||
[this](arduino_event_id_t event, arduino_event_info_t info) { this->wifi_event_callback_(event, info); });
|
||||
// Make sure WiFi is in clean state before anything starts
|
||||
this->wifi_mode_(false, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user