Fix clang-tidy: add braces around if statements, extract ensure helper

This commit is contained in:
J. Nick Koston
2026-03-26 13:33:15 -10:00
parent 4ff0d30e07
commit 554d97ff04
+10 -8
View File
@@ -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: