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);
38 RealTimeClock::dump_config();
51 this->
defer([
this, epoch]() {
58 zb_zcl_device_callback_param_t *p_device_cb_param = ZB_BUF_GET_PARAM(bufid, zb_zcl_device_callback_param_t);
59 zb_zcl_device_callback_id_t device_cb_id = p_device_cb_param->device_cb_id;
60 zb_uint16_t cluster_id = p_device_cb_param->cb_param.set_attr_value_param.cluster_id;
61 zb_uint16_t attr_id = p_device_cb_param->cb_param.set_attr_value_param.attr_id;
63 switch (device_cb_id) {
65 case ZB_ZCL_SET_ATTR_VALUE_CB_ID:
66 if (cluster_id == ZB_ZCL_CLUSTER_ID_TIME) {
67 if (attr_id == ZB_ZCL_ATTR_TIME_TIME_ID) {
68 zb_uint32_t
value = p_device_cb_param->cb_param.set_attr_value_param.values.data32;
70 ESP_LOGI(TAG,
"Synchronize time to %u",
value);
73 ESP_LOGW(TAG,
"Ignoring invalid time %u",
value);
75 }
else if (attr_id == ZB_ZCL_ATTR_TIME_TIME_STATUS_ID) {
76 zb_uint8_t
value = p_device_cb_param->cb_param.set_attr_value_param.values.data8;
77 ESP_LOGI(TAG,
"Time status %hd",
value);
78 this->
defer([
this, value]() { this->
has_time_ = ZB_ZCL_TIME_TIME_STATUS_SYNCHRONIZED_BIT_IS_SET(
value); });
82 ESP_LOGI(TAG,
"Unhandled cluster attribute id: %d", cluster_id);
83 p_device_cb_param->status = RET_NOT_IMPLEMENTED;
87 p_device_cb_param->status = RET_NOT_IMPLEMENTED;
91 ESP_LOGD(TAG,
"Zcl_device_cb_ status: %hd", p_device_cb_param->status);
void defer(const char *name, SchedulerCallback &&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 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 on_zcl_device_event(zb_bufid_t bufid)
void dump_config() override
zb_zcl_time_attrs_t * cluster_attributes_
constexpr time_t EPOCH_2000
constexpr uint32_t MAX_ZCL_TIME
ESPHOME_LOG_TAG(TAG, "zigbee.time")