44
55#include " esp_zigbee_cluster.h"
66
7- ZigbeeDimmableLight::ZigbeeDimmableLight (uint8_t endpoint) : ZigbeeEP(endpoint)
8- {
7+ ZigbeeDimmableLight::ZigbeeDimmableLight (uint8_t endpoint) : ZigbeeEP(endpoint) {
98 _device_id = ESP_ZB_HA_DIMMABLE_LIGHT_DEVICE_ID;
109
1110 zigbee_dimmable_light_cfg_t light_cfg = ZIGBEE_DEFAULT_DIMMABLE_LIGHT_CONFIG ();
@@ -19,58 +18,41 @@ ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint)
1918}
2019
2120// set attribute method -> method overridden in child class
22- void ZigbeeDimmableLight::zbAttributeSet (const esp_zb_zcl_set_attr_value_message_t *message)
23- {
21+ void ZigbeeDimmableLight::zbAttributeSet (const esp_zb_zcl_set_attr_value_message_t *message) {
2422 // check the data and call right method
25- if (message->info .cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF)
26- {
27- if (message->attribute .id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_BOOL)
28- {
29- if (_current_state != *(bool *)message->attribute .data .value )
30- {
23+ if (message->info .cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) {
24+ if (message->attribute .id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) {
25+ if (_current_state != *(bool *)message->attribute .data .value ) {
3126 _current_state = *(bool *)message->attribute .data .value ;
3227 lightChanged ();
3328 }
3429 return ;
35- }
36- else
37- {
30+ } else {
3831 log_w (" Received message ignored. Attribute ID: %d not supported for On/Off Light" , message->attribute .id );
3932 }
40- }
41- else if (message->info .cluster == ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL)
42- {
43- if (message->attribute .id == ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U8)
44- {
45- if (_current_level != *(uint8_t *)message->attribute .data .value )
46- {
33+ } else if (message->info .cluster == ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL) {
34+ if (message->attribute .id == ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U8) {
35+ if (_current_level != *(uint8_t *)message->attribute .data .value ) {
4736 _current_level = *(uint8_t *)message->attribute .data .value ;
4837 lightChanged ();
4938 }
5039 return ;
51- }
52- else
53- {
40+ } else {
5441 log_w (" Received message ignored. Attribute ID: %d not supported for Level Control" , message->attribute .id );
5542 // TODO: implement more attributes -> includes/zcl/esp_zigbee_zcl_level.h
5643 }
57- }
58- else
59- {
44+ } else {
6045 log_w (" Received message ignored. Cluster ID: %d not supported for dimmable Light" , message->info .cluster );
6146 }
6247}
6348
64- void ZigbeeDimmableLight::lightChanged ()
65- {
66- if (_on_light_change)
67- {
49+ void ZigbeeDimmableLight::lightChanged () {
50+ if (_on_light_change) {
6851 _on_light_change (_current_state, _current_level);
6952 }
7053}
7154
72- void ZigbeeDimmableLight::setLight (bool state, uint8_t level)
73- {
55+ void ZigbeeDimmableLight::setLight (bool state, uint8_t level) {
7456 // Update all attributes
7557 _current_state = state;
7658 _current_level = level;
@@ -81,25 +63,24 @@ void ZigbeeDimmableLight::setLight(bool state, uint8_t level)
8163 esp_zb_lock_acquire (portMAX_DELAY);
8264 // set on/off state
8365 esp_zb_zcl_set_attribute_val (
84- _endpoint, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, &_current_state, false );
66+ _endpoint, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, &_current_state, false
67+ );
8568 // set level
8669 esp_zb_zcl_set_attribute_val (
87- _endpoint, ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, &_current_level, false );
70+ _endpoint, ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, &_current_level, false
71+ );
8872 esp_zb_lock_release ();
8973}
9074
91- void ZigbeeDimmableLight::setLightState (bool state)
92- {
75+ void ZigbeeDimmableLight::setLightState (bool state) {
9376 setLight (state, _current_level);
9477}
9578
96- void ZigbeeDimmableLight::setLightLevel (uint8_t level)
97- {
79+ void ZigbeeDimmableLight::setLightLevel (uint8_t level) {
9880 setLight (_current_state, level);
9981}
10082
101- esp_zb_cluster_list_t *ZigbeeDimmableLight::esp_zb_dimmable_light_clusters_create (zigbee_dimmable_light_cfg_t *light_cfg)
102- {
83+ esp_zb_cluster_list_t *ZigbeeDimmableLight::esp_zb_dimmable_light_clusters_create (zigbee_dimmable_light_cfg_t *light_cfg) {
10384 esp_zb_attribute_list_t *esp_zb_basic_cluster = esp_zb_basic_cluster_create (&light_cfg->basic_cfg );
10485 esp_zb_attribute_list_t *esp_zb_identify_cluster = esp_zb_identify_cluster_create (&light_cfg->identify_cfg );
10586 esp_zb_attribute_list_t *esp_zb_groups_cluster = esp_zb_groups_cluster_create (&light_cfg->groups_cfg );
@@ -119,4 +100,4 @@ esp_zb_cluster_list_t *ZigbeeDimmableLight::esp_zb_dimmable_light_clusters_creat
119100 return esp_zb_cluster_list;
120101}
121102
122- #endif // SOC_IEEE802154_SUPPORTED
103+ #endif // SOC_IEEE802154_SUPPORTED
0 commit comments