From 3aafd230872db96366af8b54c6efd10148368ad7 Mon Sep 17 00:00:00 2001 From: Jelle Date: Mon, 3 Jun 2024 14:33:57 +0200 Subject: [PATCH] fix: change TY_ prefix to THING_ in activator module --- .github/workflows/release.yml | 1 + .releaserc.json | 6 ++++- android/consumer-rules.pro | 24 ++++++++++++++++++ android/proguard-rules.pro | 25 +++++++++++++++++++ .../rnsdk/activator/TuyaActivatorModule.kt | 18 ++++++++++++- .../Activator/TuyaRNActivatorModule.m | 13 ++++++---- src/activator.ts | 9 ++++++- 7 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 android/consumer-rules.pro diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8397bc23..95b8c2e6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - feature/tuya-sdk-upgrade jobs: release: diff --git a/.releaserc.json b/.releaserc.json index c8d67e17..6ef95ee0 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -1,6 +1,10 @@ { "branches": [ - "master" + "master", + { + "name": "feature/tuya-sdk-upgrade", + "prerelease": "RC" + } ], "plugins": [ "@semantic-release/commit-analyzer", diff --git a/android/consumer-rules.pro b/android/consumer-rules.pro new file mode 100644 index 00000000..d224b49b --- /dev/null +++ b/android/consumer-rules.pro @@ -0,0 +1,24 @@ +# https://developer.tuya.com/en/docs/app-development/integrated?id=Ka69nt96cw0uj#title-7-Step%205%3A%20Obfuscate%20the%20code + +#fastJson +-keep class com.alibaba.fastjson.**{*;} +-dontwarn com.alibaba.fastjson.** + +#mqtt +-keep class com.thingclips.smart.mqttclient.mqttv3.** { *; } +-dontwarn com.thingclips.smart.mqttclient.mqttv3.** + +#OkHttp3 +-keep class okhttp3.** { *; } +-keep interface okhttp3.** { *; } +-dontwarn okhttp3.** + +-keep class okio.** { *; } +-dontwarn okio.** + +-keep class com.thingclips.**{*;} +-dontwarn com.thingclips.** + +# Matter SDK +-keep class chip.** { *; } +-dontwarn chip.** \ No newline at end of file diff --git a/android/proguard-rules.pro b/android/proguard-rules.pro index f1b42451..7972c93b 100644 --- a/android/proguard-rules.pro +++ b/android/proguard-rules.pro @@ -19,3 +19,28 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + +# https://developer.tuya.com/en/docs/app-development/integrated?id=Ka69nt96cw0uj#title-7-Step%205%3A%20Obfuscate%20the%20code + +#fastJson +-keep class com.alibaba.fastjson.**{*;} +-dontwarn com.alibaba.fastjson.** + +#mqtt +-keep class com.thingclips.smart.mqttclient.mqttv3.** { *; } +-dontwarn com.thingclips.smart.mqttclient.mqttv3.** + +#OkHttp3 +-keep class okhttp3.** { *; } +-keep interface okhttp3.** { *; } +-dontwarn okhttp3.** + +-keep class okio.** { *; } +-dontwarn okio.** + +-keep class com.thingclips.**{*;} +-dontwarn com.thingclips.** + +# Matter SDK +-keep class chip.** { *; } +-dontwarn chip.** \ No newline at end of file diff --git a/android/src/main/java/com/tuya/smart/rnsdk/activator/TuyaActivatorModule.kt b/android/src/main/java/com/tuya/smart/rnsdk/activator/TuyaActivatorModule.kt index 7bb60925..bceee42e 100644 --- a/android/src/main/java/com/tuya/smart/rnsdk/activator/TuyaActivatorModule.kt +++ b/android/src/main/java/com/tuya/smart/rnsdk/activator/TuyaActivatorModule.kt @@ -110,17 +110,33 @@ class TuyaActivatorModule(reactContext: ReactApplicationContext) : ReactContextB } + /** + * Maps string value to ActivatorModelEnum + * Returns null on unknown case + */ + private fun getActivatorModelEnumByString(value: String): ActivatorModelEnum? { + return when (value) { + "THING_AP" -> ActivatorModelEnum.THING_AP + "THING_EZ" -> ActivatorModelEnum.THING_EZ + "THING_4G_GATEWAY" -> ActivatorModelEnum.THING_4G_GATEWAY + "THING_QR" -> ActivatorModelEnum.THING_QR + else -> null + } + } + @ReactMethod fun initActivator(params: ReadableMap, promise: Promise) { if (ReactParamsCheck.checkParams(arrayOf(HOMEID, SSID, PASSWORD, TIME, TYPE), params)) { ThingHomeSdk.getActivatorInstance().getActivatorToken(params.getDouble(HOMEID).toLong(), object : IThingActivatorGetToken { override fun onSuccess(token: String) { + val modeValue = params.getString(TYPE) as String + val mode = getActivatorModelEnumByString(modeValue) ?: ActivatorModelEnum.THING_EZ mITuyaActivator = ThingHomeSdk.getActivatorInstance().newActivator( ActivatorBuilder() .setSsid(params.getString(SSID)) .setContext(reactApplicationContext.applicationContext) .setPassword(params.getString(PASSWORD)) - .setActivatorModel(ActivatorModelEnum.valueOf(params.getString(TYPE) as String)) + .setActivatorModel(mode) .setTimeOut(params.getInt(TIME).toLong()) .setToken(token).setListener(getITuyaSmartActivatorListener(promise))) mITuyaActivator?.start() diff --git a/ios/RNTuyaSdk/Activator/TuyaRNActivatorModule.m b/ios/RNTuyaSdk/Activator/TuyaRNActivatorModule.m index 4de636b1..07480add 100644 --- a/ios/RNTuyaSdk/Activator/TuyaRNActivatorModule.m +++ b/ios/RNTuyaSdk/Activator/TuyaRNActivatorModule.m @@ -52,12 +52,15 @@ @implementation TuyaRNActivatorModule NSString *type = params[kTuyaRNActivatorModuleActivatorMode]; // NSString *token = params[kTuyaRNActivatorModuleActivatorToken]; - ThingActivatorMode mode = ThingActivatorModeEZ; - if ([type isEqualToString:@"TY_EZ"]) { - mode = ThingActivatorModeEZ; - } else if([type isEqualToString:@"TY_AP"]) { + ThingActivatorMode mode = ThingActivatorModeEZ; + + if ([type isEqualToString:@"THING_AP"]) { mode = ThingActivatorModeAP; - } else if([type isEqualToString:@"TY_QR"]) { + } else if([type isEqualToString:@"THING_EZ"]) { + mode = ThingActivatorModeEZ; + } else if([type isEqualToString:@"THING_4G_GATEWAY"]) { + mode = ThingActivatorModeAP4GGateway; + } else if([type isEqualToString:@"THING_QR"]) { mode = ThingActivatorModeQRCode; } diff --git a/src/activator.ts b/src/activator.ts index f5325c5d..d1599783 100644 --- a/src/activator.ts +++ b/src/activator.ts @@ -10,12 +10,19 @@ export function openNetworkSettings() { return tuya.openNetworkSettings({}); } +export enum ActivatorType { + AP = 'THING_AP', + EZ = 'THING_EZ', + AP_4G_GATEWAY = 'THING_4G_GATEWAY', + QR = 'THING_QR', +} + export type InitActivatorParams = { homeId: number; ssid: string; password: string; time: number; - type: 'TY_EZ' | 'TY_AP' | 'TY_QR'; + type: ActivatorType; }; export interface InitBluetoothActivatorParams {