[code-quality] fix readability-braces-around-statements (#7273)

This commit is contained in:
tomaszduda23 2024-08-14 04:14:29 +02:00 committed by GitHub
parent 56e05998ef
commit 4cb174585c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 108 additions and 65 deletions

View file

@ -18,11 +18,12 @@ class BinaryLightOutput : public light::LightOutput {
void write_state(light::LightState *state) override {
bool binary;
state->current_values_as_binary(&binary);
if (binary)
if (binary) {
this->output_->turn_on();
else
} else {
this->output_->turn_off();
}
}
protected:
output::BinaryOutput *output_;

View file

@ -16,12 +16,13 @@ class DemoSensor : public sensor::Sensor, public PollingComponent {
float base = std::isnan(this->state) ? 0.0f : this->state;
this->publish_state(base + val * 10);
} else {
if (val < 0.1)
if (val < 0.1) {
this->publish_state(NAN);
else
} else {
this->publish_state(val * 100);
}
}
}
};
} // namespace demo

View file

@ -114,10 +114,11 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
if (now - this->last_add_ < this->add_led_interval_)
return;
this->last_add_ = now;
if (this->reverse_)
if (this->reverse_) {
it.shift_left(1);
else
} else {
it.shift_right(1);
}
const AddressableColorWipeEffectColor &color = this->colors_[this->at_color_];
Color esp_color = Color(color.r, color.g, color.b, color.w);
if (color.gradient) {
@ -127,10 +128,11 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
uint8_t gradient = 255 * ((float) this->leds_added_ / color.num_leds);
esp_color = esp_color.gradient(next_esp_color, gradient);
}
if (this->reverse_)
if (this->reverse_) {
it[-1] = esp_color;
else
} else {
it[0] = esp_color;
}
if (++this->leds_added_ >= color.num_leds) {
this->leds_added_ = 0;
this->at_color_ = (this->at_color_ + 1) % this->colors_.size();
@ -207,10 +209,11 @@ class AddressableTwinkleEffect : public AddressableLightEffect {
const uint8_t sine = half_sin8(view.get_effect_data());
view = current_color * sine;
const uint8_t new_pos = view.get_effect_data() + pos_add;
if (new_pos < view.get_effect_data())
if (new_pos < view.get_effect_data()) {
view.set_effect_data(0);
else
} else {
view.set_effect_data(new_pos);
}
} else {
view = Color::BLACK;
}
@ -254,10 +257,11 @@ class AddressableRandomTwinkleEffect : public AddressableLightEffect {
view = Color(((color >> 2) & 1) * sine, ((color >> 1) & 1) * sine, ((color >> 0) & 1) * sine);
}
const uint8_t new_x = x + pos_add;
if (new_x > 0b11111)
if (new_x > 0b11111) {
view.set_effect_data(0);
else
} else {
view.set_effect_data((new_x << 3) | color);
}
} else {
view = Color(0, 0, 0, 0);
}

View file

@ -20,11 +20,12 @@ class LVGLNumber : public number::Number {
protected:
void control(float value) override {
if (this->control_lambda_ != nullptr)
if (this->control_lambda_ != nullptr) {
this->control_lambda_(value);
else
} else {
this->initial_state_ = value;
}
}
std::function<void(float)> control_lambda_{};
optional<float> initial_state_{};
};

View file

@ -20,11 +20,12 @@ class LVGLSwitch : public switch_::Switch {
protected:
void write_state(bool value) override {
if (this->state_lambda_ != nullptr)
if (this->state_lambda_ != nullptr) {
this->state_lambda_(value);
else
} else {
this->initial_state_ = value;
}
}
std::function<void(bool)> state_lambda_{};
optional<bool> initial_state_{};
};

View file

@ -20,11 +20,12 @@ class LVGLText : public text::Text {
protected:
void control(const std::string &value) override {
if (this->control_lambda_ != nullptr)
if (this->control_lambda_ != nullptr) {
this->control_lambda_(value);
else
} else {
this->initial_state_ = value;
}
}
std::function<void(const std::string)> control_lambda_{};
optional<std::string> initial_state_{};
};

View file

@ -23,10 +23,11 @@ class RGBCTLightOutput : public light::LightOutput {
light::LightTraits get_traits() override {
auto traits = light::LightTraits();
if (this->color_interlock_)
if (this->color_interlock_) {
traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::COLOR_TEMPERATURE});
else
} else {
traits.set_supported_color_modes({light::ColorMode::RGB_COLOR_TEMPERATURE, light::ColorMode::COLOR_TEMPERATURE});
}
traits.set_min_mireds(this->cold_white_temperature_);
traits.set_max_mireds(this->warm_white_temperature_);
return traits;

