mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Fix XOR condition (#5567)
This commit is contained in:
parent
e99b8aaf96
commit
b9d72231b0
1 changed files with 3 additions and 3 deletions
|
@ -52,12 +52,12 @@ template<typename... Ts> class XorCondition : public Condition<Ts...> {
|
||||||
public:
|
public:
|
||||||
explicit XorCondition(const std::vector<Condition<Ts...> *> &conditions) : conditions_(conditions) {}
|
explicit XorCondition(const std::vector<Condition<Ts...> *> &conditions) : conditions_(conditions) {}
|
||||||
bool check(Ts... x) override {
|
bool check(Ts... x) override {
|
||||||
bool xor_state = false;
|
size_t result = 0;
|
||||||
for (auto *condition : this->conditions_) {
|
for (auto *condition : this->conditions_) {
|
||||||
xor_state = xor_state ^ condition->check(x...);
|
result += condition->check(x...);
|
||||||
}
|
}
|
||||||
|
|
||||||
return xor_state;
|
return result == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue