diff --git a/esphome/components/canbus/canbus.h b/esphome/components/canbus/canbus.h index f7b84111bd..420125e1d3 100644 --- a/esphome/components/canbus/canbus.h +++ b/esphome/components/canbus/canbus.h @@ -91,10 +91,7 @@ class Canbus : public Component { * - rtr If this is a remote transmission request * - data The message data */ - void add_callback( - std::function &data)> callback) { - this->callback_manager_.add(std::move(callback)); - } + template void add_callback(F &&callback) { this->callback_manager_.add(std::forward(callback)); } protected: template friend class CanbusSendAction; diff --git a/esphome/components/rotary_encoder/rotary_encoder.h b/esphome/components/rotary_encoder/rotary_encoder.h index 9cba8680a0..4b776fe55e 100644 --- a/esphome/components/rotary_encoder/rotary_encoder.h +++ b/esphome/components/rotary_encoder/rotary_encoder.h @@ -90,7 +90,7 @@ class RotaryEncoderSensor : public sensor::Sensor, public Component { this->on_anticlockwise_callback_.add(std::forward(callback)); } - void register_listener(std::function listener) { this->listeners_.add(std::move(listener)); } + template void register_listener(F &&listener) { this->listeners_.add(std::forward(listener)); } protected: InternalGPIOPin *pin_a_; diff --git a/esphome/components/sdl/sdl_esphome.h b/esphome/components/sdl/sdl_esphome.h index bf5fde1428..c025e8ff6e 100644 --- a/esphome/components/sdl/sdl_esphome.h +++ b/esphome/components/sdl/sdl_esphome.h @@ -37,11 +37,11 @@ class Sdl : public display::Display { int get_height() override { return this->height_; } float get_setup_priority() const override { return setup_priority::HARDWARE; } void dump_config() override { LOG_DISPLAY("", "SDL", this); } - void add_key_listener(int32_t keycode, std::function &&callback) { + template void add_key_listener(int32_t keycode, F &&callback) { if (!this->key_callbacks_.count(keycode)) { this->key_callbacks_[keycode] = CallbackManager(); } - this->key_callbacks_[keycode].add(std::move(callback)); + this->key_callbacks_[keycode].add(std::forward(callback)); } int mouse_x{}; diff --git a/esphome/components/udp/udp_component.h b/esphome/components/udp/udp_component.h index 7fd6308065..fb0edf2ebd 100644 --- a/esphome/components/udp/udp_component.h +++ b/esphome/components/udp/udp_component.h @@ -28,9 +28,7 @@ class UDPComponent : public Component { void set_broadcast_port(uint16_t port) { this->broadcast_port_ = port; } void set_should_broadcast() { this->should_broadcast_ = true; } void set_should_listen() { this->should_listen_ = true; } - void add_listener(std::function)> &&listener) { - this->packet_listeners_.add(std::move(listener)); - } + template void add_listener(F &&listener) { this->packet_listeners_.add(std::forward(listener)); } void setup() override; void loop() override; void dump_config() override;