English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Site Management

Last Updated on : 2022-03-03 06:42:10download

Smart Residence App SDK is designed to provide a variety of modules and components for mobile app development in smart apartment rental scenarios. In light of this purpose, the philosophy of sites is abstracted from smart home scenarios. Each home or site encompasses a collection of devices, accounts, permissions, and other resources that are managed by app users.

Functional description

Site management supports the following capabilities:

  • 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.

After login, TuyaResidenceSite must be called to query site information and manage sites. TuyaResidenceSite is used to manage sites. For example, create, modify, query, or delete a site, and manage users on the site.

Make sure that TuyaResidenceSite in ViewController or other objects is declared as a global variable (@property). Otherwise, a temporary variable of TuyaResidenceSite might be released during initialization due to the scope limit, and thus nil is returned.

Initialize a site

This API method must be called each time an object of TuyaResidenceSite is used. The siteId parameter of the API method is also required to call other object methods of the class. If you do not have a site ID, call + createSiteWithName:geoName:rooms:latitude:longitude:success:failure: to create a site.

After the site object is initialized, call fetchSiteDetailWithSuccess:failure: to return site details. This way, the site instance object can have data respecting the properties siteModel, roomList, deviceList, groupList, sharedDeviceList, and sharedGroupList.

API description

+ (instancetype)siteWithSiteId:(long long)siteId;

Request parameters

Parameter Description
siteId The site ID. You can call TuyaResidenceSiteModel to get the value.

Return parameters

Parameter Description
instancetype An object of TuyaResidenceSite, used to call the API methods of TuyaResidenceSite.

Create a site

API description

+ (void)createSiteWithName:(NSString *)siteName
                   geoName:(NSString *)geoName
                     rooms:(NSArray <NSString *>*)rooms
                  latitude:(double)latitude
                 longitude:(double)longitude
                   success:(TYSuccessLongLong)success
                   failure:(TYFailureError)failure;

Request parameters

Parameter Description
siteName The name of the site.
geoName The name of the city in which the site is located.
rooms The string array of room names included on the site.
latitude The latitude of the site, used to locate the site and show suitable units.
longitude The longitude of the site, used to locate the site and show suitable units.

Return parameters

Parameter Description
success The success callback with the new site returned.
failure The failure callback. An error message is returned.

Example

[TuyaResidenceSite createSiteWithName:siteName geoName:geoName rooms:areas latitude:latitude longitude:longitude success:^(long long result) {

} failure:^(NSError *error) {

}];

Query site details

Returns details of a site. After the successful call, you can query the cached site information by using [TuyaResidenceSite siteWithSiteId:siteId].siteModel;.

API description

- (void)fetchSiteDetailWithSuccess:(void (^)(TuyaResidenceSiteModel *siteModel))success
                           failure:(TYFailureError)failure;

Return parameters

Parameter Description
success The success callback with an object of TuyaResidenceSiteModel returned, including site details.
failure The failure callback. An error message is returned.

Example

[self.site fetchSiteDetailWithSuccess:^(TuyaResidenceSiteModel * _Nonnull siteModel) {

} failure:^(NSError *error) {

}];

Query a list of sites

API description

+ (void)fetchSiteListWithSuccess:(void(^)(NSArray <TuyaResidenceSiteModel *> *sites))success
                         failure:(TYFailureError)failure;

Return parameters

Parameter Description
success The success callback with a list of sites returned.
failure The failure callback. An error message is returned.

Example

[TuyaResidenceSite fetchSiteListWithSuccess:^(NSArray<TuyaResidenceSiteModel *> * _Nonnull homes) {

} failure:^(NSError *error) {

}];

Query a list of rooms on a site

Returns a list of rooms on a site.

API description

- (void)fetchSiteRoomCountWithSuccess:(TYSuccessID)success
                              failure:(TYFailureError)failure;

Return parameters

Parameter Description
success The success callback with a list of rooms on the site returned.
failure The failure callback. An error message is returned.

Example

[self.site fetchSiteRoomCountWithSuccess:^(id result) {

} failure:^(NSError *error) {

}];

Modify site information

API description

- (void)updateSiteInfoWitSiteName:(NSString *)siteName
                          geoName:(NSString *)geoName
                         latitude:(double)latitude
                        longitude:(double)longitude
                          success:(TYSuccessHandler)success
                          failure:(TYFailureError)failure;

Request parameters

Parameter Description
siteName The name of the site.
geoName The name of the city in which the site is located.
latitude The latitude of the site.
longitude The longitude of the site.

