mirror of
https://github.com/esphome/esphome.git
synced 2026-02-05 05:39:41 -07:00
Merge branch 'light_flash_effect' into integration
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "light_state.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/optional.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
|
||||
namespace esphome::light {
|
||||
|
||||
@@ -509,7 +510,7 @@ color_mode_bitmask_t LightCall::get_suitable_color_modes_mask_() {
|
||||
}
|
||||
|
||||
LightCall &LightCall::set_effect(const char *effect, size_t len) {
|
||||
if (len == 4 && strncasecmp(effect, "none", 4) == 0) {
|
||||
if (len == 4 && ESPHOME_strncasecmp_P(effect, ESPHOME_PSTR("none"), 4) == 0) {
|
||||
this->set_effect(0);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "light_transformer.h"
|
||||
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
#include <strings.h>
|
||||
#include <vector>
|
||||
|
||||
@@ -188,17 +189,20 @@ class LightState : public EntityBase, public Component {
|
||||
uint32_t get_current_effect_index() const { return this->active_effect_index_; }
|
||||
|
||||
/// Get effect index by name. Returns 0 if effect not found.
|
||||
uint32_t get_effect_index(const std::string &effect_name) const {
|
||||
if (str_equals_case_insensitive(effect_name, "none")) {
|
||||
uint32_t get_effect_index(const char *effect_name) const {
|
||||
if (ESPHOME_strcasecmp_P(effect_name, ESPHOME_PSTR("none")) == 0) {
|
||||
return 0;
|
||||
}
|
||||
for (size_t i = 0; i < this->effects_.size(); i++) {
|
||||
if (str_equals_case_insensitive(effect_name, this->effects_[i]->get_name())) {
|
||||
if (strcasecmp(effect_name, this->effects_[i]->get_name().c_str()) == 0) {
|
||||
return i + 1; // Effects are 1-indexed in active_effect_index_
|
||||
}
|
||||
}
|
||||
return 0; // Effect not found
|
||||
}
|
||||
uint32_t get_effect_index(const std::string &effect_name) const {
|
||||
return this->get_effect_index(effect_name.c_str());
|
||||
}
|
||||
|
||||
/// Get effect by index. Returns nullptr if index is invalid.
|
||||
LightEffect *get_effect_by_index(uint32_t index) const {
|
||||
|
||||
Reference in New Issue
Block a user