Add new time.has_time condition (#1255)

This commit is contained in:
Ash McKenzie
2020-10-05 02:22:28 +11:00
committed by GitHub
parent 002861f13b
commit 5c86f332b2
3 changed files with 22 additions and 1 deletions
+10
View File
@@ -2,6 +2,7 @@
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#include "esphome/core/automation.h"
#include <stdlib.h>
#include <time.h>
#include <bitset>
@@ -133,5 +134,14 @@ class RealTimeClock : public Component {
std::string timezone_{};
};
template<typename... Ts> class TimeHasTimeCondition : public Condition<Ts...> {
public:
TimeHasTimeCondition(RealTimeClock *parent) : parent_(parent) {}
bool check(Ts... x) override { return this->parent_->now().is_valid(); }
protected:
RealTimeClock *parent_;
};
} // namespace time
} // namespace esphome