mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
Fix clang-tidy: add braces around if statements, extract ensure helper
This commit is contained in:
@@ -132,15 +132,10 @@ class Fan : public EntityBase {
|
||||
|
||||
/// Set the supported preset modes (stored on Fan, referenced by FanTraits via pointer).
|
||||
void set_supported_preset_modes(std::initializer_list<const char *> preset_modes) {
|
||||
if (!this->supported_preset_modes_)
|
||||
this->supported_preset_modes_ =
|
||||
new std::vector<const char *>(); // NOLINT - intentional leak, entity lives forever
|
||||
*this->supported_preset_modes_ = preset_modes;
|
||||
this->ensure_preset_modes_().assign(preset_modes.begin(), preset_modes.end());
|
||||
}
|
||||
void set_supported_preset_modes(const std::vector<const char *> &preset_modes) {
|
||||
if (!this->supported_preset_modes_)
|
||||
this->supported_preset_modes_ = new std::vector<const char *>(); // NOLINT
|
||||
*this->supported_preset_modes_ = preset_modes;
|
||||
this->ensure_preset_modes_() = preset_modes;
|
||||
}
|
||||
|
||||
/// Set the restore mode of this fan.
|
||||
@@ -184,7 +179,14 @@ class Fan : public EntityBase {
|
||||
ESPPreferenceObject rtc_;
|
||||
FanRestoreMode restore_mode_;
|
||||
|
||||
/// Preset mode storage — allocated on first use, never freed (entity lives forever).
|
||||
/// Lazy-allocate preset modes vector (never freed — entity lives forever).
|
||||
std::vector<const char *> &ensure_preset_modes_() {
|
||||
if (!this->supported_preset_modes_) {
|
||||
this->supported_preset_modes_ = new std::vector<const char *>(); // NOLINT
|
||||
}
|
||||
return *this->supported_preset_modes_;
|
||||
}
|
||||
|
||||
std::vector<const char *> *supported_preset_modes_{nullptr};
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user