3#ifdef USE_DATETIME_DATETIME
10static const char *
const TAG =
"datetime.datetime_entity";
19 ESP_LOGE(TAG,
"Year must be between 1970 and 3000");
24 ESP_LOGE(TAG,
"Month must be between 1 and 12");
32 if (this->
hour_ > 23) {
34 ESP_LOGE(TAG,
"Hour must be between 0 and 23");
39 ESP_LOGE(TAG,
"Minute must be between 0 and 59");
44 ESP_LOGE(TAG,
"Second must be between 0 and 59");
48 ESP_LOGD(TAG,
"'%s': Sending datetime %04u-%02u-%02u %02d:%02d:%02d", this->
get_name().c_str(), this->
year_,
68 if (this->
year_.
has_value() && (this->year_ < 1970 || this->year_ > 3000)) {
69 ESP_LOGE(TAG,
"Year must be between 1970 and 3000");
74 if (this->
month_.
has_value() && (this->month_ < 1 || this->month_ > 12)) {
75 ESP_LOGE(TAG,
"Month must be between 1 and 12");
88 ESP_LOGE(TAG,
"Month must be set to validate day");
98 ESP_LOGE(TAG,
"Year must be set to validate day");
109 ESP_LOGE(TAG,
"Hour must be between 0 and 23");
113 ESP_LOGE(TAG,
"Minute must be between 0 and 59");
117 ESP_LOGE(TAG,
"Second must be between 0 and 59");
127 ESP_LOGD(TAG,
" Year: %d", *this->
year_);
130 ESP_LOGD(TAG,
" Month: %d", *this->
month_);
133 ESP_LOGD(TAG,
" Day: %d", *this->
day_);
136 ESP_LOGD(TAG,
" Hour: %d", *this->
hour_);
139 ESP_LOGD(TAG,
" Minute: %d", *this->
minute_);
142 ESP_LOGD(TAG,
" Second: %d", *this->
second_);
166 ESP_LOGE(TAG,
"Could not convert the time string to an ESPTime object");
194static const int MAX_TIMESTAMP_DRIFT = 900;
198 if (!this->
parent_->has_state()) {
208 ESP_LOGW(TAG,
"Time has jumped back!");
212 }
else if (time > *this->
last_check_ && time.
timestamp - this->last_check_->timestamp > MAX_TIMESTAMP_DRIFT) {
214 ESP_LOGW(TAG,
"Time has jumped ahead!");
233 ESP_LOGW(TAG,
"Time is out of range!");
234 ESP_LOGD(TAG,
"Second=%02u Minute=%02u Hour=%02u Day=%02u Month=%02u Year=%04u", time.
second, time.
minute,
const StringRef & get_name() const
constexpr const char * c_str() const
CallbackManager< void()> state_callback_
optional< uint8_t > minute_
optional< uint8_t > hour_
optional< uint8_t > month_
DateTimeCall & set_datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
optional< uint8_t > second_
optional< uint16_t > year_
virtual void control(const DateTimeCall &call)=0
friend class DateTimeCall
ESPTime state_as_esptime() const override
optional< ESPTime > last_check_
bool matches_(const ESPTime &time) const
Providing packet encoding functions for exchanging data with a remote host.
uint8_t days_in_month(uint8_t month, uint16_t year)
A more user-friendly version of struct tm from time.h.
uint8_t minute
minutes after the hour [0-59]
static ESPTime from_epoch_local(time_t epoch)
Convert an UTC epoch timestamp to a local time ESPTime instance.
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)
void recalc_timestamp_local()
Recalculate the timestamp field from the other fields of this ESPTime instance assuming local fields.
uint8_t day_of_month
day of the month [1-31]
bool fields_in_range() const
Check if all time fields of this ESPTime are in range.
uint8_t month
month; january=1 [1-12]
void apply(DateTimeEntity *datetime)
DateTimeCall to_call(DateTimeEntity *datetime)