[code-quality] fix readability-braces-around-statements

This commit is contained in:
Tomasz Duda 2024-08-13 23:59:25 +02:00
parent 865f393c9d
commit f08ec5c1c8
13 changed files with 108 additions and 65 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -16,10 +16,11 @@ class RGBWLightOutput : public light::LightOutput {
void set_color_interlock(bool color_interlock) { color_interlock_ = color_interlock; } void set_color_interlock(bool color_interlock) { color_interlock_ = color_interlock; }
light::LightTraits get_traits() override { light::LightTraits get_traits() override {
auto traits = light::LightTraits(); auto traits = light::LightTraits();
if (this->color_interlock_) if (this->color_interlock_) {
traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::WHITE}); traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::WHITE});
else } else {
traits.set_supported_color_modes({light::ColorMode::RGB_WHITE}); traits.set_supported_color_modes({light::ColorMode::RGB_WHITE});
}
return traits; return traits;
} }
void write_state(light::LightState *state) override { 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; } void set_color_interlock(bool color_interlock) { color_interlock_ = color_interlock; }
light::LightTraits get_traits() override { light::LightTraits get_traits() override {
auto traits = light::LightTraits(); 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}); 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_supported_color_modes({light::ColorMode::RGB_COLD_WARM_WHITE});
}
traits.set_min_mireds(this->cold_white_temperature_); traits.set_min_mireds(this->cold_white_temperature_);
traits.set_max_mireds(this->warm_white_temperature_); traits.set_max_mireds(this->warm_white_temperature_);
return traits; return traits;

View file

@ -46,10 +46,11 @@ class SpiLedStrip : public light::AddressableLight,
void dump_config() override { void dump_config() override {
esph_log_config(TAG, "SPI LED Strip:"); esph_log_config(TAG, "SPI LED Strip:");
esph_log_config(TAG, " LEDs: %d", this->num_leds_); 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)); 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)); esph_log_config(TAG, " Data rate: %ukHz", (unsigned) (this->data_rate_ / 1000));
}
} }
void write_state(light::LightState *state) override { void write_state(light::LightState *state) override {

View file

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

View file

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

View file

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