diff --git a/esphome/components/datetime/__init__.py b/esphome/components/datetime/__init__.py index e048ad6cb3..cdf3387652 100644 --- a/esphome/components/datetime/__init__.py +++ b/esphome/components/datetime/__init__.py @@ -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]) diff --git a/esphome/components/datetime/datetime_base.h b/esphome/components/datetime/datetime_base.h index dea34e6110..584252bee8 100644 --- a/esphome/components/datetime/datetime_base.h +++ b/esphome/components/datetime/datetime_base.h @@ -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 &&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 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 { public: explicit DateTimeStateTrigger(DateTimeBase *parent) { diff --git a/esphome/components/datetime/datetime_entity.cpp b/esphome/components/datetime/datetime_entity.cpp index f215b7acb5..1d00231a5d 100644 --- a/esphome/components/datetime/datetime_entity.cpp +++ b/esphome/components/datetime/datetime_entity.cpp @@ -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 diff --git a/esphome/components/datetime/datetime_entity.h b/esphome/components/datetime/datetime_entity.h index 27db84cf7e..9c2fe01ef7 100644 --- a/esphome/components/datetime/datetime_entity.h +++ b/esphome/components/datetime/datetime_entity.h @@ -134,7 +134,7 @@ template class DateTimeSetAction : public Action, public } }; -#ifdef USE_TIME +#ifdef REQUIRES_TIME class OnDateTimeTrigger : public Trigger<>, public Component, public Parented { public: void loop() override; diff --git a/esphome/components/datetime/time_entity.cpp b/esphome/components/datetime/time_entity.cpp index db0094ae01..cd718bb9e5 100644 --- a/esphome/components/datetime/time_entity.cpp +++ b/esphome/components/datetime/time_entity.cpp @@ -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 diff --git a/esphome/components/datetime/time_entity.h b/esphome/components/datetime/time_entity.h index f7e0a7ddd9..2c63090312 100644 --- a/esphome/components/datetime/time_entity.h +++ b/esphome/components/datetime/time_entity.h @@ -113,7 +113,7 @@ template class TimeSetAction : public Action, public Pare } }; -#ifdef USE_TIME +#ifdef REQUIRES_TIME class OnTimeTrigger : public Trigger<>, public Component, public Parented { public: void loop() override;