Skip to content

Commit 082313d

Browse files
committed
feat(zigbee): Update checking logic
1 parent c38a689 commit 082313d

File tree

4 files changed

+62
-31
lines changed

4 files changed

+62
-31
lines changed

libraries/Zigbee/src/ep/ZigbeeContactSwitch.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,26 @@ bool ZigbeeContactSwitch::requestIASZoneEnroll() {
137137

138138
bool ZigbeeContactSwitch::restoreIASZoneEnroll() {
139139
esp_zb_lock_acquire(portMAX_DELAY);
140-
memcpy(
141-
_ias_cie_addr,
142-
(*(esp_zb_ieee_addr_t *)
143-
esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID)
144-
->data_p),
145-
sizeof(esp_zb_ieee_addr_t)
146-
);
147-
_zone_id = (*(uint8_t *)
148-
esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID)
149-
->data_p);
140+
esp_zb_zcl_attr_t *ias_cie_attr = esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID);
141+
esp_zb_zcl_attr_t *zone_id_attr = esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID);
150142
esp_zb_lock_release();
151143

144+
if (ias_cie_attr == NULL || ias_cie_attr->data_p == NULL) {
145+
log_e("Failed to restore IAS Zone enroll: ias cie address attribute not found");
146+
return false;
147+
}
148+
if (zone_id_attr == NULL || zone_id_attr->data_p == NULL) {
149+
log_e("Failed to restore IAS Zone enroll: zone id attribute not found");
150+
return false;
151+
}
152+
153+
memcpy(_ias_cie_addr, (*(esp_zb_ieee_addr_t *)ias_cie_attr->data_p), sizeof(esp_zb_ieee_addr_t));
154+
_zone_id = (*(uint8_t *)zone_id_attr->data_p);
155+
152156
log_d("Restored IAS Zone enroll: zone id(%d), ias cie address(%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X)", _zone_id, _ias_cie_addr[0], _ias_cie_addr[1], _ias_cie_addr[2], _ias_cie_addr[3], _ias_cie_addr[4], _ias_cie_addr[5], _ias_cie_addr[6], _ias_cie_addr[7]);
153157

154158
if (_zone_id == 0xFF) {
155-
log_e("Failed to restore IAS Zone enroll: zone id not found");
156-
return false;
157-
}
158-
if (_ias_cie_addr == NULL) {
159-
log_e("Failed to restore IAS Zone enroll: ias cie address not found");
159+
log_e("Failed to restore IAS Zone enroll: zone id not valid");
160160
return false;
161161
}
162162
_enrolled = true;

libraries/Zigbee/src/ep/ZigbeeDoorWindowHandle.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,32 @@ bool ZigbeeDoorWindowHandle::requestIASZoneEnroll() {
152152
return true;
153153
}
154154

155+
bool ZigbeeDoorWindowHandle::restoreIASZoneEnroll() {
156+
esp_zb_lock_acquire(portMAX_DELAY);
157+
esp_zb_zcl_attr_t *ias_cie_attr = esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID);
158+
esp_zb_zcl_attr_t *zone_id_attr = esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID);
159+
esp_zb_lock_release();
160+
161+
if (ias_cie_attr == NULL || ias_cie_attr->data_p == NULL) {
162+
log_e("Failed to restore IAS Zone enroll: ias cie address attribute not found");
163+
return false;
164+
}
165+
if (zone_id_attr == NULL || zone_id_attr->data_p == NULL) {
166+
log_e("Failed to restore IAS Zone enroll: zone id attribute not found");
167+
return false;
168+
}
169+
170+
memcpy(_ias_cie_addr, (*(esp_zb_ieee_addr_t *)ias_cie_attr->data_p), sizeof(esp_zb_ieee_addr_t));
171+
_zone_id = (*(uint8_t *)zone_id_attr->data_p);
172+
173+
log_d("Restored IAS Zone enroll: zone id(%d), ias cie address(%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X)", _zone_id, _ias_cie_addr[0], _ias_cie_addr[1], _ias_cie_addr[2], _ias_cie_addr[3], _ias_cie_addr[4], _ias_cie_addr[5], _ias_cie_addr[6], _ias_cie_addr[7]);
174+
175+
if (_zone_id == 0xFF) {
176+
log_e("Failed to restore IAS Zone enroll: zone id not valid");
177+
return false;
178+
}
179+
_enrolled = true;
180+
return true;
181+
}
182+
155183
#endif // CONFIG_ZB_ENABLED

