ESPHome 2025.6.3
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 {
12namespace datetime {
13
14class DateTimeBase : public EntityBase {
15 public:
16 virtual ESPTime state_as_esptime() const = 0;
17
18 void add_on_state_callback(std::function<void()> &&callback) { this->state_callback_.add(std::move(callback)); }
19
20#ifdef USE_TIME
21 void set_rtc(time::RealTimeClock *rtc) { this->rtc_ = rtc; }
22 time::RealTimeClock *get_rtc() const { return this->rtc_; }
23#endif
24
25 protected:
27
28#ifdef USE_TIME
30#endif
31};
32
33#ifdef USE_TIME
34class DateTimeStateTrigger : public Trigger<ESPTime> {
35 public:
37 parent->add_on_state_callback([this, parent]() { this->trigger(parent->state_as_esptime()); });
38 }
39};
40#endif
41
42} // namespace datetime
43} // namespace esphome
time::RealTimeClock * rtc_
CallbackManager< void()> state_callback_
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
DateTimeStateTrigger(DateTimeBase *parent)
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
A more user-friendly version of struct tm from time.h.
Definition time.h:15