Site Management

Last Updated on : 2022-02-17 07:01:49download

Smart Residence App SDK is designed to provide a variety of modules and components for mobile app development in smart apartment rental scenarios. A site is abstracted from smart rental scenarios. Each site is an independent unit that is managed by an account. Rooms and devices must be assigned to a project before they can be managed.

Concepts

Sites are classified into:

  • Common site: a site created by a common member.
  • Business-authorized site: a site that a business authorizes users to access.
  • Access control site: a site for which a business or member authorizes other members to manage access control.

Site management capabilities include:

  • Query a list of sites.
  • Add, modify, and remove a site.
  • Manage site information such as site names, location details, rooms, and members.
  • Manage resources for sites. For example, add devices, modify site information, listen for device status changes, and remove listeners.

Each user can manage one or more projects. The number of projects that can be configured by an account varies depending on the different plans purchased by the account. By default, new users do not have projects after registration and login. They must create projects to perform project-specific operations.

Get site manager

Returns the site manager by using TuyaSmartResidenceSdk.siteManager() to call site management API methods.

Query a list of sites

Returns a list of sites by using fun fetchSiteList(listener: Business.ResultListener<ArrayList<SiteBean?>?>?).

Example

TuyaSmartResidenceSdk
            .siteManager()
            .fetchSiteList(object : Business
            .ResultListener<ArrayList<SiteBean?>?> {
                override fun onFailure(
                    p0: BusinessResponse?,
                    p1: ArrayList<SiteBean?>?,
                    p2: String?,
                ) {
                    L.d(TAG, "onFailure BusinessResponse = $p0, ArrayList<SiteBean?> = $p1, " +
                            "String = $p2")
                }

                override fun onSuccess(
                    p0: BusinessResponse?,
                    siteList: ArrayList<SiteBean?>?,
                    p2: String?,
                ) {
                    L.d(TAG, "onSuccess BusinessResponse = $p0, ArrayList<SiteBean?> =" +
                            "$siteList, String = $p2")
                }

            })

Properties of SiteBean

  • SiteBean inherits from HomeBean. The following table lists the fields ofHomeBean.

    Field name Type Description
    name String The name of a site.
    geoName String The geographical location of a site.
    lon Double The longitude of the site.
    lat Double The latitude of the site.
    homeId Long The site ID.
    admin Boolean Indicates the identity of an administrator.
    homeStatus Integer The status of the request to join a site. Valid values:
    • 1: pending acceptance
    • 2: accepted
    • 3: rejected
    role Integer The roles of site members. Valid values:
    • -1: custom member.
    • 0: site member.
    • 1: administrator.
    • 2: site owner.
    • -999: invalid member. A member will become invalid in specific conditions.
    rooms List<RoomBean> A list of all rooms.
    deviceList List<DeviceBean> A list of all devices.
    groupList List<GroupBean> A list of all groups.
    meshList List<BlueMeshBean> A list of gateways.
    sharedDeviceList List<DeviceBean> A list of shared devices.
    sharedGroupList List<GroupBean> A list of shared groups.
  • The following table describes the parameters of SiteBean.

    Field name Type Description
    projectName String The name of the project.
    projectLocation String The location of the project.
    authStartTime Long The time when the authorization becomes effective.
    authEndTime Long The time when the authorization expires.
    memberLimit Int The minimum number of members allowed for check-in.
    authStatus String The authorization status. Valid values:
    • 0: to be effective
    • 1: authorized
    • 2: expired
    • 3: permanently valid
    siteType String The type of site. Valid values:
    • 1: common site (default value)
    • 2: access control site
    • 3: business-authorized site
    spaceFullName String The full name of the site.
    includeDeviceGroup Boolean Specifies whether device groups are included.
    dgIds List The group IDs that are included by the site.

The API method to query a site list does not return information such as rooms and devices. Therefore, after the query, use homeId to query information such as rooms and devices to get all information about the site.

Query site details

Returns details of a site. The information such as rooms and devices are automatically entered in SiteBean.

fun fetchSiteDetail(
        siteBean: SiteBean,
        callback: ITuyaSiteResultCallback
    )

The preceding method must be called again after each app startup or reconnection. Otherwise, information loss might occur.

Example

