ESPHome 2026.1.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 void add_on_state_callback(std::function<void()> &&callback) { this->state_callback_.add(std::move(callback)); }
18
19#ifdef USE_TIME
20 void set_rtc(time::RealTimeClock *rtc) { this->rtc_ = rtc; }
21 time::RealTimeClock *get_rtc() const { return this->rtc_; }
22#endif
23
24 protected:
26
27#ifdef USE_TIME
29#endif
30};
31
32class DateTimeStateTrigger : public Trigger<ESPTime> {
33 public:
35 parent->add_on_state_callback([this, parent]() { this->trigger(parent->state_as_esptime()); });
36 }
37};
38
39} // namespace esphome::datetime
void trigger(const Ts &...x)
Definition automation.h:204
time::RealTimeClock * rtc_
void add_on_state_callback(std::function< void()> &&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:15