3#ifdef USE_DATETIME_TIME
10static const char *
const TAG =
"datetime.time_entity";
13 if (this->
hour_ > 23) {
15 ESP_LOGE(TAG,
"Hour must be between 0 and 23");
20 ESP_LOGE(TAG,
"Minute must be between 0 and 59");
25 ESP_LOGE(TAG,
"Second must be between 0 and 59");
29 ESP_LOGD(TAG,
"'%s': Sending time %02d:%02d:%02d", this->
get_name().c_str(), this->
hour_, this->
minute_,
38 ESP_LOGE(TAG,
"Hour must be between 0 and 23");
42 ESP_LOGE(TAG,
"Minute must be between 0 and 59");
46 ESP_LOGE(TAG,
"Second must be between 0 and 59");
55 ESP_LOGD(TAG,
" Hour: %d", *this->
hour_);
58 ESP_LOGD(TAG,
" Minute: %d", *this->
minute_);
61 ESP_LOGD(TAG,
" Second: %d", *this->
second_);
78 ESP_LOGE(TAG,
"Could not convert the time string to an ESPTime object");
98static const int MAX_TIMESTAMP_DRIFT = 900;
102 if (!this->
parent_->has_state()) {
112 ESP_LOGW(TAG,
"Time has jumped back!");
116 }
else if (time > *this->
last_check_ && time.
timestamp - this->last_check_->timestamp > MAX_TIMESTAMP_DRIFT) {
118 ESP_LOGW(TAG,
"Time has jumped ahead!");
137 ESP_LOGW(TAG,
"Time is out of range!");
138 ESP_LOGD(TAG,
"Second=%02u Minute=%02u Hour=%02u", time.
second, time.
minute, time.
hour);
const StringRef & get_name() const
constexpr const char * c_str() const
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)