TuyaSmartResidenceSdk.siteManager().fetchSiteDetail(Global
        .currentSite!!, object : ITuyaSiteResultCallback {
        override fun onSuccess(bean: SiteBean?) {
            L.d(TAG, JSON.toJSONString(bean))
        }

        override fun onError(errorCode: String?, errorMsg: String?) {
            L.d(TAG, "fetchSiteDetailList: errorCode = $errorCode, errorMsg = $errorMsg")
        }
    })

Manage sites

Switch between sites

The returned site list and site details must be stored. To switch between sites, the details of the target site are required. In other API methods, the target site ID is also required.

Create a site

Creates a site. The fields siteName and listener are required. Other fields are optional and can be set to an empty string or 0.

fun createSite(
        siteName: String,
        geoName: String,
        lat: Double,
        lon: Double,
        rooms: List<String?>?,
        listener: Business.ResultListener<HomeResponseBean?>?
    )

Parameters

Parameter Type Description
siteName String The name of the site.
geoName String The location of the site.
lat Double The longitude of the site.
lon Double The latitude of the site.
rooms List<String? > The list of rooms.
listener Business.ResultListener The callback.

Example

TuyaSmartResidenceSdk.siteManager()
                    .createSite(homeName, "", lat = lat.toDouble(), lon = lon.toDouble(), split, object :
                        Business
                        .ResultListener<HomeResponseBean?> {
                        override fun onFailure(p0: BusinessResponse?, p1: HomeResponseBean?, p2: String?) {
                            L.d(
                                TAG, "onFailure BusinessResponse = $p0, HomeResponseBean = $p1, " +
                                        "String = $p2")
                        }

                        override fun onSuccess(p0: BusinessResponse?, p1: HomeResponseBean?, p2: String?) {
                            L.d(TAG, "onSuccess BusinessResponse = $p0, HomeResponseBean = $p1, " +
                                    "String = $p2")

                        }

                    })

Modify site information

Modifies information about a site, such as its name and location, as well as the name and quantity of rooms on the site.

You must place restrictions on the scope of such modification for security purposes. For example, the information about business-authorized sites and access control sites cannot be modified.

fun updateSiteInfo(
        homeId: Long,
        name: String?,
        lon: Double,
        lat: Double,
        geoName: String?,
        rooms: List<String?>? = null,
        overWriteRoom: Boolean? = null,
        listener: Business.ResultListener<Boolean?>?
    )

The parameters are the same as those used in createSite. The following table describes the valid values ofoverWriteRoom.

Value Description
true Deletes the original room and uses the new target room.
false Adds a room.

Example

    TuyaSmartResidenceSdk.siteManager()
                        .updateSiteInfo(Global.currentSite?.homeId ?: return@Button, homeName, lon.toDouble(), lat
                            .toDouble(), geoName, split, true, object : Business
                        .ResultListener<Boolean?> {
                            override fun onFailure(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
                                L.d(
                                    TAG, "onFailure BusinessResponse = $p0, HomeResponseBean = $p1, " +
                                            "String = $p2")
                            }

                            override fun onSuccess(p0: BusinessResponse?, p1: Boolean?, p2: String?) {
                                L.d(TAG, "onSuccess BusinessResponse = $p0, HomeResponseBean = $p1, " +
                                        "String = $p2")

                            }

                        })

Query expired business-authorized sites

Returns a list of expired business-authorized sites that are assigned with a validity period.

fun fetchExpiredList(
        pageNo: Int,
        pageSize: Int,
        listener: Business.ResultListener<SiteExpiredAuthBeans>
    )

Only the list of expired business-authorized sites is returned. Common sites and access control sites are not included in the response.

Fields of SiteExpiredAuthBeans

Field name Type Description
projectId String The project ID.
spaceId String The room ID.
projectName String The name of the project.
spaceName String The name of the room.
spaceFullName String The full name of the room.
authStartTime Long The time of check-in.
authEndTime Long The time of check-out.

Example

TuyaSmartResidenceSdk.siteManager().fetchExpiredList(1, 20, object : Business
    .ResultListener<SiteExpiredAuthBeans> {
        override fun onFailure(
            p0: BusinessResponse?,
            p1: SiteExpiredAuthBeans?,
            p2: String?,
        ) {
            L.d(TAG, "fetchExpiredList onFailure: ${p0?.errorMsg}")
        }

        override fun onSuccess(
            p0: BusinessResponse?,
            p1: SiteExpiredAuthBeans?,
            p2: String?,
        ) {

        }

    })