libraries/Zigbee/src/ep/ZigbeeDoorWindowHandle.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ class ZigbeeDoorWindowHandle : public ZigbeeEP {
7474
// Report the door/window handle value, done automatically after setting the position
7575
bool report();
7676

77-
// Request a new IAS zone enroll, needed to be called after rebooting already configured device
77+
// Request a new IAS zone enroll, can be called to enroll a new device or to re-enroll an already enrolled device
7878
bool requestIASZoneEnroll();
7979

80+
// Restore IAS Zone enroll, needed to be called after rebooting already enrolled device - restored from flash memory (faster for sleepy devices)
81+
bool restoreIASZoneEnroll();
82+
8083
// Check if the device is enrolled in the IAS Zone
8184
bool enrolled() { return _enrolled; }
8285

libraries/Zigbee/src/ep/ZigbeeVibrationSensor.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,26 @@ bool ZigbeeVibrationSensor::requestIASZoneEnroll() {
119119

120120
bool ZigbeeVibrationSensor::restoreIASZoneEnroll() {
121121
esp_zb_lock_acquire(portMAX_DELAY);
122-
memcpy(
123-
_ias_cie_addr,
124-
(*(esp_zb_ieee_addr_t *)
125-
esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID)
126-
->data_p),
127-
sizeof(esp_zb_ieee_addr_t)
128-
);
129-
_zone_id = (*(uint8_t *)
130-
esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID)
131-
->data_p);
122+
esp_zb_zcl_attr_t *ias_cie_attr = esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID);
123+
esp_zb_zcl_attr_t *zone_id_attr = esp_zb_zcl_get_attribute(_endpoint, ESP_ZB_ZCL_CLUSTER_ID_IAS_ZONE, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID);
132124
esp_zb_lock_release();
133125

126+
if (ias_cie_attr == NULL || ias_cie_attr->data_p == NULL) {
127+
log_e("Failed to restore IAS Zone enroll: ias cie address attribute not found");
128+
return false;
129+
}
130+
if (zone_id_attr == NULL || zone_id_attr->data_p == NULL) {
131+
log_e("Failed to restore IAS Zone enroll: zone id attribute not found");
132+
return false;
133+
}
134+
135+
memcpy(_ias_cie_addr, (*(esp_zb_ieee_addr_t *)ias_cie_attr->data_p), sizeof(esp_zb_ieee_addr_t));
136+
_zone_id = (*(uint8_t *)zone_id_attr->data_p);
137+
134138
log_d("Restored IAS Zone enroll: zone id(%d), ias cie address(%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X)", _zone_id, _ias_cie_addr[0], _ias_cie_addr[1], _ias_cie_addr[2], _ias_cie_addr[3], _ias_cie_addr[4], _ias_cie_addr[5], _ias_cie_addr[6], _ias_cie_addr[7]);
135139

136140
if (_zone_id == 0xFF) {
137-
log_e("Failed to restore IAS Zone enroll: zone id not found");
138-
return false;
139-
}
140-
if (_ias_cie_addr == NULL) {
141-
log_e("Failed to restore IAS Zone enroll: ias cie address not found");
141+
log_e("Failed to restore IAS Zone enroll: zone id not valid");
142142
return false;
143143
}
144144
_enrolled = true;

0 commit comments

Comments
 (0)