ESPHome  2024.4.2
datetime_base.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include "esphome/core/time.h"
7 
8 namespace esphome {
9 namespace datetime {
10 
11 class DateTimeBase : public EntityBase {
12  public:
14  bool has_state() const { return this->has_state_; }
15 
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  protected:
22 
23  bool has_state_{false};
24 };
25 
26 class DateTimeStateTrigger : public Trigger<ESPTime> {
27  public:
28  explicit DateTimeStateTrigger(DateTimeBase *parent) {
29  parent->add_on_state_callback([this, parent]() { this->trigger(parent->state_as_esptime()); });
30  }
31 };
32 
33 } // namespace datetime
34 } // namespace esphome
A more user-friendly version of struct tm from time.h.
Definition: time.h:17
CallbackManager< void()> state_callback_
Definition: datetime_base.h:21
bool has_state() const
Return whether this Datetime has gotten a full state yet.
Definition: datetime_base.h:14
void add_on_state_callback(std::function< void()> &&callback)
Definition: datetime_base.h:18
virtual ESPTime state_as_esptime() const =0
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
DateTimeStateTrigger(DateTimeBase *parent)
Definition: datetime_base.h:28