[components] Define simple setters in the header (#22459)

This commit is contained in:
J. Nick Koston authored and GitHub committed 2026-11-09 09:18:46 -05:00
1 parent 86442c8816
commit d9cac9a88f
24 files changed
+35 -92

No files matched your search

@@ -141,7 +141,7 @@ class DeepSleepComponent final : public Component {
*/
void set_wakeup_pin(InternalGPIOPin *pin) { this->wakeup_pin_ = pin; }
void set_wakeup_pin_mode(WakeupPinMode wakeup_pin_mode);
void set_wakeup_pin_mode(WakeupPinMode wakeup_pin_mode) { this->wakeup_pin_mode_ = wakeup_pin_mode; }
#endif // USE_ESP32
#if defined(USE_BK72XX)
@@ -153,7 +153,7 @@ class DeepSleepComponent final : public Component {
#if defined(USE_ESP32)
#if SOC_PM_SUPPORT_EXT1_WAKEUP
void set_ext1_wakeup(Ext1Wakeup ext1_wakeup);
void set_ext1_wakeup(Ext1Wakeup ext1_wakeup) { this->ext1_wakeup_ = ext1_wakeup; }
#endif
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
@@ -162,7 +162,9 @@ class DeepSleepComponent final : public Component {
// Set the duration in ms for how long the code should run before entering
// deep sleep mode, according to the cause the ESP32 has woken.
void set_run_duration(WakeupCauseToRunDuration wakeup_cause_to_run_duration);
void set_run_duration(WakeupCauseToRunDuration wakeup_cause_to_run_duration) {
this->wakeup_cause_to_run_duration_ = wakeup_cause_to_run_duration;
}
#endif // USE_ESP32
/// Set a duration in ms for how long the code should run before entering deep sleep mode.
@@ -68,18 +68,6 @@ optional<uint32_t> DeepSleepComponent::get_run_duration_() const {
return this->run_duration_;
}
void DeepSleepComponent::set_wakeup_pin_mode(WakeupPinMode wakeup_pin_mode) {
this->wakeup_pin_mode_ = wakeup_pin_mode;
}
#if SOC_PM_SUPPORT_EXT1_WAKEUP
void DeepSleepComponent::set_ext1_wakeup(Ext1Wakeup ext1_wakeup) { this->ext1_wakeup_ = ext1_wakeup; }
#endif
void DeepSleepComponent::set_run_duration(WakeupCauseToRunDuration wakeup_cause_to_run_duration) {
wakeup_cause_to_run_duration_ = wakeup_cause_to_run_duration;
}
void DeepSleepComponent::dump_config_platform_() {
if (wakeup_pin_ != nullptr) {
LOG_PIN(" Wakeup Pin: ", this->wakeup_pin_);
-3
View File
@@ -15,7 +15,6 @@ ESPHOME_LOG_TAG(TAG, "display");
void Display::fill(Color color) { this->filled_rectangle(0, 0, this->get_width(), this->get_height(), color); }
void Display::clear() { this->fill(COLOR_OFF); }
void Display::set_rotation(DisplayRotation rotation) { this->rotation_ = rotation; }
void HOT Display::line(int x1, int y1, int x2, int y2, Color color) {
const int32_t dx = abs(x2 - x1), sx = x1 < x2 ? 1 : -1;
@@ -716,8 +715,6 @@ void Display::printf(int x, int y, BaseFont *font, const char *format, ...) {
va_end(arg);
}
void Display::set_writer(display_writer_t &&writer) { this->writer_ = writer; }
void Display::set_pages(std::vector<DisplayPage *> pages) {
if (pages.empty())
return;
+2 -2
View File
@@ -726,7 +726,7 @@ class Display : public PollingComponent {
int *height);
/// Internal method to set the display writer lambda.
void set_writer(display_writer_t &&writer);
void set_writer(display_writer_t &&writer) { this->writer_ = writer; }
void show_page(DisplayPage *page);
void show_next_page();
@@ -743,7 +743,7 @@ class Display : public PollingComponent {
#endif
/// Internal method to set the display rotation with.
virtual void set_rotation(DisplayRotation rotation);
virtual void set_rotation(DisplayRotation rotation) { this->rotation_ = rotation; }
// Internal method to set display auto clearing.
void set_auto_clear(bool auto_clear_enabled) { this->auto_clear_enabled_ = auto_clear_enabled; }
@@ -359,9 +359,6 @@ void ESP32Camera::set_data_pins(std::array<uint8_t, 8> pins) {
this->config_.pin_d6 = pins[6];
this->config_.pin_d7 = pins[7];
}
void ESP32Camera::set_vsync_pin(uint8_t pin) { this->config_.pin_vsync = pin; }
void ESP32Camera::set_href_pin(uint8_t pin) { this->config_.pin_href = pin; }
void ESP32Camera::set_pixel_clock_pin(uint8_t pin) { this->config_.pin_pclk = pin; }
void ESP32Camera::set_external_clock(uint8_t pin, uint32_t frequency) {
this->config_.pin_xclk = pin;
this->config_.xclk_freq_hz = frequency;
@@ -377,8 +374,6 @@ void ESP32Camera::set_i2c_id(i2c::InternalI2CBus *i2c_bus) {
this->config_.pin_sccb_scl = -1;
}
#endif // USE_I2C
void ESP32Camera::set_reset_pin(uint8_t pin) { this->config_.pin_reset = pin; }
void ESP32Camera::set_power_down_pin(uint8_t pin) { this->config_.pin_pwdn = pin; }
/* set image parameters */
void ESP32Camera::set_frame_size(ESP32CameraFrameSize size) {
@@ -470,27 +465,16 @@ void ESP32Camera::set_pixel_format(ESP32CameraPixelFormat format) {
break;
}
}
void ESP32Camera::set_jpeg_quality(uint8_t quality) { this->config_.jpeg_quality = quality; }
/* set exposure parameters */
/* set gains parameters */
/* set white balance */
/* set test mode */
/* set fps */
void ESP32Camera::set_max_update_interval(uint32_t max_update_interval) {
this->max_update_interval_ = max_update_interval;
}
void ESP32Camera::set_idle_update_interval(uint32_t idle_update_interval) {
this->idle_update_interval_ = idle_update_interval;
}
/* set frame buffer parameters */
void ESP32Camera::set_frame_buffer_mode(camera_grab_mode_t mode) { this->config_.grab_mode = mode; }
void ESP32Camera::set_frame_buffer_count(uint8_t fb_count) {
this->config_.fb_count = fb_count;
this->set_frame_buffer_mode(fb_count > 1 ? CAMERA_GRAB_LATEST : CAMERA_GRAB_WHEN_EMPTY);
}
void ESP32Camera::set_frame_buffer_location(camera_fb_location_t fb_location) {
this->config_.fb_location = fb_location;
}
/* ---------------- public API (specific) ---------------- */
void ESP32Camera::start_stream(camera::CameraRequester requester) {
+10 -10
View File
@@ -135,20 +135,20 @@ class ESP32Camera final : public camera::Camera {
/* setters */
/* -- pin assignment */
void set_data_pins(std::array<uint8_t, 8> pins);
void set_vsync_pin(uint8_t pin);
void set_href_pin(uint8_t pin);
void set_pixel_clock_pin(uint8_t pin);
void set_vsync_pin(uint8_t pin) { this->config_.pin_vsync = pin; }
void set_href_pin(uint8_t pin) { this->config_.pin_href = pin; }
void set_pixel_clock_pin(uint8_t pin) { this->config_.pin_pclk = pin; }
void set_external_clock(uint8_t pin, uint32_t frequency);
void set_i2c_pins(uint8_t sda, uint8_t scl);
#ifdef USE_I2C
void set_i2c_id(i2c::InternalI2CBus *i2c_bus);
#endif // USE_I2C
void set_reset_pin(uint8_t pin);
void set_power_down_pin(uint8_t pin);
void set_reset_pin(uint8_t pin) { this->config_.pin_reset = pin; }
void set_power_down_pin(uint8_t pin) { this->config_.pin_pwdn = pin; }
/* -- image */
void set_pixel_format(ESP32CameraPixelFormat format);
void set_frame_size(ESP32CameraFrameSize size);
void set_jpeg_quality(uint8_t quality);
void set_jpeg_quality(uint8_t quality) { this->config_.jpeg_quality = quality; }
void set_vertical_flip(bool vertical_flip) { this->vertical_flip_ = vertical_flip; }
void set_horizontal_mirror(bool horizontal_mirror) { this->horizontal_mirror_ = horizontal_mirror; }
void set_contrast(int contrast) { this->contrast_ = contrast; }
@@ -169,12 +169,12 @@ class ESP32Camera final : public camera::Camera {
/* -- test */
void set_test_pattern(bool test_pattern) { this->test_pattern_ = test_pattern; }
/* -- framerates */
void set_max_update_interval(uint32_t max_update_interval);
void set_idle_update_interval(uint32_t idle_update_interval);
void set_max_update_interval(uint32_t max_update_interval) { this->max_update_interval_ = max_update_interval; }
void set_idle_update_interval(uint32_t idle_update_interval) { this->idle_update_interval_ = idle_update_interval; }
/* -- frame buffer */
void set_frame_buffer_mode(camera_grab_mode_t mode);
void set_frame_buffer_mode(camera_grab_mode_t mode) { this->config_.grab_mode = mode; }
void set_frame_buffer_count(uint8_t fb_count);
void set_frame_buffer_location(camera_fb_location_t fb_location);
void set_frame_buffer_location(camera_fb_location_t fb_location) { this->config_.fb_location = fb_location; }
#ifdef USE_ESP32_CAMERA_CAPTURE
/* -- single image capture */
void set_capture_delay(uint16_t capture_delay) { this->capture_delay_ = capture_delay; }
@@ -57,9 +57,6 @@ void GraphicalDisplayMenu::dump_config() {
}
}
void GraphicalDisplayMenu::set_foreground_color(Color foreground_color) { this->foreground_color_ = foreground_color; }
void GraphicalDisplayMenu::set_background_color(Color background_color) { this->background_color_ = background_color; }
void GraphicalDisplayMenu::on_before_show() {
if (this->display_ != nullptr) {
this->previous_display_page_ = this->display_->get_active_page();
@@ -41,8 +41,8 @@ class GraphicalDisplayMenu final : public display_menu_base::DisplayMenuComponen
void set_display(display::Display *display) { this->display_ = display; }
void set_font(display::BaseFont *font) { this->font_ = font; }
template<typename V> void set_menu_item_value(V menu_item_value) { this->menu_item_value_ = menu_item_value; }
void set_foreground_color(Color foreground_color);
void set_background_color(Color background_color);
void set_foreground_color(Color foreground_color) { this->foreground_color_ = foreground_color; }
void set_background_color(Color background_color) { this->background_color_ = background_color; }
template<typename F> void add_on_redraw_callback(F &&cb) { this->on_redraw_callbacks_.add(std::forward<F>(cb)); }
-1
View File
@@ -217,7 +217,6 @@ uint8_t MAX7219Component::printf(const char *format, ...) {
return this->print(buffer);
return 0;
}
void MAX7219Component::set_writer(max7219_writer_t &&writer) { this->writer_ = writer; }
void MAX7219Component::set_intensity(uint8_t intensity) {
intensity &= 0xF;
if (intensity != this->intensity_) {
+1 -1
View File
@@ -19,7 +19,7 @@ class MAX7219Component final : public PollingComponent,
/// `buffer` holds 8 bytes per chip, a static array from code generation
MAX7219Component(uint8_t num_chips, uint8_t *buffer) : num_chips_(num_chips), buffer_(buffer) {}
void set_writer(max7219_writer_t &&writer);
void set_writer(max7219_writer_t &&writer) { this->writer_ = writer; }
void setup() override;
-4
View File
@@ -884,9 +884,7 @@ void MQTTClientComponent::disable_log_message() { this->log_message_.topic = "";
bool MQTTClientComponent::is_log_message_enabled() const { return !this->log_message_.topic.empty(); }
void MQTTClientComponent::register_mqtt_component(MQTTComponent *component) { this->children_.push_back(component); }
void MQTTClientComponent::set_keep_alive(uint16_t keep_alive_s) { this->mqtt_backend_.set_keep_alive(keep_alive_s); }
void MQTTClientComponent::set_log_message_template(MQTTMessage &&message) { this->log_message_ = std::move(message); }
const MQTTDiscoveryInfo &MQTTClientComponent::get_discovery_info() const { return this->discovery_info_; }
void MQTTClientComponent::set_topic_prefix(std::string topic_prefix) { this->topic_prefix_ = std::move(topic_prefix); }
const std::string &MQTTClientComponent::get_topic_prefix() const { return this->topic_prefix_; }
void MQTTClientComponent::disable_birth_message() {
this->birth_message_.topic = "";
@@ -919,8 +917,6 @@ void MQTTClientComponent::set_birth_message(MQTTMessage &&message) {
this->recalculate_availability_();
}
void MQTTClientComponent::set_shutdown_message(MQTTMessage &&message) { this->shutdown_message_ = std::move(message); }
void MQTTClientComponent::set_discovery_info(std::string &&prefix, MQTTDiscoveryUniqueIdGenerator unique_id_generator,
MQTTDiscoveryObjectIdGenerator object_id_generator, bool retain,
bool discover_ip, bool clean) {
+3 -3
View File
@@ -160,7 +160,7 @@ class MQTTClientComponent final : public Component {
/// Remove the birth message.
void disable_birth_message();
void set_shutdown_message(MQTTMessage &&message);
void set_shutdown_message(MQTTMessage &&message) { this->shutdown_message_ = std::move(message); }
void disable_shutdown_message();
/// Set the keep alive time in seconds, every 0.7*keep_alive a ping will be sent.
@@ -204,12 +204,12 @@ class MQTTClientComponent final : public Component {
*
* @param topic_prefix The topic prefix. The last "/" is appended automatically.
*/
void set_topic_prefix(std::string topic_prefix);
void set_topic_prefix(std::string topic_prefix) { this->topic_prefix_ = std::move(topic_prefix); }
/// Get the topic prefix of this device, using default if necessary
const std::string &get_topic_prefix() const;
/// Manually set the topic used for logging.
void set_log_message_template(MQTTMessage &&message);
void set_log_message_template(MQTTMessage &&message) { this->log_message_ = std::move(message); }
void set_log_level(int level) { this->log_level_ = level; }
/// Get the topic used for logging. Defaults to "<topic_prefix>/debug" and the value is cached for speed.
void disable_log_message();
@@ -50,12 +50,6 @@ void log_mqtt_component(const char *tag, MQTTComponent *obj, bool state_topic, b
}
}
void MQTTComponent::set_qos(uint8_t qos) { this->qos_ = qos; }
void MQTTComponent::set_subscribe_qos(uint8_t qos) { this->subscribe_qos_ = qos; }
void MQTTComponent::set_retain(bool retain) { this->retain_ = retain; }
StringRef MQTTComponent::get_discovery_topic_to_(std::span<char, MQTT_DISCOVERY_TOPIC_MAX_LEN> buf,
const MQTTDiscoveryInfo &discovery_info) const {
char sanitized_name[ESPHOME_DEVICE_NAME_MAX_LEN + 1];
@@ -368,7 +362,6 @@ MQTTComponent::MQTTComponent() = default;
float MQTTComponent::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; }
void MQTTComponent::disable_discovery() { this->discovery_enabled_ = false; }
void MQTTComponent::set_command_retain(bool command_retain) { this->command_retain_ = command_retain; }
void MQTTComponent::set_availability(std::string topic, std::string payload_available,
std::string payload_not_available) {
+4 -4
View File
@@ -104,11 +104,11 @@ class MQTTComponent : public Component {
bool is_internal() const { return this->is_internal_; }
/// Set QOS for state messages.
void set_qos(uint8_t qos);
void set_qos(uint8_t qos) { this->qos_ = qos; }
uint8_t get_qos() const { return this->qos_; }
/// Set whether state message should be retained.
void set_retain(bool retain);
void set_retain(bool retain) { this->retain_ = retain; }
bool get_retain() const { return this->retain_; }
/// Disable discovery. Sets friendly name to "".
@@ -116,7 +116,7 @@ class MQTTComponent : public Component {
bool is_discovery_enabled() const;
/// Set the QOS for subscribe messages (used in discovery).
void set_subscribe_qos(uint8_t qos);
void set_subscribe_qos(uint8_t qos) { this->subscribe_qos_ = qos; }
/// Override this method to return the component type (e.g. "light", "sensor", ...)
virtual const char *component_type() const = 0;
@@ -130,7 +130,7 @@ class MQTTComponent : public Component {
this->custom_command_topic_ = std::forward<T>(custom_command_topic);
}
/// Set whether command message should be retained.
void set_command_retain(bool command_retain);
void set_command_retain(bool command_retain) { this->command_retain_ = command_retain; }
/// MQTT_COMPONENT setup priority.
float get_setup_priority() const override;
-2
View File
@@ -1429,8 +1429,6 @@ void Nextion::check_pending_waveform_() {
}
#endif // USE_NEXTION_WAVEFORM
void Nextion::set_writer(const nextion_writer_t &writer) { this->writer_ = writer; }
bool Nextion::is_updating() { return this->connection_state_.is_updating_; }
} // namespace esphome::nextion
+1 -1
View File
@@ -1059,7 +1059,7 @@ class Nextion final : public NextionBase, public PollingComponent, public uart::
void set_brightness(float brightness) { this->brightness_ = brightness; }
void update() override;
void loop() override;
void set_writer(const nextion_writer_t &writer);
void set_writer(const nextion_writer_t &writer) { this->writer_ = writer; }
// This function has been deprecated
void set_wait_for_ack(bool wait_for_ack);
@@ -32,8 +32,6 @@ void NfcTagBinarySensor::set_tag_name(const char *str) {
this->match_tag_name_ = true;
}
void NfcTagBinarySensor::set_uid(const NfcTagUid &uid) { this->uid_ = uid; }
bool NfcTagBinarySensor::tag_match_ndef_string(const std::shared_ptr<NdefMessage> &msg) {
for (const auto &record : msg->get_records()) {
if (record->get_payload().find(this->match_string_.c_str(), 0, this->match_string_.size()) != std::string::npos) {
@@ -17,7 +17,7 @@ class NfcTagBinarySensor final : public binary_sensor::BinarySensor, public Comp
// Both keep the pointer; the string must outlive the sensor (codegen passes a literal)
void set_ndef_match_string(const char *str);
void set_tag_name(const char *str);
void set_uid(const NfcTagUid &uid);
void set_uid(const NfcTagUid &uid) { this->uid_ = uid; }
bool tag_match_ndef_string(const std::shared_ptr<NdefMessage> &msg);
bool tag_match_tag_name(const std::shared_ptr<NdefMessage> &msg);
@@ -234,11 +234,4 @@ void RotaryEncoderSensor::loop() {
}
}
void RotaryEncoderSensor::set_restore_mode(RotaryEncoderRestoreMode restore_mode) {
this->restore_mode_ = restore_mode;
}
void RotaryEncoderSensor::set_resolution(RotaryEncoderResolution mode) { this->store_.resolution = mode; }
void RotaryEncoderSensor::set_min_value(int32_t min_value) { this->store_.min_value = min_value; }
void RotaryEncoderSensor::set_max_value(int32_t max_value) { this->store_.max_value = max_value; }
} // namespace esphome::rotary_encoder
@@ -52,7 +52,7 @@ class RotaryEncoderSensor final : public sensor::Sensor, public Component {
*
* @param restore_mode The restore mode to use.
*/
void set_restore_mode(RotaryEncoderRestoreMode restore_mode);
void set_restore_mode(RotaryEncoderRestoreMode restore_mode) { this->restore_mode_ = restore_mode; }
/** Set the resolution of the rotary encoder.
*
@@ -61,7 +61,7 @@ class RotaryEncoderSensor final : public sensor::Sensor, public Component {
*
* @param mode The new mode of the encoder.
*/
void set_resolution(RotaryEncoderResolution mode);
void set_resolution(RotaryEncoderResolution mode) { this->store_.resolution = mode; }
/// Manually set the value of the counter.
void set_value(int value) {
@@ -70,8 +70,8 @@ class RotaryEncoderSensor final : public sensor::Sensor, public Component {
}
void set_reset_pin(GPIOPin *pin_i) { this->pin_i_ = pin_i; }
void set_min_value(int32_t min_value);
void set_max_value(int32_t max_value);
void set_min_value(int32_t min_value) { this->store_.min_value = min_value; }
void set_max_value(int32_t max_value) { this->store_.max_value = max_value; }
void set_publish_initial_value(bool publish_initial_value) { publish_initial_value_ = publish_initial_value; }
// ========== INTERNAL METHODS ==========
-1
View File
@@ -208,7 +208,6 @@ void ThrottleAverageFilter::initialize(Sensor *parent, Filter *next) {
// LambdaFilter
LambdaFilter::LambdaFilter(lambda_filter_t lambda_filter) : lambda_filter_(std::move(lambda_filter)) {}
const lambda_filter_t &LambdaFilter::get_lambda_filter() const { return this->lambda_filter_; }
void LambdaFilter::set_lambda_filter(const lambda_filter_t &lambda_filter) { this->lambda_filter_ = lambda_filter; }
optional<float> LambdaFilter::new_value(float value) {
auto it = this->lambda_filter_(value);
+1 -1
View File
@@ -288,7 +288,7 @@ class LambdaFilter : public Filter {
optional<float> new_value(float value) override;
const lambda_filter_t &get_lambda_filter() const;
void set_lambda_filter(const lambda_filter_t &lambda_filter);
void set_lambda_filter(const lambda_filter_t &lambda_filter) { this->lambda_filter_ = lambda_filter; }
protected:
lambda_filter_t lambda_filter_;
@@ -35,7 +35,6 @@ void Filter::initialize(TextSensor *parent, Filter *next) {
// LambdaFilter
LambdaFilter::LambdaFilter(lambda_filter_t lambda_filter) : lambda_filter_(std::move(lambda_filter)) {}
const lambda_filter_t &LambdaFilter::get_lambda_filter() const { return this->lambda_filter_; }
void LambdaFilter::set_lambda_filter(const lambda_filter_t &lambda_filter) { this->lambda_filter_ = lambda_filter; }
bool LambdaFilter::new_value(std::string &value) {
auto result = this->lambda_filter_(value);
+1 -1
View File
@@ -56,7 +56,7 @@ class LambdaFilter : public Filter {
bool new_value(std::string &value) override;
const lambda_filter_t &get_lambda_filter() const;
void set_lambda_filter(const lambda_filter_t &lambda_filter);
void set_lambda_filter(const lambda_filter_t &lambda_filter) { this->lambda_filter_ = lambda_filter; }
protected:
lambda_filter_t lambda_filter_;