2#if defined(USE_ZIGBEE) && defined(USE_ESP32) && defined(USE_TIME)
9static constexpr uint32_t REGISTER_RETRY_TIMEOUT_ID = 0;
10static constexpr uint32_t SYNC_RETRY_TIMEOUT_ID = 1;
30 ezb_zcl_time_interface_t time_interface = {
35 if (!esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
39 ret = ezb_zcl_time_server_interface_register(this->
endpoint_, time_interface);
40 esp_zigbee_lock_release();
41 if (
ret != EZB_ERR_NONE) {
42 ESP_LOGW(TAG,
"Setup failed: %d",
ret);
54 if (
status == EZB_ERR_NONE) {
55 ESP_LOGV(TAG,
"Time synchronization successful");
56 }
else if (
status == EZB_ERR_TIMEOUT) {
57 ESP_LOGW(TAG,
"Time synchronization timed out");
59 ESP_LOGW(TAG,
"Time synchronization failed with error: %d",
status);
65 if (esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
66 ESP_LOGV(TAG,
"Updating time sync from Zigbee network...");
68 EZB_ZCL_TIME_SERVER_RANK_MASTER);
69 esp_zigbee_lock_release();
73 ESP_LOGW(TAG,
"Could not acquire Zigbee lock to synchronize time, will retry maximum 3 times");
79 ESP_LOGW(TAG,
"Could not acquire Zigbee lock to synchronize time");
84 ESP_LOGD(TAG,
"Not connected to Zigbee network, cannot synchronize time");
98 if (utc <= (std::numeric_limits<uint32_t>::max() -
EPOCH_2000)) {
105 this->
defer([
this, utc]() {
106 ESP_LOGV(TAG,
"Setting device time to UTC: %u",
static_cast<unsigned>(utc));
116 RealTimeClock::dump_config();
void mark_failed()
Mark this component as failed.
void defer(const char *name, SchedulerCallback &&f)
Defer a callback to the next loop() call with a const char* name.
void set_timeout(const char *name, uint32_t timeout, SchedulerCallback &&f)
Set a timeout function with a const char* name.
ESPTime now()
Get the time in the currently defined timezone.
virtual time_t timestamp_now()
Get the current time as the UTC epoch since January 1st 1970.
void synchronize_epoch_(uint32_t epoch)
Report a unix epoch as current time.
void add_on_start_callback(F &&cb)
void add_on_join_callback(F &&cb)
void set_epoch_time(uint32_t utc)
static void status_cb(ezb_err_t status)
ZigbeeComponent * parent_
static void set_utc_time(uint32_t utc)
static uint32_t get_utc_time()
void dump_config() override
constexpr time_t EPOCH_2000
ESPHOME_LOG_TAG(TAG, "zigbee.time")