2#if defined(USE_ZIGBEE) && defined(USE_NRF52) && defined(USE_TIME)
19 zb_uint32_t nw_time) {
20 if (
status == RET_OK && auth_level >= ZB_ZCL_TIME_HAS_SYNCHRONIZED_BIT && nw_time <=
MAX_ZCL_TIME) {
23 ESP_LOGE(TAG,
"Status: %d, auth_level: %u, short_addr: %d, endpoint: %d, nw_time: %u",
status, auth_level,
24 short_addr, endpoint, nw_time);
39 RealTimeClock::dump_config();
52 this->
defer([
this, epoch]() {
59 zb_zcl_device_callback_param_t *p_device_cb_param = ZB_BUF_GET_PARAM(bufid, zb_zcl_device_callback_param_t);
60 zb_zcl_device_callback_id_t device_cb_id = p_device_cb_param->device_cb_id;
61 zb_uint16_t cluster_id = p_device_cb_param->cb_param.set_attr_value_param.cluster_id;
62 zb_uint16_t attr_id = p_device_cb_param->cb_param.set_attr_value_param.attr_id;
64 switch (device_cb_id) {
66 case ZB_ZCL_SET_ATTR_VALUE_CB_ID:
67 if (cluster_id == ZB_ZCL_CLUSTER_ID_TIME) {
68 if (attr_id == ZB_ZCL_ATTR_TIME_TIME_ID) {
69 zb_uint32_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data32;
71 ESP_LOGI(TAG,
"Synchronize time to %u", value);
74 ESP_LOGW(TAG,
"Ignoring invalid time %u", value);
76 }
else if (attr_id == ZB_ZCL_ATTR_TIME_TIME_STATUS_ID) {
77 zb_uint8_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data8;
78 ESP_LOGI(TAG,
"Time status %hd", value);
79 this->
defer([
this, value]() { this->
has_time_ = ZB_ZCL_TIME_TIME_STATUS_SYNCHRONIZED_BIT_IS_SET(value); });
83 ESP_LOGI(TAG,
"Unhandled cluster attribute id: %d", cluster_id);
84 p_device_cb_param->status = RET_NOT_IMPLEMENTED;
88 p_device_cb_param->status = RET_NOT_IMPLEMENTED;
92 ESP_LOGD(TAG,
"Zcl_device_cb_ status: %hd", p_device_cb_param->status);
void defer(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call 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_join_callback(F &&cb)
void add_callback(zb_uint8_t endpoint, std::function< void(zb_bufid_t bufid)> &&cb)
void set_epoch_time(uint32_t utc)
ZigbeeComponent * parent_
static void sync_time(zb_ret_t status, zb_uint32_t auth_level, zb_uint16_t short_addr, zb_uint8_t endpoint, zb_uint32_t nw_time)
void dump_config() override
void zcl_device_cb_(zb_bufid_t bufid)
zb_zcl_time_attrs_t * cluster_attributes_
constexpr time_t EPOCH_2000
constexpr uint32_t MAX_ZCL_TIME
ESPHOME_LOG_TAG(TAG, "zigbee.time")