Skip to content

Commit

Permalink
Updated to use test data from resources
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Jul 19, 2024
1 parent 00b50ac commit 2b46d85
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,45 +68,34 @@ class CHIPLedgerDetailsFragment : Fragment() {
.toString()
Log.d(TAG, "Dcl request Url: $url")

// Ledger API call
val responseRaw: String = """
{
"vid": 65521,
"pid": 32769,
"deviceTypeId": 1,
"productName": "Harmony Home",
"productLabel": "Purifier",
"partNumber": "1",
"commissioningCustomFlow": 2,
"commissioningCustomFlowUrl": "https://example.com/matter/65521/32769/setup/1/index.html",
"commissioningModeInitialStepsHint": 0,
"commissioningModeInitialStepsInstruction": "",
"commissioningModeSecondaryStepsHint": 0,
"commissioningModeSecondaryStepsInstruction": "",
"userManualUrl": "https://example.com/matter/65521/32769/manual/1/index.html",
"supportUrl": "https://example.com/matter/65521/32769/support/1/index.html",
"productUrl": "https://example.com/matter/65521/32769/product/1/index.html",
"lsfUrl": "",
"lsfRevision": 0,
"creator": "cosmos1cj3f9jue3s389n2u6492nvyn86apey0x6hx03u",
"schemaVersion": 1,
"enhancedSetupFlowOptions": 1,
"enhancedSetupFlowTCUrl": "https://example.com/matter/65521/32769/tc/1/content.json",
"enhancedSetupFlowTCRevision": 1,
"enhancedSetupFlowTCDigest": "MTZlYjIwYWViYzU2ZWI0Nzc4Zjg0NTRiMmJjMjVlYWFlOTY5MjMzNGRiMzRhMjUxZjMwYmQ1Y2MzYzI1NGI2OA==",
"enhancedSetupFlowTCFileSize": 1024,
"maintenanceUrl": "https://example.com/matter/65521/32769/maintenance/1/index.html"
}
"""
val context = getContext()!!
val mockDclRequestsResponsesRaw = readRawResourceFile(R.raw.mock_dcl_responses_json)
val mockDclRequestsResponses: org.json.JSONArray = org.json.JSONArray(mockDclRequestsResponsesRaw)

val mockDclRequestsResponseMap = HashMap<String, org.json.JSONObject>()
for (i in 0 until mockDclRequestsResponses.length()) {
val mockDclRequestsResponse = mockDclRequestsResponses.getJSONObject(i)

val mockDclRequest: org.json.JSONObject = mockDclRequestsResponse.getJSONObject("request")
val mockDclResponse: org.json.JSONObject = mockDclRequestsResponse.getJSONObject("response")

val mockDclRequestURL = mockDclRequest.getString("url")
val mockDclResponseBody = mockDclResponse.getJSONObject("body")

mockDclRequestsResponseMap.put(mockDclRequestURL, mockDclResponseBody)
Log.d(TAG, "mockDclRequestURL= $mockDclRequestURL")
Log.d(TAG, "mockDclResponseBody= $mockDclResponseBody")
}

val response: org.json.JSONObject = org.json.JSONObject(responseRaw)
Log.d(TAG, "Request url= $url")
val response: org.json.JSONObject = mockDclRequestsResponseMap.get(url.toString())!!
Log.d(TAG, "Response from dcl $response")
Toast.makeText(getContext(), "Enhanced Setup Flow: $response", Toast.LENGTH_LONG).show()
Toast.makeText(context, "Enhanced Setup Flow: $response", Toast.LENGTH_LONG).show()

val enhancedSetupFlowOptions = response.optInt("enhancedSetupFlowOptions", 0)

if (0 != (enhancedSetupFlowOptions and 0b00000001)) {
Toast.makeText(getContext(), "Enhanced Setup Flow supported!", Toast.LENGTH_SHORT).show()
Toast.makeText(context, "Enhanced Setup Flow supported!", Toast.LENGTH_SHORT).show()

binding.commissionBtn.setOnClickListener {
FragmentUtil.getHost(this@CHIPLedgerDetailsFragment, Callback::class.java)
Expand Down

0 comments on commit 2b46d85

Please sign in to comment.