House Management

Last Updated on : 2022-02-17 06:45:08download

Feature overview

TuyaCommunityHouse is used to describe all information about a house. You can call APIs to get house details, query a list of rooms from a house, and sort the devices and groups displayed in a house.

Initialize a house

API description

+ (instancetype)houseWithHouseId:(long long)houseId;

Parameters

Parameter Description
houseId The house ID.

Example

long long houseId;
TuyaCommunityHouse *house = [TuyaCommunityHouse houseWithHouseId:houseId];

Query house details

API description

- (void)getHouseDetailWithSuccess:(void(^)(TuyaCommunityHouseModel *result))success
                          failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
success The success callback.
failure The failure callback.

Example

[house getHouseDetailWithSuccess:^(TuyaCommunityHouseModel * _Nonnull result) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Change the house location

- (void)updateHouseLocationWithGeoName:(NSString *)geoName
                              latitude:(double)latitude
                             longitude:(double)longitude
                               success:(void(^)(void))success
                               failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
geoName NSString
latitude double
longitude double
success The success callback.
failure The failure callback.

Example

[house updateHouseLocationWithGeoName:@"xxx" latitude:0 longitude:0 success:^{
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Sort devices and groups in a house

Sorts the devices or groups in a house.

API description

- (void)sortDeviceOrGroupWithOrderList:(NSArray<NSDictionary *>*)orderList
                               success:(void(^)(void))success
                               failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
orderList The details of a device or group. Format: [@{@"bizId": @"XXX", @"bizType": @"XXX"}]
success The success callback.
failure The failure callback.

Example

[house sortDeviceOrGroupWithOrderList:@[] success:^{
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Query the weather overview for a house

API description

- (void)getHouseWeatherSketchWithSuccess:(void(^)(TuyaCommunityWeatherSketchModel *result))success
                                 failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
success The success callback.
failure The failure callback.

Example

[house getHouseWeatherSketchWithSuccess:^(TuyaCommunityWeatherSketchModel * _Nonnull result) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Query the weather details for a house

Returns the weather details for a house. Multiple weather data is returned, such as the temperature, humidity, ultraviolet (UV) index, and air quality.

API description

- (void)getHouseWeatherDetailWithOptionModel:(TuyaCommunityWeatherOptionModel *)optionModel
                                     success:(void(^)(NSArray<TuyaCommunityWeatherModel *>*list))success
                                     failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
optionModel -
success The success callback.
failure The failure callback.

Example

TuyaCommunityWeatherOptionModel *model;
[house getHouseWeatherDetailWithOptionModel:model
                                    success:^(NSArray<TuyaCommunityWeatherModel *> * _Nonnull list) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

House information management

TuyaCommunityHouseManager is used to implement management of houses that are specified by TuyaCommunityHouse. For example, add houses, query a list of houses, and listen for house changes.

You can call TuyaCommunityHouseModel to get information about a house.

Functional description

Query a list of houses

Returns a list of houses for the current user.

API description

- (void)getHouseListWithSuccess:(void(^)(NSArray<TuyaCommunityHouseModel *>*list))success
                        failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
success The success callback.
failure The failure callback.

Example

self.houseManager = [TuyaCommunityHouseManager new];
[self.houseManager getHouseListWithSuccess:^(NSArray<TuyaCommunityHouseModel *> * _Nonnull list) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Query a list of communities

Returns a list of communities. A house can be added only after a community is selected. Therefore, call this API method to get a target community before a house is added to the community.

API description

- (void)getCommunityListWithKeyword:(NSString * _Nullable)keyword
                           latitude:(double)latitude
                          longitude:(double)longitude
                            success:(void(^)(NSArray<TuyaCommunityListModel *>*list))success
                            failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
keyword The name of a community. This parameter is optional and used to query a list of communities.
latitude The latitude. This parameter is optional and used to display the surrounding communities.
longitude The longitude. This parameter is optional and used to display the surrounding communities.
success The success callback.
failure The failure callback.

Example

[self.houseManager getCommunityListWithKeyword:@""
                                      latitude:0
                                     longitude:0
                                   success:^(NSArray<TuyaCommunityListModel *> * _Nonnull list) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Query a house space tree

Returns a house space tree after a community is selected to add a house. Information about the building, unit, floor, and room ID is displayed by the space tree. The hasMore field in the response indicates whether subordinate spaces are available.

API description

- (void)getHouseTreeListWithTreeId:(NSString *)treeId
                           success:(void(^)(NSArray<TuyaCommunityHouseTreeModel *>*list))success
                           failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
treeId The space tree ID. To query a space tree for a specific community, communityId is required.
success The success callback.
failure The failure callback.

Example

[self.houseManager getHouseTreeListWithTreeId:@"xxx"
                                      success:^(NSArray<TuyaCommunityHouseTreeModel *> * _Nonnull list) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Add a house

API description

- (void)addHouseWithName:(NSString *)name
             communityId:(NSString *)communityId
                  roomId:(NSString *)roomId
                userType:(NSString *)userType
              expireTime:(NSString * _Nullable)expireTime
                 success:(void(^)(TuyaCommunityHouseModel *result))success
                 failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
name The details of a house, including the building, unit, floor, and room ID.
roomId The room ID. This is the value of treeId for the bottom-level space specific to a house.
userType The type of member, such as the owner, house member, or tenant.
expireTime The expiration time. This parameter is optional and specifies the expiration time of a tenant user. Format: yyyyMMdd.
success The success callback.
failure The failure callback.

Example

[self.houseManager addHouseWithName:@"xxx"
                        communityId:@"xxx"
                             roomId:@"xxx"
                           userType:@"xxx"
                         expireTime:nil
                            success:^(TuyaCommunityHouseModel * _Nonnull result) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];
  • A user must be verified before the user can add a house. You can call getUserCertificationInfoWithSuccess:failure: of the class TuyaCommunityHouseMemberService to query the user verification status. If the user is not verified, call verifyUserInfoWithRealName:sex:idCard:success:failure: of the class TuyaCommunityHouseMemberService to verify the user.

  • userType specifies the user type. You can call getMemberTypeListWithroomId:success:failure: of the class TuyaCommunityHouseMemberService to query a list of user types. The value of memberTypeCode in TuyaCommunityMemberTypeModel matches the value of userType.

Query basic information about a house

Returns basic information about a house.

API description

- (void)getHouseInfoWithHouseId:(long long)houseId
                        success:(void(^)(TuyaCommunityHouseModel *result))success
                        failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
houseId The house ID.
success The success callback.
failure The failure callback.

Example

[self.houseManager getHouseInfoWithHouseId:@"xxx"
                                   success:^(TuyaCommunityHouseModel * _Nonnull result) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Query the result of reviewing a house

Returns the reviewing status of a house.

API description

- (void)getHouseAuditResultWithCommunityId:(NSString *)communityId
                                roomUserId:(NSString *)roomUserId
                                   success:(void(^)(TuyaCommunityHouseAuditStatus auditStatus, NSString *msg))success
                                   failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
communityId The community ID.
roomUserId The ID of the mapping between a house and a user.
success The success callback.
failure The failure callback.

Example

[self.houseManager getHouseAuditResultWithCommunityId:@"xxx"
                                           roomUserId:@"xxx"
                                              success:^(TuyaCommunityHouseAuditStatus auditStatus, NSString * _Nonnull msg) {
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Transfer out of a house

Transfers a user out of a house if the user’s property ownership is changed, a lease expires, or due to other reasons.

API description

- (void)moveOutHouseWithCommunityId:(NSString *)communityId
                         roomUserId:(NSString *)roomUserId
                            success:(void(^)(void))success
                            failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
communityId The community ID.
roomUserId The ID of the mapping between a house and a user.
success The success callback.
failure The failure callback.

Example

[self.houseManager moveOutHouseWithCommunityId:@"xxx"
                                    roomUserId:@"xxx"
                                       success:^{
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

Delete a house

Deletes a house if the house is pending reviewing, the house user is transferred out of the house, or failed to pass the reviewing.

API description

- (void)deleteHouseWithCommunityId:(NSString *)communityId
                           houseId:(long long)houseId
                           success:(void(^)(void))success
                           failure:(void(^)(NSError *error))failure;

Parameters

Parameter Description
communityId The community ID.
houseId The house ID.
success The success callback.
failure The failure callback.

Example

[self.houseManager deleteHouseWithCommunityId:@"xxx"
                                      houseId:@"xxx"
                                      success:^{
    // success handler
} failure:^(NSError * _Nonnull error) {
    // failure handler
}];

TuyaCommunityHouseManagerDelegate protocol

Enables follow-up operations after a house is deleted, the house reviewing status is changed, or an MQTT connection is built, thanks to the implemented protocol TuyaCommunityHouseManagerDelegate.

API description

// The callback that is executed when a house is added.
- (void)houseManager:(TuyaCommunityHouseManager *)houseManager didAddHouse:(TuyaCommunityHouseModel *)house;

// The callback that is executed when a house is deleted.
- (void)houseManager:(TuyaCommunityHouseManager *)houseManager didRemoveHouse:(long long)houseId;

// The callback that is executed when the reviewing status of a house is changed.
- (void)houseManager:(TuyaCommunityHouseManager *)houseManager didUpdateHouseAuditStatus:(TuyaCommunityHouseModel *)house;

// An MQTT connection is built.
// Note: An MQTT persistent connection is closed after the program enters the background, and restarted after the program enters the foreground. Therefore, the current house details must be queried again using the delegate to keep the current house data up to date.
- (void)houseManagerServiceConnectedSuccess:(TuyaCommunityHouseManager *)houseManager;

Object description

TuyaCommunityHouseModel

Property Type Description
communityId NSString The community ID.
communityName NSString The name of a community.
houseAddress NSString The address of a house.
houseId long long The house ID.
houseName NSString The name of a house.
auditStatus TuyaCommunityHouseAuditStatus The reviewing status of a house. Valid values:
  • TuyaCommunityHouseAuditStatusPending: pending reviewing
  • TuyaCommunityHouseAuditStatusPass: approved
  • TuyaCommunityHouseAuditStatusFailure: rejected
  • TuyaCommunityHouseAuditStatusMovedOut: transferred out of a house
guestHouse BOOL Specifies whether a user is a guest.
userTypeName NSString The type of the current user.
memberNum NSInteger The number of members in a house.
roomUserId NSString The ID of the mapping between a house and a user.
roomId NSString The room ID.
name NSString The name of a house.
admin BOOL Indicates whether a user is granted smart home permissions, including the smart home owner’s or administrator’s permissions.
geoName NSString The geographical location of a house.
longitude double The longitude of the house.
latitude double The latitude of the house.
dealStatus TuyaCommunityMemberInviteStatus The status of a member’s request to join a house. Valid values:
  • TuyaCommunityMemberInviteStatusPending: pending acception
  • TuyaCommunityMemberInviteStatusAccept: accepted
  • TuyaCommunityMemberInviteStatusReject: rejected
role TuyaCommunityMemberRole The role of the member. Valid values:
  • TuyaCommunityMemberRoleCustom: custom member.
  • TuyaCommunityMemberRoleMember: house member.
  • TuyaCommunityMemberRoleAdmin: administrator.
  • TuyaCommunityMemberRoleOwner: house owner.
  • TuyaCommunityMemberRoleUnknown: invalid member. A member will become invalid in specific conditions.
rooms NSArray<TuyaCommunityRoomModel> A list of rooms.
nickName NSString The nickname of an inviter.
propertyCompanyName NSString The name of a property company.

TuyaCommunityModel

Property Type Description
communityName NSString The name of a community.
communityId NSString The community ID.

TuyaCommunityListModel

Property Type Description
city NSString The city.
hasLocation BOOL Indicates whether the location is included.
list NSArray<TuyaComunityModel> A list of communities.

TuyaCommunityHouseTreeModel

Property Type Description
spaceTreeName NSString A space tree that includes information subordinate to a community, for example, Building 1 and Unit 1.
spaceTreeId NSString The node ID of a space tree subordinate to a community. The value of spaceTreeId for the bottom level is a room ID.
hasMore BOOL Indicates whether subordinate levels are included.

TuyaCommunityHouse

Property Type Description
houseModel TuyaCommunityHouseModel The information about a house.
delegate id<TuyaCommunityHouseDelegate> The delegate of a house.
roomList NSArray<TuyaCommunityRoomModel> A list of sorted rooms.
deviceList NSArray<TuyaSmartDeviceModel> A list of devices.
groupList NSArray<TuyaSmartGroupModel> A list of groups.
sharedDeviceList NSArray<TuyaSmartDeviceModel> A list of shared devices.
sharedGroupList NSArray<TuyaSmartGroupModel> A list of shared groups.