mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
switch to cg.add_define
This commit is contained in:
parent
bd2e7ae299
commit
bfb030de05
6 changed files with 9 additions and 8 deletions
|
@ -159,6 +159,7 @@ async def setup_datetime_core_(var, config, requires_time: bool = True):
|
|||
if requires_time:
|
||||
rtc = await cg.get_variable(config[CONF_TIME_ID])
|
||||
cg.add(var.set_rtc(rtc))
|
||||
cg.add_define("REQUIRES_TIME")
|
||||
|
||||
for conf in config.get(CONF_ON_TIME, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/entity_base.h"
|
||||
#include "esphome/core/time.h"
|
||||
#ifdef USE_TIME
|
||||
#ifdef REQUIRES_TIME
|
||||
#include "esphome/components/time/real_time_clock.h"
|
||||
#endif
|
||||
|
||||
|
@ -20,7 +20,7 @@ class DateTimeBase : public EntityBase {
|
|||
|
||||
void add_on_state_callback(std::function<void()> &&callback) { this->state_callback_.add(std::move(callback)); }
|
||||
|
||||
#ifdef USE_TIME
|
||||
#ifdef REQUIRES_TIME
|
||||
void set_rtc(time::RealTimeClock *rtc) { this->rtc_ = rtc; }
|
||||
time::RealTimeClock *get_rtc() const { return this->rtc_; }
|
||||
#endif
|
||||
|
@ -28,14 +28,14 @@ class DateTimeBase : public EntityBase {
|
|||
protected:
|
||||
CallbackManager<void()> state_callback_;
|
||||
|
||||
#ifdef USE_TIME
|
||||
#ifdef REQUIRES_TIME
|
||||
time::RealTimeClock *rtc_;
|
||||
#endif
|
||||
|
||||
bool has_state_{false};
|
||||
};
|
||||
|
||||
#ifdef USE_TIME
|
||||
#ifdef REQUIRES_TIME
|
||||
class DateTimeStateTrigger : public Trigger<ESPTime> {
|
||||
public:
|
||||
explicit DateTimeStateTrigger(DateTimeBase *parent) {
|
||||
|
|
|
@ -192,7 +192,7 @@ void DateTimeEntityRestoreState::apply(DateTimeEntity *time) {
|
|||
time->publish_state();
|
||||
}
|
||||
|
||||
#ifdef USE_TIME
|
||||
#ifdef REQUIRES_TIME
|
||||
static const int MAX_TIMESTAMP_DRIFT = 900; // how far can the clock drift before we consider
|
||||
// there has been a drastic time synchronization
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ template<typename... Ts> class DateTimeSetAction : public Action<Ts...>, public
|
|||
}
|
||||
};
|
||||
|
||||
#ifdef USE_TIME
|
||||
#ifdef REQUIRES_TIME
|
||||
class OnDateTimeTrigger : public Trigger<>, public Component, public Parented<DateTimeEntity> {
|
||||
public:
|
||||
void loop() override;
|
||||
|
|
|
@ -94,7 +94,7 @@ void TimeEntityRestoreState::apply(TimeEntity *time) {
|
|||
time->publish_state();
|
||||
}
|
||||
|
||||
#ifdef USE_TIME
|
||||
#ifdef REQUIRES_TIME
|
||||
static const int MAX_TIMESTAMP_DRIFT = 900; // how far can the clock drift before we consider
|
||||
// there has been a drastic time synchronization
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ template<typename... Ts> class TimeSetAction : public Action<Ts...>, public Pare
|
|||
}
|
||||
};
|
||||
|
||||
#ifdef USE_TIME
|
||||
#ifdef REQUIRES_TIME
|
||||
class OnTimeTrigger : public Trigger<>, public Component, public Parented<TimeEntity> {
|
||||
public:
|
||||
void loop() override;
|
||||
|
|
Loading…
Reference in a new issue