mirror of
https://github.com/esphome/esphome.git
synced 2025-10-19 10:13:49 +01:00
Merge branch 'fixed_vectors_for_automations' into integration
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
#include "esphome/core/scheduler.h"
|
#include "esphome/core/scheduler.h"
|
||||||
#include "esphome/core/application.h"
|
#include "esphome/core/application.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ namespace esphome {
|
|||||||
|
|
||||||
template<typename... Ts> class AndCondition : public Condition<Ts...> {
|
template<typename... Ts> class AndCondition : public Condition<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit AndCondition(const std::vector<Condition<Ts...> *> &conditions) : conditions_(conditions) {}
|
explicit AndCondition(std::initializer_list<Condition<Ts...> *> conditions) : conditions_(conditions) {}
|
||||||
bool check(Ts... x) override {
|
bool check(Ts... x) override {
|
||||||
for (auto *condition : this->conditions_) {
|
for (auto *condition : this->conditions_) {
|
||||||
if (!condition->check(x...))
|
if (!condition->check(x...))
|
||||||
@@ -25,12 +26,12 @@ template<typename... Ts> class AndCondition : public Condition<Ts...> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<Condition<Ts...> *> conditions_;
|
FixedVector<Condition<Ts...> *> conditions_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class OrCondition : public Condition<Ts...> {
|
template<typename... Ts> class OrCondition : public Condition<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit OrCondition(const std::vector<Condition<Ts...> *> &conditions) : conditions_(conditions) {}
|
explicit OrCondition(std::initializer_list<Condition<Ts...> *> conditions) : conditions_(conditions) {}
|
||||||
bool check(Ts... x) override {
|
bool check(Ts... x) override {
|
||||||
for (auto *condition : this->conditions_) {
|
for (auto *condition : this->conditions_) {
|
||||||
if (condition->check(x...))
|
if (condition->check(x...))
|
||||||
@@ -41,7 +42,7 @@ template<typename... Ts> class OrCondition : public Condition<Ts...> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<Condition<Ts...> *> conditions_;
|
FixedVector<Condition<Ts...> *> conditions_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class NotCondition : public Condition<Ts...> {
|
template<typename... Ts> class NotCondition : public Condition<Ts...> {
|
||||||
@@ -55,7 +56,7 @@ template<typename... Ts> class NotCondition : public Condition<Ts...> {
|
|||||||
|
|
||||||
template<typename... Ts> class XorCondition : public Condition<Ts...> {
|
template<typename... Ts> class XorCondition : public Condition<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit XorCondition(const std::vector<Condition<Ts...> *> &conditions) : conditions_(conditions) {}
|
explicit XorCondition(std::initializer_list<Condition<Ts...> *> conditions) : conditions_(conditions) {}
|
||||||
bool check(Ts... x) override {
|
bool check(Ts... x) override {
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
for (auto *condition : this->conditions_) {
|
for (auto *condition : this->conditions_) {
|
||||||
@@ -66,7 +67,7 @@ template<typename... Ts> class XorCondition : public Condition<Ts...> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<Condition<Ts...> *> conditions_;
|
FixedVector<Condition<Ts...> *> conditions_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... Ts> class LambdaCondition : public Condition<Ts...> {
|
template<typename... Ts> class LambdaCondition : public Condition<Ts...> {
|
||||||
|
Reference in New Issue
Block a user