4
4
5
5
#include " esp_zigbee_cluster.h"
6
6
7
- ZigbeeDimmableLight::ZigbeeDimmableLight (uint8_t endpoint) : ZigbeeEP(endpoint)
8
- {
7
+ ZigbeeDimmableLight::ZigbeeDimmableLight (uint8_t endpoint) : ZigbeeEP(endpoint) {
9
8
_device_id = ESP_ZB_HA_DIMMABLE_LIGHT_DEVICE_ID;
10
9
11
10
zigbee_dimmable_light_cfg_t light_cfg = ZIGBEE_DEFAULT_DIMMABLE_LIGHT_CONFIG ();
@@ -19,58 +18,41 @@ ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint)
19
18
}
20
19
21
20
// 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) {
24
22
// 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 ) {
31
26
_current_state = *(bool *)message->attribute .data .value ;
32
27
lightChanged ();
33
28
}
34
29
return ;
35
- }
36
- else
37
- {
30
+ } else {
38
31
log_w (" Received message ignored. Attribute ID: %d not supported for On/Off Light" , message->attribute .id );
39
32
}
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 ) {
47
36
_current_level = *(uint8_t *)message->attribute .data .value ;
48
37
lightChanged ();
49
38
}
50
39
return ;
51
- }
52
- else
53
- {
40
+ } else {
54
41
log_w (" Received message ignored. Attribute ID: %d not supported for Level Control" , message->attribute .id );
55
42
// TODO: implement more attributes -> includes/zcl/esp_zigbee_zcl_level.h
56
43
}
57
- }
58
- else
59
- {
44
+ } else {
60
45
log_w (" Received message ignored. Cluster ID: %d not supported for dimmable Light" , message->info .cluster );
61
46
}
62
47
}
63
48
64
- void ZigbeeDimmableLight::lightChanged ()
65
- {
66
- if (_on_light_change)
67
- {
49
+ void ZigbeeDimmableLight::lightChanged () {
50
+ if (_on_light_change) {
68
51
_on_light_change (_current_state, _current_level);
69
52
}
70
53
}
71
54
72
- void ZigbeeDimmableLight::setLight (bool state, uint8_t level)
73
- {
55
+ void ZigbeeDimmableLight::setLight (bool state, uint8_t level) {
74
56
// Update all attributes
75
57
_current_state = state;
76
58
_current_level = level;
@@ -81,25 +63,24 @@ void ZigbeeDimmableLight::setLight(bool state, uint8_t level)
81
63
esp_zb_lock_acquire (portMAX_DELAY);
82
64
// set on/off state
83
65
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
+ );
85
68
// set level
86
69
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
+ );
88
72
esp_zb_lock_release ();
89
73
}
90
74
91
- void ZigbeeDimmableLight::setLightState (bool state)
92
- {
75
+ void ZigbeeDimmableLight::setLightState (bool state) {
93
76
setLight (state, _current_level);
94
77
}
95
78
96
- void ZigbeeDimmableLight::setLightLevel (uint8_t level)
97
- {
79
+ void ZigbeeDimmableLight::setLightLevel (uint8_t level) {
98
80
setLight (_current_state, level);
99
81
}
100
82
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) {
103
84
esp_zb_attribute_list_t *esp_zb_basic_cluster = esp_zb_basic_cluster_create (&light_cfg->basic_cfg );
104
85
esp_zb_attribute_list_t *esp_zb_identify_cluster = esp_zb_identify_cluster_create (&light_cfg->identify_cfg );
105
86
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
119
100
return esp_zb_cluster_list;
120
101
}
121
102
122
- #endif // SOC_IEEE802154_SUPPORTED
103
+ #endif // SOC_IEEE802154_SUPPORTED
0 commit comments