@@ -2317,9 +2317,29 @@ static sl_status_t zwave_command_class_user_credential_user_get(
23172317 sl_status_t status
23182318 = attribute_store_get_desired (node, &user_id, sizeof (user_id));
23192319
2320+ // If we enter this state it means that something went badly wrong or
2321+ // user initiate the interview process again.
2322+ // In both cases we want to invalidate the user database so that the device
2323+ // can send us the correct user database.
23202324 if (status != SL_STATUS_OK) {
2321- sl_log_error (LOG_TAG,
2322- " Can't get user unique id value. Not sending USER_GET." );
2325+ sl_log_warning (LOG_TAG,
2326+ " Can't get user unique id value. Reset user database." );
2327+ attribute_store_node_t endpoint_node
2328+ = attribute_store_get_node_parent (node);
2329+ // Get User node count
2330+ auto user_count = attribute_store_get_node_child_count_by_type (
2331+ endpoint_node,
2332+ ATTRIBUTE (USER_UNIQUE_ID));
2333+
2334+ for (size_t j = 0 ; j < user_count; j++) {
2335+ // Delete the first attribute we find until we have no more left
2336+ attribute_store_node_t user_node
2337+ = attribute_store_get_node_child_by_type (endpoint_node,
2338+ ATTRIBUTE (USER_UNIQUE_ID),
2339+ 0 );
2340+ attribute_store_delete_node (user_node);
2341+ }
2342+ // NOTE : In the case of user re-interviewing the device, it will be interviewed again when the node goes ONLINE.
23232343 return SL_STATUS_NOT_SUPPORTED;
23242344 }
23252345
@@ -2549,23 +2569,14 @@ void zwave_network_status_changed(attribute_store_node_t updated_node,
25492569 auto user_count = attribute_store_get_node_child_count_by_type (
25502570 endpoint_node,
25512571 ATTRIBUTE (USER_UNIQUE_ID));
2552- sl_log_debug (LOG_TAG,
2553- " Endpoint %d supports User Credential. Removing all "
2554- " existing user nodes (%d)..." ,
2555- i,
2556- user_count);
2557- for (size_t j = 0 ; j < user_count; j++) {
2558- // Delete the first attribute we find until we have no more left
2559- attribute_store_node_t user_node
2560- = attribute_store_get_node_child_by_type (endpoint_node,
2561- ATTRIBUTE (USER_UNIQUE_ID),
2562- 0 );
2563- attribute_store_delete_node (user_node);
2572+ sl_log_debug (LOG_TAG, " Endpoint %d supports User Credential." , endpoint_id);
2573+ if (user_count == 0 ) {
2574+ sl_log_debug (LOG_TAG, " No user found. Starting User and Credential interview" );
2575+ // Start the interview process with user ID = 0
2576+ trigger_get_user (endpoint_node, 0 );
2577+ } else {
2578+ sl_log_debug (LOG_TAG, " Users already discovered. No actions needed." );
25642579 }
2565-
2566- sl_log_debug (LOG_TAG, " Starting User and Credential interview" );
2567- // Start the interview process with user ID = 0
2568- trigger_get_user (endpoint_node, 0 );
25692580 }
25702581 }
25712582 }
0 commit comments