@@ -226,35 +226,35 @@ void ZigbeeOccupancySensor::zbAttributeSet(const esp_zb_zcl_set_attr_value_messa
226226 if (message->info .cluster == ESP_ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING) {
227227 // PIR
228228 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 ;
230230 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PIR);
231231 } 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 ;
233233 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PIR);
234234 } 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 ;
236236 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PIR);
237237 }
238238 // Ultrasonic
239239 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 ;
241241 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_ULTRASONIC);
242242 } 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 ;
244244 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_ULTRASONIC);
245245 } 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 ;
247247 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_ULTRASONIC);
248248 }
249249 // Physical Contact
250250 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 ;
252252 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PHYSICAL_CONTACT);
253253 } 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 ;
255255 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PHYSICAL_CONTACT);
256256 } 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 ;
258258 occupancyConfigChanged (ZIGBEE_OCCUPANCY_SENSOR_TYPE_PHYSICAL_CONTACT);
259259 } else {
260260 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
266266
267267void ZigbeeOccupancySensor::occupancyConfigChanged (ZigbeeOccupancySensorType sensor_type) {
268268 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+ }
270283 } else {
271284 log_w (" No callback function set for occupancy config change" );
272285 }
0 commit comments