4#ifdef USE_DATETIME_DATETIME
11static const char *
const TAG =
"datetime.datetime_entity";
20 ESP_LOGE(TAG,
"Year must be between 1970 and 3000");
25 ESP_LOGE(TAG,
"Month must be between 1 and 12");
33 if (this->
hour_ > 23) {
35 ESP_LOGE(TAG,
"Hour must be between 0 and 23");
40 ESP_LOGE(TAG,
"Minute must be between 0 and 59");
45 ESP_LOGE(TAG,
"Second must be between 0 and 59");
49 ESP_LOGD(TAG,
"'%s': Sending datetime %04u-%02u-%02u %02d:%02d:%02d", this->
get_name().c_str(), this->
year_,
52#if defined(USE_DATETIME_DATETIME) && defined(USE_CONTROLLER_REGISTRY)
72 if (this->
year_.
has_value() && (this->year_ < 1970 || this->year_ > 3000)) {
73 ESP_LOGE(TAG,
"Year must be between 1970 and 3000");
78 if (this->
month_.
has_value() && (this->month_ < 1 || this->month_ > 12)) {
79 ESP_LOGE(TAG,
"Month must be between 1 and 12");
92 ESP_LOGE(TAG,
"Month must be set to validate day");
102 ESP_LOGE(TAG,
"Year must be set to validate day");
113 ESP_LOGE(TAG,
"Hour must be between 0 and 23");
117 ESP_LOGE(TAG,
"Minute must be between 0 and 59");
121 ESP_LOGE(TAG,
"Second must be between 0 and 59");
131 ESP_LOGD(TAG,
" Year: %d", *this->
year_);
134 ESP_LOGD(TAG,
" Month: %d", *this->
month_);
137 ESP_LOGD(TAG,
" Day: %d", *this->
day_);
140 ESP_LOGD(TAG,
" Hour: %d", *this->
hour_);
143 ESP_LOGD(TAG,
" Minute: %d", *this->
minute_);
146 ESP_LOGD(TAG,
" Second: %d", *this->
second_);
170 ESP_LOGE(TAG,
"Could not convert the time string to an ESPTime object");
198static const int MAX_TIMESTAMP_DRIFT = 900;
202 if (!this->
parent_->has_state()) {
212 ESP_LOGW(TAG,
"Time has jumped back!");
216 }
else if (time > *this->
last_check_ && time.
timestamp - this->last_check_->timestamp > MAX_TIMESTAMP_DRIFT) {
218 ESP_LOGW(TAG,
"Time has jumped ahead!");
237 ESP_LOGW(TAG,
"Time is out of range!");
238 ESP_LOGD(TAG,
"Second=%02u Minute=%02u Hour=%02u Day=%02u Month=%02u Year=%04u", time.
second, time.
minute,
static void notify_datetime_update(datetime::DateTimeEntity *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_
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)