@@ -31,6 +31,7 @@ ZigbeeContactSwitch::ZigbeeContactSwitch(uint8_t endpoint) : ZigbeeEP(endpoint)
3131 _zone_status = 0 ;
3232 _zone_id = 0xff ;
3333 _ias_cie_endpoint = 1 ;
34+ _enrolled = false ;
3435
3536 // Create custom contact switch configuration
3637 zigbee_contact_switch_cfg_t contact_switch_cfg = ZIGBEE_DEFAULT_CONTACT_SWITCH_CONFIG ();
@@ -44,31 +45,33 @@ void ZigbeeContactSwitch::setIASClientEndpoint(uint8_t ep_number) {
4445}
4546
4647bool ZigbeeContactSwitch::setClosed () {
48+ esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
4749 log_v (" Setting Contact switch to closed" );
4850 uint8_t closed = 0 ; // ALARM1 = 0, ALARM2 = 0
4951 esp_zb_lock_acquire (portMAX_DELAY);
50- esp_err_t ret = esp_zb_zcl_set_attribute_val (
52+ ret = esp_zb_zcl_set_attribute_val (
5153 _endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_ZONESTATUS_ID, &closed, false
5254 );
5355 esp_zb_lock_release ();
54- if (ret != ESP_OK ) {
55- log_e (" Failed to set contact switch to closed: 0x%x: %s" , ret, esp_err_to_name (ret));
56+ if (ret != ESP_ZB_ZCL_STATUS_SUCCESS ) {
57+ log_e (" Failed to set contact switch to closed: 0x%x: %s" , ret, esp_zb_zcl_status_to_name (ret));
5658 return false ;
5759 }
5860 _zone_status = closed;
5961 return report ();
6062}
6163
6264bool ZigbeeContactSwitch::setOpen () {
65+ esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
6366 log_v (" Setting Contact switch to open" );
6467 uint8_t open = ESP_ZB_ZCL_IAS_ZONE_ZONE_STATUS_ALARM1 | ESP_ZB_ZCL_IAS_ZONE_ZONE_STATUS_ALARM2; // ALARM1 = 1, ALARM2 = 1
6568 esp_zb_lock_acquire (portMAX_DELAY);
66- esp_err_t ret = esp_zb_zcl_set_attribute_val (
69+ ret = esp_zb_zcl_set_attribute_val (
6770 _endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_ZONESTATUS_ID, &open, false
6871 );
6972 esp_zb_lock_release ();
70- if (ret != ESP_OK ) {
71- log_e (" Failed to set contact switch to open: 0x%x: %s" , ret, esp_err_to_name (ret));
73+ if (ret != ESP_ZB_ZCL_STATUS_SUCCESS ) {
74+ log_e (" Failed to set contact switch to open: 0x%x: %s" , ret, esp_zb_zcl_status_to_name (ret));
7275 return false ;
7376 }
7477 _zone_status = open;
@@ -90,13 +93,9 @@ bool ZigbeeContactSwitch::report() {
9093 status_change_notif_cmd.delay = 0 ;
9194
9295 esp_zb_lock_acquire (portMAX_DELAY);
93- esp_err_t ret = esp_zb_zcl_ias_zone_status_change_notif_cmd_req (&status_change_notif_cmd);
96+ uint8_t tsn = esp_zb_zcl_ias_zone_status_change_notif_cmd_req (&status_change_notif_cmd);
9497 esp_zb_lock_release ();
95- if (ret != ESP_OK) {
96- log_e (" Failed to send IAS Zone status changed notification: 0x%x: %s" , ret, esp_err_to_name (ret));
97- return false ;
98- }
99- log_v (" IAS Zone status changed notification sent" );
98+ log_v (" IAS Zone status changed notification sent with transaction sequence number: %u" , tsn);
10099 return true ;
101100}
102101
@@ -115,11 +114,25 @@ void ZigbeeContactSwitch::zbIASZoneEnrollResponse(const esp_zb_zcl_ias_zone_enro
115114 );
116115 esp_zb_lock_release ();
117116 _zone_id = message->zone_id ;
117+ _enrolled = true ;
118118 }
119-
120119 } else {
121120 log_w (" Received message ignored. Cluster ID: %d not supported for On/Off Light" , message->info .cluster );
122121 }
123122}
124123
124+ bool ZigbeeContactSwitch::requestIASZoneEnroll () {
125+ esp_zb_zcl_ias_zone_enroll_request_cmd_t enroll_request;
126+ enroll_request.zcl_basic_cmd .src_endpoint = _endpoint;
127+ enroll_request.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
128+ enroll_request.zone_type = ESP_ZB_ZCL_IAS_ZONE_ZONETYPE_CONTACT_SWITCH;
129+ enroll_request.manuf_code = 0 ;
130+
131+ esp_zb_lock_acquire (portMAX_DELAY);
132+ uint8_t tsn = esp_zb_zcl_ias_zone_enroll_cmd_req (&enroll_request);
133+ esp_zb_lock_release ();
134+ log_v (" IAS Zone enroll request send with transaction sequence number: %u" , tsn);
135+ return true ;
136+ }
137+
125138#endif // CONFIG_ZB_ENABLED
0 commit comments