ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
datetime_base.h
Go to the documentation of this file.
1#pragma once
2
6#include "esphome/core/time.h"
7#ifdef USE_TIME
9#endif
10
11namespace esphome::datetime {
12
13class DateTimeBase : public EntityBase {
14 public:
15 virtual ESPTime state_as_esptime() const = 0;
16
17 template<typename F> void add_on_state_callback(F &&callback) {
18 this->state_callback_.add(std::forward<F>(callback));
19 }
20
21#ifdef USE_TIME
22 void set_rtc(time::RealTimeClock *rtc) { this->rtc_ = rtc; }
23 time::RealTimeClock *get_rtc() const { return this->rtc_; }
24#endif
25
26 protected:
28
29#ifdef USE_TIME
31#endif
32};
33
34class DateTimeStateTrigger : public Trigger<ESPTime> {
35 public:
36 explicit DateTimeStateTrigger(DateTimeBase *parent) : parent_(parent) {
37 parent->add_on_state_callback([this]() { this->trigger(this->parent_->state_as_esptime()); });
38 }
39
40 protected:
42};
43
44} // namespace esphome::datetime
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:482
time::RealTimeClock * rtc_
void add_on_state_callback(F &&callback)
time::RealTimeClock * get_rtc() const
void set_rtc(time::RealTimeClock *rtc)
virtual ESPTime state_as_esptime() const =0
LazyCallbackManager< void()> state_callback_
DateTimeStateTrigger(DateTimeBase *parent)
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
A more user-friendly version of struct tm from time.h.
Definition time.h:23