4#ifdef USE_DATETIME_TIME
11static const char *
const TAG =
"datetime.time_entity";
14 if (this->
hour_ > 23) {
16 ESP_LOGE(TAG,
"Hour must be between 0 and 23");
21 ESP_LOGE(TAG,
"Minute must be between 0 and 59");
26 ESP_LOGE(TAG,
"Second must be between 0 and 59");
30 ESP_LOGD(TAG,
"'%s': Sending time %02d:%02d:%02d", this->
get_name().c_str(), this->
hour_, this->
minute_,
33#if defined(USE_DATETIME_TIME) && defined(USE_CONTROLLER_REGISTRY)
42 ESP_LOGE(TAG,
"Hour must be between 0 and 23");
46 ESP_LOGE(TAG,
"Minute must be between 0 and 59");
50 ESP_LOGE(TAG,
"Second must be between 0 and 59");
59 ESP_LOGD(TAG,
" Hour: %d", *this->
hour_);
62 ESP_LOGD(TAG,
" Minute: %d", *this->
minute_);
65 ESP_LOGD(TAG,
" Second: %d", *this->
second_);
82 ESP_LOGE(TAG,
"Could not convert the time string to an ESPTime object");
102static const int MAX_TIMESTAMP_DRIFT = 900;
106 if (!this->
parent_->has_state()) {
116 ESP_LOGW(TAG,
"Time has jumped back!");
120 }
else if (time > *this->
last_check_ && time.
timestamp - this->last_check_->timestamp > MAX_TIMESTAMP_DRIFT) {
122 ESP_LOGW(TAG,
"Time has jumped ahead!");
141 ESP_LOGW(TAG,
"Time is out of range!");
142 ESP_LOGD(TAG,
"Second=%02u Minute=%02u Hour=%02u", time.
second, time.
minute, time.
hour);
static void notify_time_update(datetime::TimeEntity *obj)
const StringRef & get_name() const
void set_has_state(bool state)
constexpr const char * c_str() const
void trigger(const Ts &...x)
CallbackManager< void()> state_callback_
bool matches_(const ESPTime &time) const
optional< ESPTime > last_check_
optional< uint8_t > second_
optional< uint8_t > hour_
optional< uint8_t > minute_
TimeCall & set_time(uint8_t hour, uint8_t minute, uint8_t second)
virtual void control(const TimeCall &call)=0
Providing packet encoding functions for exchanging data with a remote host.
A more user-friendly version of struct tm from time.h.
uint8_t minute
minutes after the hour [0-59]
uint8_t second
seconds after the minute [0-60]
uint8_t hour
hours since midnight [0-23]
time_t timestamp
unix epoch time (seconds since UTC Midnight January 1, 1970)
static bool strptime(const std::string &time_to_parse, ESPTime &esp_time)
Convert a string to ESPTime struct as specified by the format argument.
bool is_valid() const
Check if this ESPTime is valid (all fields in range and year is greater than 2018)
bool fields_in_range() const
Check if all time fields of this ESPTime are in range.
void apply(TimeEntity *time)
TimeCall to_call(TimeEntity *time)