Skip to content

Commit 9560a8a

Browse files
committed
feat(zigbee): Illumanance sensor update
1 parent 8a0f8df commit 9560a8a

File tree

5 files changed

+18
-34
lines changed

5 files changed

+18
-34
lines changed

libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp

+12-20
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,28 @@
44
ZigbeeIlluminanceSensor::ZigbeeIlluminanceSensor(uint8_t endpoint) : ZigbeeEP(endpoint) {
55
_device_id = ESP_ZB_HA_LIGHT_SENSOR_DEVICE_ID;
66

7-
esp_zb_light_sensor_cfg_t light_sensor_cfg = ESP_ZB_DEFAULT_LIGHT_SENSOR_CONFIG();
7+
esp_zb_light_sensor_cfg_t light_sensor_cfg = ESP_ZB_DEFAULT_ILLUMINANCE_SENSOR_CONFIG();
88
_cluster_list = esp_zb_light_sensor_clusters_create(&light_sensor_cfg);
99

1010
_ep_config = {
1111
.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_LIGHT_SENSOR_DEVICE_ID, .app_device_version = 0
1212
};
1313
}
1414

15-
static int16_t zb_int_to_s16(int value) {
16-
return (int16_t) value;
17-
}
18-
19-
void ZigbeeIlluminanceSensor::setMinMaxValue(int min, int max) {
20-
int16_t zb_min = zb_int_to_s16(min);
21-
int16_t zb_max = zb_int_to_s16(max);
15+
void ZigbeeIlluminanceSensor::setMinMaxValue(uint16_t min, uint16_t max) {
2216
esp_zb_attribute_list_t *light_measure_cluster =
2317
esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
24-
esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_ID, (void *)&zb_min);
25-
esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&zb_max);
18+
esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_ID, (void *)&min);
19+
esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&max);
2620
}
2721

28-
void ZigbeeIlluminanceSensor::setTolerance(int tolerance) {
29-
uint16_t zb_tolerance = (uint16_t) tolerance;
22+
void ZigbeeIlluminanceSensor::setTolerance(uint16_t tolerance) {
3023
esp_zb_attribute_list_t *light_measure_cluster =
3124
esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
32-
esp_zb_illuminance_meas_cluster_add_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_TOLERANCE_ID, (void *)&zb_tolerance);
25+
esp_zb_illuminance_meas_cluster_add_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_TOLERANCE_ID, (void *)&tolerance);
3326
}
3427

35-
void ZigbeeIlluminanceSensor::setReporting(uint16_t min_interval, uint16_t max_interval, int delta) {
28+
void ZigbeeIlluminanceSensor::setReporting(uint16_t min_interval, uint16_t max_interval, uint16_t delta) {
3629
esp_zb_zcl_reporting_info_t reporting_info;
3730
memset(&reporting_info, 0, sizeof(esp_zb_zcl_reporting_info_t));
3831
reporting_info.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV;
@@ -44,27 +37,26 @@ void ZigbeeIlluminanceSensor::setReporting(uint16_t min_interval, uint16_t max_i
4437
reporting_info.u.send_info.max_interval = max_interval;
4538
reporting_info.u.send_info.def_min_interval = min_interval;
4639
reporting_info.u.send_info.def_max_interval = max_interval;
47-
reporting_info.u.send_info.delta.u16 = (uint16_t) delta;
40+
reporting_info.u.send_info.delta.u16 = delta;
4841
reporting_info.dst.profile_id = ESP_ZB_AF_HA_PROFILE_ID;
4942
reporting_info.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC;
5043
esp_zb_lock_acquire(portMAX_DELAY);
5144
esp_zb_zcl_update_reporting_info(&reporting_info);
5245
esp_zb_lock_release();
5346
}
5447

55-
void ZigbeeIlluminanceSensor::setIlluminance(int illuminanceValue) {
56-
int16_t zb_illuminanceValue = zb_int_to_s16(illuminanceValue);
48+
void ZigbeeIlluminanceSensor::setIlluminance(uint16_t illuminanceValue) {
5749
log_v("Updating Illuminance...");
5850
/* Update illuminance sensor measured illuminance */
59-
log_d("Setting Illuminance to %d", zb_illuminanceValue);
51+
log_d("Setting Illuminance to %d", illuminanceValue);
6052
esp_zb_lock_acquire(portMAX_DELAY);
6153
esp_zb_zcl_set_attribute_val(
62-
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_ID, &zb_illuminanceValue, false
54+
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_ID, &illuminanceValue, false
6355
);
6456
esp_zb_lock_release();
6557
}
6658

67-
void ZigbeeIlluminanceSensor::reportIlluminance() {
59+
void ZigbeeIlluminanceSensor::report() {
6860
/* Send report attributes command */
6961
esp_zb_zcl_report_attr_cmd_t report_attr_cmd;
7062
report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;

libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.h

+6-14
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
#include "ZigbeeEP.h"
1010
#include "ha/esp_zigbee_ha_standard.h"
1111

12-
/*
13-
the new macro works here, but should better be added to
14-
esp-zigbee-sdk/components/esp-zigbee-lib/include/ha/esp_zigbee_ha_standard.h
15-
*/
16-
#define ESP_ZB_DEFAULT_LIGHT_SENSOR_CONFIG() \
12+
#define ESP_ZB_DEFAULT_ILLUMINANCE_SENSOR_CONFIG() \
1713
{ \
1814
.basic_cfg = \
1915
{ \
@@ -27,10 +23,6 @@ esp-zigbee-sdk/components/esp-zigbee-lib/include/ha/esp_zigbee_ha_standard.h
2723
.illuminance_cfg = \
2824
{ \
2925
.measured_value = ESP_ZB_ZCL_ILLUMINANCE_MEASUREMENT_LIGHT_SENSOR_TYPE_DEFAULT_VALUE, \
30-
/*not sure with next two values, but there are no*/ \
31-
/*ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_DEFAULT and*/ \
32-
/*ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_DEFAULT*/ \
33-
/*thats why I chose MIN_VALUE and MAX_VALUE*/ \
3426
.min_value = ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_MIN_VALUE, \
3527
.max_value = ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_MAX_VALUE, \
3628
}, \
@@ -42,19 +34,19 @@ class ZigbeeIlluminanceSensor : public ZigbeeEP {
4234
~ZigbeeIlluminanceSensor() {}
4335

4436
// Set the illuminance value
45-
void setIlluminance(int value);
37+
void setIlluminance(uint16_t value);
4638

4739
// Set the min and max value for the illuminance sensor
48-
void setMinMaxValue(int min, int max);
40+
void setMinMaxValue(uint16_t min, uint16_t max);
4941

5042
// Set the tolerance value for the illuminance sensor
51-
void setTolerance(int tolerance);
43+
void setTolerance(uint16_t tolerance);
5244

5345
// Set the reporting interval for illuminance measurement in seconds and delta
54-
void setReporting(uint16_t min_interval, uint16_t max_interval, int delta);
46+
void setReporting(uint16_t min_interval, uint16_t max_interval, uint16_t delta);
5547

5648
// Report the illuminance value
57-
void reportIlluminance();
49+
void report();
5850
};
5951

6052
#endif // CONFIG_ZB_ENABLED

0 commit comments

Comments
 (0)