Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TUYA sdk upgrade #9

Merged
merged 15 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@commitlint/config-conventional"
]
}
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint & Build

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn lint
- run: yarn build
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn build
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn semantic-release
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ gradle
#
npm-debug.log
yarn-error.log
package-lock.json

# BUCK
buck-out/
Expand All @@ -67,3 +66,5 @@ buck-out/
*.jsbundle
*.zip
*.lock
!yarn.lock
!package-lock.json
22 changes: 22 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"branches": [
"master"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github",
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": [
"docs",
"package.json"
],
"message": "chore(release): ${nextRelease.version} [skip ci]"
}
]
],
"tagFormat": "${version}"
}
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @volst/react-native-tuya
# @owowagency/react-native-tuya

This is a fork of [TuyaInc/tuyasmart-home-sdk-react-native](https://github.com/TuyaInc/tuyasmart-home-sdk-react-native), fixing a lot of issues we came across and a better install guide. It also uses TypeScript. We use it currently in multiple projects for clients and it is stable.

Expand All @@ -15,49 +15,49 @@ Tuya Cloud HTTP API interface package
## Getting started

```
npm install @volst/react-native-tuya
npm install @owowagency/react-native-tuya
```

This library contains native code which is automatically linked in React Native >= 0.59. For iOS, run `cd ios && pod install`.

## Installation

In the Tuya development environment create a new app and make sure you have an "App key", "App secret" and "Secure image". [Read how to do this](https://tuyainc.github.io/tuyasmart_home_ios_sdk_doc/en/resource/Preparation.html).
In the Tuya development environment create a new app and make sure you have an "App key", "App secret" [Read how to do this](https://tuyainc.github.io/tuyasmart_home_ios_sdk_doc/en/resource/Preparation.html).

### iOS

Put the secure image into the root path of your project as [explained here](https://tuyainc.github.io/tuyasmart_home_ios_sdk_doc/en/resource/Preparation.html).
Download the security dependency and add it to the project as [explained here](https://developer.tuya.com/en/docs/app-development/integrate-sdk?id=Ka5d52ewngdoi#title-1-Integrate%20with%20the%20SDK).

In `ios/AppDelegate.m`, add the following import;

```obj-c
#import <TuyaSmartHomeKit/TuyaSmartKit.h>
#import <ThingSmartHomeKit/ThingSmartKit.h>
```

Then, under the `roootView.backgroundColor` line in the same file, add this:

```obj-c
#ifdef DEBUG
[[TuyaSmartSDK sharedInstance] setDebugMode:YES];
[[ThingSmartSDK sharedInstance] setDebugMode:YES];
#endif

[[TuyaSmartSDK sharedInstance] startWithAppKey:@"xxx" secretKey:@"xxx"];
[[ThingSmartSDK sharedInstance] startWithAppKey:@"xxx" secretKey:@"xxx"];
```

Now replace the `xxx` with your app key and secret key.

### Android

Assuming you already have created an app in the Tuya development environment (otherwise follow the iOS steps before this), follow [these steps](https://tuyainc.github.io/tuyasmart_home_android_sdk_doc/en/resource/Integrated.html#3-integrated-security-image). You should now have an app key, app secret and security image for Android. Make sure the security image is put in `android/src/main/assets/t_s.bmp`.
Assuming you already have created an app in the Tuya development environment (otherwise follow the iOS steps before this), follow [these steps](https://developer.tuya.com/en/docs/app-development/integrated?id=Ka69nt96cw0uj#title-5-Step%203%3A%20Integrate%20with%20security%20component). You should now have an app key, app secret and security dependency for Android

Open your `AndroidManifest.xml` and put the following **in the `<application>` tag**:

```xml
<meta-data
android:name="TUYA_SMART_APPKEY"
android:name="THING_SMART_APPKEY"
android:value="xxx" />
<meta-data
android:name="TUYA_SMART_SECRET"
android:name="THING_SMART_SECRET"
android:value="xxx" />
```

Expand Down Expand Up @@ -104,7 +104,7 @@ Now you can actually use the methods in this package. Unfortunately I don't have
To login with an existing account:

```js
import { loginWithEmail } from '@volst/react-native-tuya';
import { loginWithEmail } from '@owowagency/react-native-tuya';

await loginWithEmail({
countryCode: '+1',
Expand All @@ -116,7 +116,7 @@ await loginWithEmail({
To register a new account you first need to validate the email address. And then actually register using the code in the email.

```js
import { getRegisterEmailValidateCode, registerAccountWithEmail } from '@volst/react-native-tuya';
import { getRegisterEmailValidateCode, registerAccountWithEmail } from '@owowagency/react-native-tuya';

await getRegisterEmailValidateCode({
countryCode: '+1',
Expand All @@ -136,7 +136,7 @@ await registerAccountWithEmail({
To get the currently logged in user:

```js
import { getCurrentUser } from '@volst/react-native-tuya';
import { getCurrentUser } from '@owowagency/react-native-tuya';

const user = await getCurrentUser();
```
Expand Down
6 changes: 3 additions & 3 deletions RNTuyaSdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Pod::Spec.new do |s|

s.authors = package['author']
s.homepage = package['homepage']
s.platforms = { :ios => "9.0" }
s.platforms = { :ios => "12.0" }

s.source = { :git => "https://github.com/Volst/react-native-tuya.git", :tag => "v#{s.version}" }
s.source = { :git => "https://github.com/owowagency/react-native-tuya.git", :tag => "v#{s.version}" }
s.source_files = "ios/**/*.{h,m}"

s.dependency 'React'
s.dependency 'TuyaSmartHomeKit', '~> 3.29.5'
s.dependency 'ThingSmartHomeKit', '~> 5.8.0'
end
51 changes: 37 additions & 14 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,22 @@ apply plugin: 'maven-publish'
buildscript {
ext.kotlin_version = '1.7.20'
repositories {

maven {
url 'https://maven.aliyun.com/nexus/content/groups/public/'
}
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}


android {
compileSdkVersion 28
compileSdkVersion 31

defaultConfig {
minSdkVersion 16
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
Expand All @@ -37,21 +33,33 @@ android {
}
}

packagingOptions {
pickFirst 'lib/*/libc++_shared.so'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

configurations.all {
exclude group: "com.thingclips.smart", module: 'thingsmart-modularCampAnno'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.alibaba:fastjson:1.1.67.android'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.6.0'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation 'com.tuya.smart:tuyasmart:3.36.3'
implementation 'com.thingclips.smart:thingsmart:5.11.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.facebook.react:react-native:+'
implementation 'de.greenrobot:eventbus:2.4.0'
Expand All @@ -60,14 +68,29 @@ dependencies {
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
}

repositories {
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$projectDir/../node_modules/react-native/android"
}
mavenCentral()
google()
maven {
url "https://maven-other.tuya.com/repository/maven-releases/"
maven { url 'https://maven-other.tuya.com/repository/maven-releases/' }
maven { url "https://maven-other.tuya.com/repository/maven-commercial-releases/" }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://developer.huawei.com/repo/' }
maven { url 'https://jitpack.io' }
}

allprojects {
repositories {
exclusiveContent {
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
}
}
24 changes: 24 additions & 0 deletions android/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -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.**
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
android.useAndroidX=true
25 changes: 25 additions & 0 deletions android/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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.**

This file was deleted.

Loading