@@ -19,6 +19,7 @@ ZigbeeEP::ZigbeeEP(uint8_t endpoint) {
19
19
_ep_config.endpoint = 0 ;
20
20
_cluster_list = nullptr ;
21
21
_on_identify = nullptr ;
22
+ _time_status = 0 ;
22
23
if (!lock) {
23
24
lock = xSemaphoreCreateBinary ();
24
25
if (lock == NULL ) {
@@ -240,7 +241,6 @@ void ZigbeeEP::zbIdentify(const esp_zb_zcl_set_attr_value_message_t *message) {
240
241
241
242
void ZigbeeEP::addTimeCluster (tm time, int32_t gmt_offset) {
242
243
time_t utc_time = 0 ;
243
-
244
244
// Check if time is set
245
245
if (time .tm_year > 0 ) {
246
246
// Convert time to UTC
@@ -251,6 +251,7 @@ void ZigbeeEP::addTimeCluster(tm time, int32_t gmt_offset) {
251
251
esp_zb_attribute_list_t *time_cluster_server = esp_zb_zcl_attr_list_create (ESP_ZB_ZCL_CLUSTER_ID_TIME);
252
252
esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_ZONE_ID, (void *)&gmt_offset);
253
253
esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_ID, (void *)&utc_time);
254
+ esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_STATUS_ID, (void *)&_time_status);
254
255
// Create time cluster client attributes
255
256
esp_zb_attribute_list_t *time_cluster_client = esp_zb_zcl_attr_list_create (ESP_ZB_ZCL_CLUSTER_ID_TIME);
256
257
// Add time clusters to cluster list
@@ -260,6 +261,7 @@ void ZigbeeEP::addTimeCluster(tm time, int32_t gmt_offset) {
260
261
261
262
void ZigbeeEP::setTime (tm time) {
262
263
time_t utc_time = mktime (&time );
264
+ log_d (" Setting time to %lld" , utc_time);
263
265
esp_zb_lock_acquire (portMAX_DELAY);
264
266
esp_zb_zcl_set_attribute_val (_endpoint, ESP_ZB_ZCL_CLUSTER_ID_TIME, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_TIME_TIME_ID, &utc_time, false );
265
267
esp_zb_lock_release ();
@@ -306,6 +308,14 @@ tm ZigbeeEP::getTime(uint8_t endpoint, int32_t short_addr, esp_zb_ieee_addr_t ie
306
308
307
309
struct tm *timeinfo = localtime (&_read_time);
308
310
if (timeinfo) {
311
+ // Update time
312
+ setTime (*timeinfo);
313
+ // Update time status to synced
314
+ _time_status |= 0x02 ;
315
+ esp_zb_lock_acquire (portMAX_DELAY);
316
+ esp_zb_zcl_set_attribute_val (_endpoint, ESP_ZB_ZCL_CLUSTER_ID_TIME, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_TIME_TIME_STATUS_ID, &_time_status, false );
317
+ esp_zb_lock_release ();
318
+
309
319
return *timeinfo;
310
320
} else {
311
321
log_e (" Error while converting time" );
@@ -343,8 +353,9 @@ int32_t ZigbeeEP::getTimezone(uint8_t endpoint, int32_t short_addr, esp_zb_ieee_
343
353
// Wait for response or timeout
344
354
if (xSemaphoreTake (lock, ZB_CMD_TIMEOUT) != pdTRUE) {
345
355
log_e (" Error while reading timezone" );
356
+ return 0 ;
346
357
}
347
-
358
+ setTimezone (_read_timezone);
348
359
return _read_timezone;
349
360
}
350
361
0 commit comments