@@ -226,35 +226,35 @@ void ZigbeeOccupancySensor::zbAttributeSet(const esp_zb_zcl_set_attr_value_messa
226
226
if (message->info .cluster == ESP_ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING) {
227
227
// PIR
228
228
if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_PIR_OCC_TO_UNOCC_DELAY_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
229
- uint16_t pir_occ_to_unocc_delay = *(uint16_t *)message->attribute .data .value ;
229
+ _pir_occ_to_unocc_delay = *(uint16_t *)message->attribute .data .value ;
230
230
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PIR);
231
231
} else if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_PIR_UNOCC_TO_OCC_DELAY_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
232
- uint16_t pir_unocc_to_occ_delay = *(uint16_t *)message->attribute .data .value ;
232
+ _pir_unocc_to_occ_delay = *(uint16_t *)message->attribute .data .value ;
233
233
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PIR);
234
234
} else if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_PIR_UNOCC_TO_OCC_THRESHOLD_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U8) {
235
- uint8_t pir_unocc_to_occ_threshold = *(uint8_t *)message->attribute .data .value ;
235
+ _pir_unocc_to_occ_threshold = *(uint8_t *)message->attribute .data .value ;
236
236
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PIR);
237
237
}
238
238
// Ultrasonic
239
239
else if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_ULTRASONIC_OCCUPIED_TO_UNOCCUPIED_DELAY_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
240
- uint16_t ultrasonic_occ_to_unocc_delay = *(uint16_t *)message->attribute .data .value ;
240
+ _ultrasonic_occ_to_unocc_delay = *(uint16_t *)message->attribute .data .value ;
241
241
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_ULTRASONIC);
242
242
} else if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_ULTRASONIC_UNOCCUPIED_TO_OCCUPIED_DELAY_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
243
- uint16_t ultrasonic_unocc_to_occ_delay = *(uint16_t *)message->attribute .data .value ;
243
+ _ultrasonic_unocc_to_occ_delay = *(uint16_t *)message->attribute .data .value ;
244
244
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_ULTRASONIC);
245
245
} else if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_ULTRASONIC_UNOCCUPIED_TO_OCCUPIED_THRESHOLD_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U8) {
246
- uint8_t ultrasonic_unocc_to_occ_threshold = *(uint8_t *)message->attribute .data .value ;
246
+ _ultrasonic_unocc_to_occ_threshold = *(uint8_t *)message->attribute .data .value ;
247
247
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_ULTRASONIC);
248
248
}
249
249
// Physical Contact
250
250
else if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_PHYSICAL_CONTACT_OCCUPIED_TO_UNOCCUPIED_DELAY_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
251
- uint16_t physical_contact_occ_to_unocc_delay = *(uint16_t *)message->attribute .data .value ;
251
+ _physical_contact_occ_to_unocc_delay = *(uint16_t *)message->attribute .data .value ;
252
252
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PHYSICAL_CONTACT);
253
253
} else if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_PHYSICAL_CONTACT_UNOCCUPIED_TO_OCCUPIED_DELAY_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
254
- uint16_t physical_contact_unocc_to_occ_delay = *(uint16_t *)message->attribute .data .value ;
254
+ _physical_contact_unocc_to_occ_delay = *(uint16_t *)message->attribute .data .value ;
255
255
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PHYSICAL_CONTACT);
256
256
} else if (message->attribute .id == ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_PHYSICAL_CONTACT_UNOCCUPIED_TO_OCCUPIED_THRESHOLD_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U8) {
257
- uint8_t physical_contact_unocc_to_occ_threshold = *(uint8_t *)message->attribute .data .value ;
257
+ _physical_contact_unocc_to_occ_threshold = *(uint8_t *)message->attribute .data .value ;
258
258
occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PHYSICAL_CONTACT);
259
259
} else {
260
260
log_w (" Received message ignored. Attribute ID: %d not supported for Occupancy Sensor endpoint" , message->attribute .id );
@@ -266,7 +266,20 @@ void ZigbeeOccupancySensor::zbAttributeSet(const esp_zb_zcl_set_attr_value_messa
266
266
267
267
void ZigbeeOccupancySensor::occupancyConfigChanged (ZigbeeOccupancySensorType sensor_type) {
268
268
if (_on_occupancy_config_change) {
269
- _on_occupancy_config_change (sensor_type); // sensor type, delay, delay, threshold
269
+ switch (sensor_type) {
270
+ case ZIGBEE_OCCUPANCY_SENSOR_TYPE_PIR:
271
+ _on_occupancy_config_change (sensor_type, _pir_occ_to_unocc_delay, _pir_unocc_to_occ_delay, _pir_unocc_to_occ_threshold);
272
+ break ;
273
+ case ZIGBEE_OCCUPANCY_SENSOR_TYPE_ULTRASONIC:
274
+ _on_occupancy_config_change (sensor_type, _ultrasonic_occ_to_unocc_delay, _ultrasonic_unocc_to_occ_delay, _ultrasonic_unocc_to_occ_threshold);
275
+ break ;
276
+ case ZIGBEE_OCCUPANCY_SENSOR_TYPE_PHYSICAL_CONTACT:
277
+ _on_occupancy_config_change (sensor_type, _physical_contact_occ_to_unocc_delay, _physical_contact_unocc_to_occ_delay, _physical_contact_unocc_to_occ_threshold);
278
+ break ;
279
+ default :
280
+ log_e (" Invalid sensor type for occupancy config change: 0x%x" , sensor_type);
281
+ break ;
282
+ }
270
283
} else {
271
284
log_w (" No callback function set for occupancy config change" );
272
285
}
0 commit comments