1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-26 04:33:47 +00:00

[light] Replace std::vector with FixedVector in strobe and color_wipe effects

This commit is contained in:
J. Nick Koston
2025-10-21 11:10:02 -10:00
parent 8e8a2bde95
commit d6961610c7
3 changed files with 46 additions and 6 deletions

View File

@@ -1,9 +1,9 @@
#pragma once
#include <utility>
#include <vector>
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#include "esphome/components/light/light_state.h"
#include "esphome/components/light/addressable_light.h"
@@ -113,7 +113,7 @@ struct AddressableColorWipeEffectColor {
class AddressableColorWipeEffect : public AddressableLightEffect {
public:
explicit AddressableColorWipeEffect(const std::string &name) : AddressableLightEffect(name) {}
void set_colors(const std::vector<AddressableColorWipeEffectColor> &colors) { this->colors_ = colors; }
void set_colors(const std::initializer_list<AddressableColorWipeEffectColor> &colors) { this->colors_ = colors; }
void set_add_led_interval(uint32_t add_led_interval) { this->add_led_interval_ = add_led_interval; }
void set_reverse(bool reverse) { this->reverse_ = reverse; }
void apply(AddressableLight &it, const Color &current_color) override {
@@ -155,7 +155,7 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
}
protected:
std::vector<AddressableColorWipeEffectColor> colors_;
FixedVector<AddressableColorWipeEffectColor> colors_;
size_t at_color_{0};
uint32_t last_add_{0};
uint32_t add_led_interval_{};

View File

@@ -1,9 +1,9 @@
#pragma once
#include <utility>
#include <vector>
#include "esphome/core/automation.h"
#include "esphome/core/helpers.h"
#include "light_effect.h"
namespace esphome {
@@ -188,10 +188,10 @@ class StrobeLightEffect : public LightEffect {
this->last_switch_ = now;
}
void set_colors(const std::vector<StrobeLightEffectColor> &colors) { this->colors_ = colors; }
void set_colors(const std::initializer_list<StrobeLightEffectColor> &colors) { this->colors_ = colors; }
protected:
std::vector<StrobeLightEffectColor> colors_;
FixedVector<StrobeLightEffectColor> colors_;
uint32_t last_switch_{0};
size_t at_color_{0};
};

View File

@@ -123,3 +123,43 @@ light:
red: 100%
green: 50%
blue: 50%
# Test StrobeLightEffect with multiple colors
- platform: monochromatic
id: test_strobe_multiple
name: Strobe Multiple Colors
output: test_ledc_1
effects:
- strobe:
name: Strobe Multi
colors:
- state: true
brightness: 100%
duration: 500ms
- state: false
duration: 250ms
- state: true
brightness: 50%
duration: 500ms
# Test StrobeLightEffect with transition
- platform: rgb
id: test_strobe_transition
name: Strobe With Transition
red: test_ledc_1
green: test_ledc_2
blue: test_ledc_3
effects:
- strobe:
name: Strobe Transition
colors:
- state: true
red: 100%
green: 0%
blue: 0%
duration: 1s
transition_length: 500ms
- state: true
red: 0%
green: 100%
blue: 0%
duration: 1s
transition_length: 500ms