View file

@ -16,10 +16,11 @@ class RGBWLightOutput : public light::LightOutput {
void set_color_interlock(bool color_interlock) { color_interlock_ = color_interlock; }
light::LightTraits get_traits() override {
auto traits = light::LightTraits();
if (this->color_interlock_)
if (this->color_interlock_) {
traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::WHITE});
else
} else {
traits.set_supported_color_modes({light::ColorMode::RGB_WHITE});
}
return traits;
}
void write_state(light::LightState *state) override {

View file

@ -20,10 +20,11 @@ class RGBWWLightOutput : public light::LightOutput {
void set_color_interlock(bool color_interlock) { color_interlock_ = color_interlock; }
light::LightTraits get_traits() override {
auto traits = light::LightTraits();
if (this->color_interlock_)
if (this->color_interlock_) {
traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::COLD_WARM_WHITE});
else
} else {
traits.set_supported_color_modes({light::ColorMode::RGB_COLD_WARM_WHITE});
}
traits.set_min_mireds(this->cold_white_temperature_);
traits.set_max_mireds(this->warm_white_temperature_);
return traits;

View file

@ -46,11 +46,12 @@ class SpiLedStrip : public light::AddressableLight,
void dump_config() override {
esph_log_config(TAG, "SPI LED Strip:");
esph_log_config(TAG, " LEDs: %d", this->num_leds_);
if (this->data_rate_ >= spi::DATA_RATE_1MHZ)
if (this->data_rate_ >= spi::DATA_RATE_1MHZ) {
esph_log_config(TAG, " Data rate: %uMHz", (unsigned) (this->data_rate_ / 1000000));
else
} else {
esph_log_config(TAG, " Data rate: %ukHz", (unsigned) (this->data_rate_ / 1000));
}
}
void write_state(light::LightState *state) override {
if (this->is_failed())

View file

@ -246,162 +246,180 @@ class Application {
#ifdef USE_BINARY_SENSOR
const std::vector<binary_sensor::BinarySensor *> &get_binary_sensors() { return this->binary_sensors_; }
binary_sensor::BinarySensor *get_binary_sensor_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->binary_sensors_)
for (auto *obj : this->binary_sensors_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_SWITCH
const std::vector<switch_::Switch *> &get_switches() { return this->switches_; }
switch_::Switch *get_switch_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->switches_)
for (auto *obj : this->switches_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_BUTTON
const std::vector<button::Button *> &get_buttons() { return this->buttons_; }
button::Button *get_button_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->buttons_)
for (auto *obj : this->buttons_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_SENSOR
const std::vector<sensor::Sensor *> &get_sensors() { return this->sensors_; }
sensor::Sensor *get_sensor_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->sensors_)
for (auto *obj : this->sensors_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_TEXT_SENSOR
const std::vector<text_sensor::TextSensor *> &get_text_sensors() { return this->text_sensors_; }
text_sensor::TextSensor *get_text_sensor_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->text_sensors_)
for (auto *obj : this->text_sensors_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_FAN
const std::vector<fan::Fan *> &get_fans() { return this->fans_; }
fan::Fan *get_fan_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->fans_)
for (auto *obj : this->fans_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_COVER
const std::vector<cover::Cover *> &get_covers() { return this->covers_; }
cover::Cover *get_cover_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->covers_)
for (auto *obj : this->covers_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_LIGHT
const std::vector<light::LightState *> &get_lights() { return this->lights_; }
light::LightState *get_light_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->lights_)
for (auto *obj : this->lights_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_CLIMATE
const std::vector<climate::Climate *> &get_climates() { return this->climates_; }
climate::Climate *get_climate_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->climates_)
for (auto *obj : this->climates_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_NUMBER
const std::vector<number::Number *> &get_numbers() { return this->numbers_; }
number::Number *get_number_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->numbers_)
for (auto *obj : this->numbers_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_DATETIME_DATE
const std::vector<datetime::DateEntity *> &get_dates() { return this->dates_; }
datetime::DateEntity *get_date_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->dates_)
for (auto *obj : this->dates_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_DATETIME_TIME
const std::vector<datetime::TimeEntity *> &get_times() { return this->times_; }
datetime::TimeEntity *get_time_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->times_)
for (auto *obj : this->times_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_DATETIME_DATETIME
const std::vector<datetime::DateTimeEntity *> &get_datetimes() { return this->datetimes_; }
datetime::DateTimeEntity *get_datetime_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->datetimes_)
for (auto *obj : this->datetimes_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_TEXT
const std::vector<text::Text *> &get_texts() { return this->texts_; }
text::Text *get_text_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->texts_)
for (auto *obj : this->texts_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_SELECT
const std::vector<select::Select *> &get_selects() { return this->selects_; }
select::Select *get_select_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->selects_)
for (auto *obj : this->selects_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_LOCK
const std::vector<lock::Lock *> &get_locks() { return this->locks_; }
lock::Lock *get_lock_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->locks_)
for (auto *obj : this->locks_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_VALVE
const std::vector<valve::Valve *> &get_valves() { return this->valves_; }
valve::Valve *get_valve_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->valves_)
for (auto *obj : this->valves_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
#ifdef USE_MEDIA_PLAYER
const std::vector<media_player::MediaPlayer *> &get_media_players() { return this->media_players_; }
media_player::MediaPlayer *get_media_player_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->media_players_)
for (auto *obj : this->media_players_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
@ -411,9 +429,10 @@ class Application {
return this->alarm_control_panels_;
}
alarm_control_panel::AlarmControlPanel *get_alarm_control_panel_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->alarm_control_panels_)
for (auto *obj : this->alarm_control_panels_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
@ -421,9 +440,10 @@ class Application {
#ifdef USE_EVENT
const std::vector<event::Event *> &get_events() { return this->events_; }
event::Event *get_event_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->events_)
for (auto *obj : this->events_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif
@ -431,9 +451,10 @@ class Application {
#ifdef USE_UPDATE
const std::vector<update::UpdateEntity *> &get_updates() { return this->updates_; }
update::UpdateEntity *get_update_by_key(uint32_t key, bool include_internal = false) {
for (auto *obj : this->updates_)
for (auto *obj : this->updates_) {
if (obj->get_object_id_hash() == key && (include_internal || !obj->is_internal()))
return obj;
}
return nullptr;
}
#endif

View file

@ -278,10 +278,11 @@ template<typename... Ts> class RepeatAction : public Action<Ts...> {
this->then_.add_actions(actions);
this->then_.add_action(new LambdaAction<uint32_t, Ts...>([this](uint32_t iteration, Ts... x) {
iteration++;
if (iteration >= this->count_.value(x...))
if (iteration >= this->count_.value(x...)) {
this->play_next_tuple_(this->var_);
else
} else {
this->then_.play(iteration, x...);
}
}));
}

View file

@ -85,22 +85,26 @@ struct Color {
}
inline Color operator+(const Color &add) const ESPHOME_ALWAYS_INLINE {
Color ret;
if (uint8_t(add.r + this->r) < this->r)
if (uint8_t(add.r + this->r) < this->r) {
ret.r = 255;
else
} else {
ret.r = this->r + add.r;
if (uint8_t(add.g + this->g) < this->g)
}
if (uint8_t(add.g + this->g) < this->g) {
ret.g = 255;
else
} else {
ret.g = this->g + add.g;
if (uint8_t(add.b + this->b) < this->b)
}
if (uint8_t(add.b + this->b) < this->b) {
ret.b = 255;
else
} else {
ret.b = this->b + add.b;
if (uint8_t(add.w + this->w) < this->w)
}
if (uint8_t(add.w + this->w) < this->w) {
ret.w = 255;
else
} else {
ret.w = this->w + add.w;
}
return ret;
}
inline Color &operator+=(const Color &add) ESPHOME_ALWAYS_INLINE { return *this = (*this) + add; }
@ -108,22 +112,26 @@ struct Color {
inline Color &operator+=(uint8_t add) ESPHOME_ALWAYS_INLINE { return *this = (*this) + add; }
inline Color operator-(const Color &subtract) const ESPHOME_ALWAYS_INLINE {
Color ret;
if (subtract.r > this->r)
if (subtract.r > this->r) {
ret.r = 0;
else
} else {
ret.r = this->r - subtract.r;
if (subtract.g > this->g)
}
if (subtract.g > this->g) {
ret.g = 0;
else
} else {
ret.g = this->g - subtract.g;
if (subtract.b > this->b)
}
if (subtract.b > this->b) {
ret.b = 0;
else
} else {
ret.b = this->b - subtract.b;
if (subtract.w > this->w)
}
if (subtract.w > this->w) {
ret.w = 0;
else
} else {
ret.w = this->w - subtract.w;
}
return ret;
}
inline Color &operator-=(const Color &subtract) ESPHOME_ALWAYS_INLINE { return *this = (*this) - subtract; }