Return parameters

Parameter Description
success The success callback.
failure The failure callback. An error message is returned.

Example

[self.site updateSiteInfoWitSiteName:siteName geoName:geoname latitude:latitude longitude:longitude success:^{

} failure:^(NSError *error) {

}];

Add a room to a site

API description

- (void)addSiteRoomWithRoomName:(NSString *)roomName
                        success:(TYSuccessHandler)success
                        failure:(TYFailureError)failure;

Request parameters

Parameter Description
roomName The name of a room.

Return parameters

Parameter Description
success The success callback with the new room returned.
failure The failure callback. An error message is returned.

Example

[self.site addSiteRoomWithRoomName:_addRoomTextField.text success:^{

} failure:^(NSError *error) {

}];

Modify member information on a site

Modifies information about a member on a site. If the role of a member is set to TYSiteRoleType_Owner, the member is assigned the ownership of the site.

API description

- (void)updateSiteMemberInfoWithMemberId:(long long)memberId
                            headPicImage:(UIImage * _Nullable)headPicImage
                              memberName:(NSString *)memberName
                                    role:(TYSiteRoleType)role
                                 success:(TYSuccessHandler)success
                                 failure:(TYFailureError)failure;

Request parameters

Parameter Description
memberId The member ID.
headPicImage The image of the member avatar.
memberName The name of the member.
role The role of the member.

Return parameters

Parameter Description
success The success callback.
failure The failure callback. An error message is returned.

Example

[self.site updateSiteMemberInfoWithMemberId:memberId headPicImage:nil memberName:_memberNameTextField.text role:TYSiteRoleType_Owner success:^{

} failure:^(NSError *error) {

}];

Delete a site

API description

- (void)removeSiteWithOwnerId:(long long)ownerId
                      success:(TYSuccessHandler)success
                      failure:(TYFailureError)failure;

Request parameters

Parameter Description
ownerId The owner ID of the site.

Return parameters

Parameter Description
success The success callback.
failure The failure callback. An error message is returned.

Example

[self.site removeSiteWithOwnerId:groupUserId success:^{

} failure:^(NSError *error) {

}];

Query a list of expired residence orders

API description

- (void)fetchExpiredListWithPageSize:(NSInteger)pageSize
                              pageNo:(NSInteger)pageNo
                             success:(void (^)(NSArray<TuyaResidenceExpiredAuthorModel * > *))success
                             failure:(TYFailureError)failure;

Request parameters

Parameter Description
pageSize The number of entries to be returned per page. Valid values: 1 to 100.
pageNo The page number, starting from 1 and incremented by 1 for each request.

Return parameters

Parameter Description
success The success callback with a list of expired residence orders returned.
failure The failure callback. An error message is returned.

Example

[self.site fetchExpiredListWithPageSize:20 pageNo:1 success:^(NSArray<TuyaResidenceExpiredAuthorModel *> *list) {

} failure:^(NSError *error) {

}];

Query a list of members on a site

API description

- (void)fetchSiteResidentListWithSuccess:(void (^)(NSArray<TuyaResidenceSiteMemberModel *> *list))success
                                 failure:(TYFailureError)failure;

Return parameters

Parameter Description
success The success callback with a list of members on the site returned.
failure The failure callback. An error message is returned.

Example

[self.site fetchSiteResidentListWithSuccess:^(NSArray<TuyaResidenceSiteMemberModel *> * _Nonnull list) {

} failure:^(NSError *error) {

}];

Remove a member from a site

API description

- (void)removeMemberWithMemberId:(long long)memberId
                         success:(TYSuccessHandler)success
                         failure:(TYFailureError)failure;

Request parameters

Parameter Description
memberId The member ID.

Return parameters

Parameter Description
success The success callback.
failure The failure callback. An error message is returned.

Example

[self.site removeMemberWithMemberId:model.memberId success:^{

} failure:^(NSError *error) {

}];

Query current login information

Returns information about the currently logged-in user of a site.

API description

- (void)fetchLoginedSiteMemberInfoWithSuccess:(void(^)(TuyaResidenceSiteMemberModel *model))success
                                      failure:(TYFailureError)failure;

Return parameters

Parameter Description
success The success callback with current user information returned.
failure The failure callback. An error message is returned.

Example

[self.site fetchLoginedSiteMemberInfoWithSuccess:^(TuyaResidenceSiteMemberModel * _Nonnull model) {

} failure:^(NSError *error) {

}];

This section contains the following topics to help you quickly understand related concepts and how-to guides: