3 #ifdef USE_DATETIME_TIME 10 static 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_,
37 if (this->
hour_.has_value() && this->
hour_ > 23) {
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");
53 ESP_LOGD(TAG,
"'%s' - Setting", this->parent_->get_name().c_str());
54 if (this->
hour_.has_value()) {
55 ESP_LOGD(TAG,
" Hour: %d", *this->
hour_);
57 if (this->
minute_.has_value()) {
58 ESP_LOGD(TAG,
" Minute: %d", *this->
minute_);
60 if (this->
second_.has_value()) {
61 ESP_LOGD(TAG,
" Second: %d", *this->
second_);
63 this->parent_->control(*
this);
78 ESP_LOGE(TAG,
"Could not convert the time string to an ESPTime object");
81 return this->set_time(
val);
97 static const int MAX_TIMESTAMP_DRIFT = 900;
101 if (!this->parent_->has_state()) {
104 ESPTime time = this->parent_->rtc_->now();
108 if (this->last_check_.has_value()) {
109 if (*this->last_check_ > time && this->last_check_->
timestamp - time.
timestamp > MAX_TIMESTAMP_DRIFT) {
111 ESP_LOGW(TAG,
"Time has jumped back!");
112 }
else if (*this->last_check_ >= time) {
115 }
else if (time > *this->last_check_ && time.
timestamp - this->last_check_->timestamp > MAX_TIMESTAMP_DRIFT) {
117 ESP_LOGW(TAG,
"Time has jumped ahead!");
118 this->last_check_ = time;
124 if (*this->last_check_ >= time)
127 if (this->matches_(*this->last_check_)) {
134 this->last_check_ = time;
136 ESP_LOGW(TAG,
"Time is out of range!");
137 ESP_LOGD(TAG,
"Second=%02u Minute=%02u Hour=%02u", time.
second, time.
minute, time.
hour);
140 if (this->matches_(time))
145 return time.
is_valid() && time.
hour == this->parent_->hour && time.
minute == this->parent_->minute &&
146 time.
second == this->parent_->second;
152 #endif // USE_DATETIME_TIME
TimeCall & set_time(uint8_t hour, uint8_t minute, uint8_t second)
A more user-friendly version of struct tm from time.h.
void apply(TimeEntity *time)
CallbackManager< void()> state_callback_
void increment_second()
Increment this clock instance by one second.
uint8_t second
seconds after the minute [0-60]
time_t timestamp
unix epoch time (seconds since UTC Midnight January 1, 1970)
uint8_t minute
minutes after the hour [0-59]
bool is_valid() const
Check if this ESPTime is valid (all fields in range and year is greater than 2018) ...
TimeCall to_call(TimeEntity *time)
Implementation of SPI Controller mode.
uint8_t hour
hours since midnight [0-23]
const StringRef & get_name() const
bool matches_(const ESPTime &time) const
bool fields_in_range() const
Check if all time fields of this ESPTime are in range.
static bool strptime(const std::string &time_to_parse, ESPTime &esp_time)
Convert a string to ESPTime struct as specified by the format argument.