@@ -34,10 +34,10 @@ ZigbeeMultistate::ZigbeeMultistate(uint8_t endpoint) : ZigbeeEP(endpoint) {
34
34
_multistate_clusters = 0 ;
35
35
_input_state = 0 ;
36
36
_output_state = 0 ;
37
- _input_state_names = nullptr ;
38
37
_input_state_names_length = 0 ;
39
- _output_state_names = nullptr ;
40
38
_output_state_names_length = 0 ;
39
+ // _input_state_names = nullptr;
40
+ // _output_state_names = nullptr;
41
41
_on_multistate_output_change = nullptr ;
42
42
}
43
43
@@ -55,25 +55,25 @@ bool ZigbeeMultistate::addMultistateInput() {
55
55
char default_description[] = " \x10 " // Size of the description text
56
56
" Multistate Input" ; // Description text
57
57
uint32_t application_type = 0x00000000 | (0x0D << 24 ); // Application type
58
- const char * state_text[] = { " Off" , " On" , " Auto" }; // State text array
58
+ // const char* state_text[] = { "Off", "On", "Auto" }; // State text array
59
59
60
- esp_err_t ret = esp_zb_multistate_input_cluster_add_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_DESCRIPTION_ID , (void *)default_description);
60
+ esp_err_t ret = esp_zb_multistate_input_cluster_add_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTI_INPUT_DESCRIPTION_ID , (void *)default_description);
61
61
if (ret != ESP_OK) {
62
62
log_e (" Failed to add description attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
63
63
return false ;
64
64
}
65
65
66
- ret = esp_zb_multistate_input_cluster_add_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_APPLICATION_TYPE_ID , (void *)&application_type);
66
+ ret = esp_zb_multistate_input_cluster_add_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTI_INPUT_APPLICATION_TYPE_ID , (void *)&application_type);
67
67
if (ret != ESP_OK) {
68
68
log_e (" Failed to add application type attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
69
69
return false ;
70
70
}
71
71
72
- ret = esp_zb_multistate_input_cluster_add_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_STATE_TEXT_ID , (void *)state_text);
73
- if (ret != ESP_OK) {
74
- log_e (" Failed to add state text attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
75
- return false ;
76
- }
72
+ // ret = esp_zb_multistate_input_cluster_add_attr(multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTI_INPUT_STATE_TEXT_ID , (void *)state_text);
73
+ // if (ret != ESP_OK) {
74
+ // log_e("Failed to add state text attribute: 0x%x: %s", ret, esp_err_to_name(ret));
75
+ // return false;
76
+ // }
77
77
78
78
ret = esp_zb_cluster_list_add_multistate_input_cluster (_cluster_list, multistate_input_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
79
79
if (ret != ESP_OK) {
@@ -102,23 +102,23 @@ bool ZigbeeMultistate::addMultistateOutput() {
102
102
const char * state_text[] = { " Off" , " On" , " Auto" }; // State text array
103
103
uint16_t num_states = 3 ; // Number of states
104
104
105
- esp_err_t ret = esp_zb_multistate_output_cluster_add_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_DESCRIPTION_ID , (void *)default_description);
105
+ esp_err_t ret = esp_zb_multistate_output_cluster_add_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_DESCRIPTION_ID , (void *)default_description);
106
106
if (ret != ESP_OK) {
107
107
log_e (" Failed to add description attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
108
108
return false ;
109
109
}
110
110
111
- ret = esp_zb_multistate_output_cluster_add_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_APPLICATION_TYPE_ID , (void *)&application_type);
111
+ ret = esp_zb_multistate_output_cluster_add_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_APPLICATION_TYPE_ID , (void *)&application_type);
112
112
if (ret != ESP_OK) {
113
113
log_e (" Failed to add application type attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
114
114
return false ;
115
115
}
116
116
117
- ret = esp_zb_multistate_output_cluster_add_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_STATE_TEXT_ID , (void *)state_text);
118
- if (ret != ESP_OK) {
119
- log_e (" Failed to add state text attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
120
- return false ;
121
- }
117
+ // ret = esp_zb_multistate_output_cluster_add_attr(multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_STATE_TEXT_ID , (void *)state_text);
118
+ // if (ret != ESP_OK) {
119
+ // log_e("Failed to add state text attribute: 0x%x: %s", ret, esp_err_to_name(ret));
120
+ // return false;
121
+ // }
122
122
123
123
ret = esp_zb_cluster_list_add_multistate_output_cluster (_cluster_list, multistate_output_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
124
124
if (ret != ESP_OK) {
@@ -141,7 +141,7 @@ bool ZigbeeMultistate::setMultistateInputApplication(uint32_t application_type)
141
141
142
142
esp_zb_attribute_list_t *multistate_input_cluster =
143
143
esp_zb_cluster_list_get_cluster (_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_MULTI_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
144
- esp_err_t ret = esp_zb_cluster_update_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_APPLICATION_TYPE_ID , (void *)&application_type_value);
144
+ esp_err_t ret = esp_zb_cluster_update_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTI_INPUT_APPLICATION_TYPE_ID , (void *)&application_type_value);
145
145
if (ret != ESP_OK) {
146
146
log_e (" Failed to set Multistate Input application type: 0x%x: %s" , ret, esp_err_to_name (ret));
147
147
return false ;
@@ -160,7 +160,7 @@ bool ZigbeeMultistate::setMultistateOutputApplication(uint32_t application_type)
160
160
161
161
esp_zb_attribute_list_t *multistate_output_cluster =
162
162
esp_zb_cluster_list_get_cluster (_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_MULTI_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
163
- esp_err_t ret = esp_zb_cluster_update_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_APPLICATION_TYPE_ID , (void *)&application_type_value);
163
+ esp_err_t ret = esp_zb_cluster_update_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_APPLICATION_TYPE_ID , (void *)&application_type_value);
164
164
if (ret != ESP_OK) {
165
165
log_e (" Failed to set Multistate Output application type: 0x%x: %s" , ret, esp_err_to_name (ret));
166
166
return false ;
@@ -200,7 +200,7 @@ bool ZigbeeMultistate::setMultistateInputDescription(const char *description) {
200
200
zb_description[description_length + 1 ] = ' \0 ' ;
201
201
202
202
// Update the description attribute
203
- esp_err_t ret = esp_zb_cluster_update_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_DESCRIPTION_ID , (void *)zb_description);
203
+ esp_err_t ret = esp_zb_cluster_update_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTI_INPUT_DESCRIPTION_ID , (void *)zb_description);
204
204
if (ret != ESP_OK) {
205
205
log_e (" Failed to set description: 0x%x: %s" , ret, esp_err_to_name (ret));
206
206
return false ;
@@ -240,14 +240,62 @@ bool ZigbeeMultistate::setMultistateOutputDescription(const char *description) {
240
240
zb_description[description_length + 1 ] = ' \0 ' ;
241
241
242
242
// Update the description attribute
243
- esp_err_t ret = esp_zb_cluster_update_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_DESCRIPTION_ID , (void *)zb_description);
243
+ esp_err_t ret = esp_zb_cluster_update_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_DESCRIPTION_ID , (void *)zb_description);
244
244
if (ret != ESP_OK) {
245
245
log_e (" Failed to set description: 0x%x: %s" , ret, esp_err_to_name (ret));
246
246
return false ;
247
247
}
248
248
return true ;
249
249
}
250
250
251
+ bool ZigbeeMultistate::setMultistateInputStates (uint16_t number_of_states) {
252
+ if (!(_multistate_clusters & MULTISTATE_INPUT)) {
253
+ log_e (" Multistate Input cluster not added" );
254
+ return false ;
255
+ }
256
+
257
+ esp_zb_attribute_list_t *multistate_input_cluster =
258
+ esp_zb_cluster_list_get_cluster (_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_MULTI_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
259
+ if (multistate_input_cluster == nullptr ) {
260
+ log_e (" Failed to get multistate input cluster" );
261
+ return false ;
262
+ }
263
+
264
+ esp_err_t ret = esp_zb_cluster_update_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTI_INPUT_NUMBER_OF_STATES_ID, (void *)&number_of_states);
265
+ if (ret != ESP_OK) {
266
+ log_e (" Failed to set number of states: 0x%x: %s" , ret, esp_err_to_name (ret));
267
+ return false ;
268
+ }
269
+
270
+ _input_state_names_length = number_of_states;
271
+ return true ;
272
+ }
273
+
274
+ bool ZigbeeMultistate::setMultistateOutputStates (uint16_t number_of_states) {
275
+ if (!(_multistate_clusters & MULTISTATE_OUTPUT)) {
276
+ log_e (" Multistate Output cluster not added" );
277
+ return false ;
278
+ }
279
+
280
+ esp_zb_attribute_list_t *multistate_output_cluster =
281
+ esp_zb_cluster_list_get_cluster (_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_MULTI_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
282
+ if (multistate_output_cluster == nullptr ) {
283
+ log_e (" Failed to get multistate output cluster" );
284
+ return false ;
285
+ }
286
+
287
+ esp_err_t ret = esp_zb_cluster_update_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_NUMBER_OF_STATES_ID, (void *)&number_of_states);
288
+ if (ret != ESP_OK) {
289
+ log_e (" Failed to set number of states: 0x%x: %s" , ret, esp_err_to_name (ret));
290
+ return false ;
291
+ }
292
+
293
+ _output_state_names_length = number_of_states;
294
+ return true ;
295
+ }
296
+
297
+ /* TODO: revisit this after arrays are supported
298
+
251
299
bool ZigbeeMultistate::setMultistateInputStates(const char * const states[], uint16_t states_length) {
252
300
if (!(_multistate_clusters & MULTISTATE_INPUT)) {
253
301
log_e("Multistate Input cluster not added");
@@ -261,12 +309,12 @@ bool ZigbeeMultistate::setMultistateInputStates(const char * const states[], uin
261
309
return false;
262
310
}
263
311
264
- esp_err_t ret = esp_zb_cluster_update_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_STATE_TEXT_ID , (void *)states);
312
+ esp_err_t ret = esp_zb_cluster_update_attr(multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTI_INPUT_STATE_TEXT_ID , (void *)states);
265
313
if (ret != ESP_OK) {
266
314
log_e("Failed to set states text: 0x%x: %s", ret, esp_err_to_name(ret));
267
315
return false;
268
316
}
269
- ret = esp_zb_cluster_update_attr (multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_NUMBER_OF_STATES_ID , (void *)&states_length);
317
+ ret = esp_zb_cluster_update_attr(multistate_input_cluster, ESP_ZB_ZCL_ATTR_MULTI_INPUT_NUMBER_OF_STATES_ID , (void *)&states_length);
270
318
if (ret != ESP_OK) {
271
319
log_e("Failed to set number of states: 0x%x: %s", ret, esp_err_to_name(ret));
272
320
return false;
@@ -291,12 +339,12 @@ bool ZigbeeMultistate::setMultistateOutputStates(const char * const states[], ui
291
339
return false;
292
340
}
293
341
294
- esp_err_t ret = esp_zb_cluster_update_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_STATE_TEXT_ID , (void *)states);
342
+ esp_err_t ret = esp_zb_cluster_update_attr(multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_STATE_TEXT_ID , (void *)states);
295
343
if (ret != ESP_OK) {
296
344
log_e("Failed to set states text: 0x%x: %s", ret, esp_err_to_name(ret));
297
345
return false;
298
346
}
299
- ret = esp_zb_cluster_update_attr (multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_NUMBER_OF_STATES_ID , (void *)&states_length);
347
+ ret = esp_zb_cluster_update_attr(multistate_output_cluster, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_NUMBER_OF_STATES_ID , (void *)&states_length);
300
348
if (ret != ESP_OK) {
301
349
log_e("Failed to set number of states: 0x%x: %s", ret, esp_err_to_name(ret));
302
350
return false;
@@ -307,11 +355,12 @@ bool ZigbeeMultistate::setMultistateOutputStates(const char * const states[], ui
307
355
_output_state_names_length = states_length;
308
356
return true;
309
357
}
358
+ */
310
359
311
360
// set attribute method -> method overridden in child class
312
361
void ZigbeeMultistate::zbAttributeSet (const esp_zb_zcl_set_attr_value_message_t *message) {
313
362
if (message->info .cluster == ESP_ZB_ZCL_CLUSTER_ID_MULTI_OUTPUT) {
314
- if (message->attribute .id == ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_PRESENT_VALUE_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
363
+ if (message->attribute .id == ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_PRESENT_VALUE_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
315
364
_output_state = *(uint16_t *)message->attribute .data .value ;
316
365
multistateOutputChanged ();
317
366
} else {
@@ -339,7 +388,7 @@ bool ZigbeeMultistate::setMultistateInput(uint16_t state) {
339
388
log_d (" Setting multistate input to %d" , state);
340
389
esp_zb_lock_acquire (portMAX_DELAY);
341
390
ret = esp_zb_zcl_set_attribute_val (
342
- _endpoint, ESP_ZB_ZCL_CLUSTER_ID_MULTI_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_PRESENT_VALUE_ID , &state, false
391
+ _endpoint, ESP_ZB_ZCL_CLUSTER_ID_MULTI_INPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_MULTI_INPUT_PRESENT_VALUE_ID , &state, false
343
392
);
344
393
esp_zb_lock_release ();
345
394
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
@@ -358,7 +407,7 @@ bool ZigbeeMultistate::setMultistateOutput(uint16_t state) {
358
407
/* Update multistate output */
359
408
esp_zb_lock_acquire (portMAX_DELAY);
360
409
ret = esp_zb_zcl_set_attribute_val (
361
- _endpoint, ESP_ZB_ZCL_CLUSTER_ID_MULTI_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_PRESENT_VALUE_ID , &_output_state, false
410
+ _endpoint, ESP_ZB_ZCL_CLUSTER_ID_MULTI_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_PRESENT_VALUE_ID , &_output_state, false
362
411
);
363
412
esp_zb_lock_release ();
364
413
@@ -373,7 +422,7 @@ bool ZigbeeMultistate::reportMultistateInput() {
373
422
/* Send report attributes command */
374
423
esp_zb_zcl_report_attr_cmd_t report_attr_cmd;
375
424
report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
376
- report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_MULTISTATE_INPUT_PRESENT_VALUE_ID ;
425
+ report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_MULTI_INPUT_PRESENT_VALUE_ID ;
377
426
report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI;
378
427
report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_MULTI_INPUT;
379
428
report_attr_cmd.zcl_basic_cmd .src_endpoint = _endpoint;
@@ -394,7 +443,7 @@ bool ZigbeeMultistate::reportMultistateOutput() {
394
443
/* Send report attributes command */
395
444
esp_zb_zcl_report_attr_cmd_t report_attr_cmd;
396
445
report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
397
- report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_MULTISTATE_OUTPUT_PRESENT_VALUE_ID ;
446
+ report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_MULTI_OUTPUT_PRESENT_VALUE_ID ;
398
447
report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI;
399
448
report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_MULTI_OUTPUT;
400
449
report_attr_cmd.zcl_basic_cmd .src_endpoint = _endpoint;
0 commit comments