ESPHome 2025.5.0
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:
17 bool has_state() const { return this->has_state_; }
18
19 virtual ESPTime state_as_esptime() const = 0;
20
21 void add_on_state_callback(std::function<void()> &&callback) { this->state_callback_.add(std::move(callback)); }
22
23#ifdef USE_TIME
24 void set_rtc(time::RealTimeClock *rtc) { this->rtc_ = rtc; }
25 time::RealTimeClock *get_rtc() const { return this->rtc_; }
26#endif
27
28 protected:
30
31#ifdef USE_TIME
33#endif
34
35 bool has_state_{false};
36};
37
38#ifdef USE_TIME
39class DateTimeStateTrigger : public Trigger<ESPTime> {
40 public:
42 parent->add_on_state_callback([this, parent]() { this->trigger(parent->state_as_esptime()); });
43 }
44};
45#endif
46
47} // namespace datetime
48} // namespace esphome
time::RealTimeClock * rtc_
CallbackManager< void()> state_callback_
void add_on_state_callback(std::function< void()> &&callback)
bool has_state() const
Return whether this Datetime has gotten a full state yet.
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