npm package: @rentlydev/rently-tuya
Description: rently-tuya
Author: harishkumar00
Latest version: 0.2.5

# @rentlydev/rently-tuya

A React Native module for integrating the Tuya Doorbell SDK, enabling applications to interact with Tuya-compatible smart doorbells. This library provides essential functionalities such as device pairing, live preview, and push notification registration, ensuring a seamless smart home experience.

Fully compatible with TypeScript.

## Supported platforms

| Platform  |  Support |
|---|---|
| iOS  |  ✅ |
| Android  |  ✅ |
| Web  |  ❌ |
| Windows  |  ❌ |
| macOS  |  ❌ |

## Installation

```sh
npm install @rentlydev/rently-tuya
```
or

```sh
yarn add @rentlydev/rently-tuya
```

## Configuration and Permissions

### iOS
(Configuration details to be added)

### Android
(Configuration details to be added)

## Summary

### Methods

* [`initAirbrake`](#initAirbrake)
* [`getCurrentWifi`](#getCurrentWifi)
* [`getDeviceData`](#getDeviceData)
* [`setTuyaHome`](#setTuyaHome)
* [`getTokenForQRCode`](#getTokenForQRCode)
* [`initActivatorForQRCode`](#initActivatorForQRCode)
* [`loginWithUid`](#loginWithUid)
* [`logout`](#logout)
* [`openCameraLivePreview`](#openCameraLivePreview)
* [`registerForPushNotification`](#registerForPushNotification)
* [`renameDevice`](#renameDevice)
* [`resetDevice`](#resetDevice)

### Listeners

* [`Listeners`](#Listeners)

---

## Usage

### initAirbrake
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.initAirbrake({ key: '', id: '' });
```

Parameters:
* `key` (String) - Airbrake Project Key.
* `id` (String) - Airbrake Project Id.

### getCurrentWifi
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.getCurrentWifi();
```
Response:

(String) - Current connected Wi-Fi name.

### getDeviceData
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.getDeviceData({ devId: '' });
```
Parameters:
* `devId` (String) - Doorbell Device Id.

### setTuyaHome
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.setTuyaHome({ homeId: '' })
```
Parameters:
* `homeId` (String) - Home Id associated with Doorbell.

### getTokenForQRCode
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.getTokenForQRCode({ homeId: '' })
```
Parameters:
* `homeId` (String) - Home Id associated with Doorbell.

Response:

(String) - Token required for QR code activation.

### initActivatorForQRCode
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.initActivatorForQRCode({
    ssid: '',
    paasword: '',
    time: '',
    token: ''
})
```
Parameters:
* `ssid` (String) - Wi-Fi name.
* `password` (String) - Wi-Fi Password.
* `time` (String) - Timeout for activation.
* `token` (String) - Token from getTokenForQRCode.

### loginWithUid
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.loginWithUid({
    uid: '',
    paasword: '',
    countryCode: ''
})
```
Parameters:
* `uid` (String) - Login Uid.
* `password` (String) - Login Password.
* `countryCode` (String) - Login Country code.

### logout
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.logout()
```

### openCameraLivePreview
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.openCameraLivePreview({
    id: '',
    countryCode: '',
    uid: '',
    passwd: '',
    devId: '',
    homeId: '',
    last_moveout_at: '',
    resetRequired: true,
    isResident: true,
    display_remove_doorbell_button: true,
    propertyCredentialUsername: '',
    propertyCredentialPassword: '',
    tuya_product_name: '',
    device_uuid: '',
    serial_no: '',
    flavour: '',
    doorbell_default_settings_updated: true,
    motion_detection: true,
    continuous_recording: true,
    event_recording: true,
    set_sensitivity_low: true
})
```
Parameters:
* `id` (String) - Unique identifier for the user.
* `countryCode` (String) - The country code associated with the user.
* `uid` (String) - Unique user identifier used for authentication.
* `passwd` (String) - Password for the user account.
* `devId` (String) - Unique identifier for the Tuya doorbell device.
* `homeId` (String) - Identifier for the home where the Tuya doorbell is registered.
* `last_moveout_at` (String) - Timestamp of the last move-out event for the asset.
* `resetRequired` (String) - Indicates whether a reset is required for the device.
* `isResident` (String) - Specifies if the user is a resident of the associated home.
* `display_remove_doorbell_button` (String) - Determines if the option to remove the doorbell should be shown.
* `propertyCredentialUsername` (String) - Username for property authentication.
* `propertyCredentialPassword` (String) - Password for property management system authentication.
* `tuya_product_name` (String) - Name of the Tuya doorbell product.
* `device_uuid` (String) - UUID of the device.
* `serial_no` (String) - Serial number of the doorbell device.
* `flavour` (String) - Theme for the UI.
* `doorbell_default_settings_updated` (String) - Specifies whether the default doorbell settings should be updated.
* `motion_detection` (String) - Indicates if motion detection should be enabled.
* `continuous_recording` (String) - Indicates if continuous recording should be enabled.
* `event_recording` (String) - Indicates if evet recording should be enabled.
* `set_sensitivity_low` (String) - Indicates if sensitivity should be set to low.

### registerForPushNotification
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.registerForPushNotification({ token: '' })
```
Parameters:
* `token` (String) - FCM Token.

### renameDevice
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.renameDevice({ deviceId: '', name: '' })
```
Parameters:
* `deviceId` (String) - Device Id.
* `name` (String) - New device name.

### resetDevice
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

const response = await RentlyTuya.resetDevice({ 
    devId: '',
    homeId: '',
    username: '',
    password: '',
    countryCode: ''
})
```

Parameters:
* `devId` (String) - Doorbell Device Id.
* `homeId` (String) - Home Id associated with Doorbell.
* `username` (String) - User ID.
* `password` (String) - Password.
* `countryCode` (String) - Country Code.

### Listeners
> [!IMPORTANT]
After processing, a success or failure event should be sent.

## Android
```javascript
import RentlyTuya from '@rentlydev/rently-tuya';

export class ExposedToJava {
  removeCamera(devId: string) {}

  navigateToAddDoorbell(devId: string) {}

  resetDoorbellDefaultSettingsFlag(id: string) {}
}
```

## iOS
```javascript
  React.useEffect(() => {
      const data = new NativeEventEmitter(NativeModules.KeylessListener);
      data.addListener('REMOVE_CAMERA', (data: any) => {});
      data.addListener('RESET_WIFI', (data: any) => {});
      data.addListener('RESET_DEFAULT_SETTINGS_FLAG', (data: any) => {});
  }, []);
```

## How To Run Example App ?

To run example app, follow the below steps

1. Clone the repository
2. Run `yarn install`
3. Navigate to example/ios folder i.e `cd example/ios` and do `pod install`, then `cd ..`
4. For android run `yarn example android`
5. For ios run `yarn example ios`

## Demo Video

[Android & iOS](https://drive.google.com/drive/folders/1307uBsdACw-H_FxlF3TWz7cqm6Phhx-6?usp=sharing)