English
English
简体中文
Contact Us
Register
Log In

Member Information Management

Last Updated on : 2021-11-19 12:11:55download

Functional description

The capabilities to manage home member information depend on TuyaSmartHomeInvitation and TuyaSmartHomeMember of TuyaSmartHome. TYHomeRoleType specifies a type of member role.

Class name (protocol name) Description
TuyaSmartHomeMember Manage home members.

Add a home member

A home owner that is specified by TYHomeRoleType_Owner can add an administrator and other members with lower permissions. An administrator that is specified by TYHomeRoleType_Admin can only add common members and other members with lower permissions.

API description

The autoAccept field of the TuyaSmartHomeAddMemberRequestModel object specifies whether an invitation is automatically accepted to add an invitee to the home. If the value is set to NO, you must call TuyaSmartHome - joinFamilyWithAccept:success:failure:, so the invitee needs to accept the invitation before joining the home.

- (void)addHomeMemberWithAddMemeberRequestModel:(TuyaSmartHomeAddMemberRequestModel *)requestModel success:(TYSuccessDict)success failure:(TYFailureError)failure;

Parameters

Parameter Description
requestModel The request model to add a member.
success The success callback.
failure The failure callback.

Data model of TuyaSmartHomeAddMemberRequestModel

Field Type Description
name NSString The nickname of the invitee.
account NSString The account of the invitee.
countryCode NSString The country code of the invitee’s account.
role TYHomeRoleType The role of the member.
headPic UIImage The avatar of the invitee. If the value is set to nil, the invitee’s personal avatar is used.
autoAccept BOOL Specifies whether the invitation is automatically accepted. Valid values:
  • YES: The invitation is automatically accepted.
  • NO: The invitee needs to accept the invitation before joining the home.

Example

ObjC:

- (void)addShare {
	[self.smartHome addHomeMemberWithAddMemeberRequestModel:requestModel success:^(NSDictionary *dict) {
		NSLog(@"addNewMember success");
	} failure:^(NSError *error) {
		NSLog(@"addNewMember failure");
	}];
}

Swift:

func addShare() {
	home?.addHomeMember(requestModel: requestModel, success: {
		print("addNewMember success")
	}, failure: { (error) in
		if let e = error {
			print("addNewMember failure: \(e)")
		}
	})
}

Remove a member

A home owner that is specified by TYHomeRoleType_Owner can remove an administrator and other members with lower permissions. An administrator that is specified by TYHomeRoleType_Admin can only remove common members and other members with lower permissions.

API description

The home will be processed in varied ways, depending on different values of memberId:

  • If memberId is set to an administrator, common member, or custom role, the member to be removed will leave the home. In this case, the home will not be deleted and its devices will not be reset.
  • If memberId is set to the home owner, the home is deleted and all devices of the home will be reset. The result is the same as that of dismissHome.
- (void)removeHomeMemberWithMemberId:(long long)memberId
							success:(TYSuccessHandler)success
							failure:(TYFailureError)failure;

Parameters

Parameter Description
memberId The member ID.
success The success callback.
failure The failure callback.

Example

ObjC:

- (void)removeMember:(TuyaSmartHomeMemberModel *)memberModel {
	// self.homeMember = [[TuyaSmartHomeMember alloc] init];
	[self.homeMember removeHomeMemberWithMemberId:memberModel.memberId success:^{
		NSLog(@"removeMember success");
	} failure:^(NSError *error) {
		NSLog(@"removeMember failure: %@", error);
	}];
}

Swift:

func removeMember(_ memberModel: TuyaSmartHomeMemberModel) {
	homeMember?.removeHomeMember(withMemberId: memberModel.memberId, success: {
		print("removeMember success")
	}, failure: { (error) in
		if let e = error {
			print("removeMember failure: \(e)")
		}
	})
}

Query a list of home members

API description

- (void)getHomeMemberListWithSuccess:(void(^)(NSArray <TuyaSmartHomeMemberModel *> *memberList))success failure:(TYFailureError)failure;

Parameters

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

Example

ObjC:

- (void)initMemberList {
 //	_home = [TuyaSmartHome homeWithHomeId:homeId];
	[_home getHomeMemberListWithSuccess:^(NSArray<TuyaSmartHomeMemberModel *> *memberList) {
		NSLog(@"getMemberList success: %@", memberList);
	} failure:^(NSError *error) {
		NSLog(@"getMemberList failure");
	}];
}

Swift:

func initMemberList() {
	home.getHomeMemberList(withSuccess: { memberList in
		print("getMemberList success: \(memberList)")
	}, failure: { (error) in
		if let e = error {
			print("getMemberList failure: \(e)")
		}
	})
}

Update member information

A home owner that is specified by TYHomeRoleType_Owner can modify an administrator and other members with lower permissions. An administrator that is specified by TYHomeRoleType_Admin can only modify common members and other members with lower permissions.

API description

- (void)updateHomeMemberInfoWithMemberRequestModel:(TuyaSmartHomeMemberRequestModel *)memberRequestModel success:(TYSuccessHandler)success failure:(TYFailureError)failure;

Parameters

Parameter Description
memberRequestModel The request model to modify a member.
success The success callback.
failure The failure callback.

Example

ObjC:

- (void)modifyMemberName:(TuyaSmartHomeMemberModel *)memberModel name:(NSString *)name {
	// self.homeMember = [[TuyaSmartHomeMember alloc] init];
TuyaSmartHomeMemberRequestModel *requestModel = [[TuyaSmartHomeMemberRequestModel alloc] init];
	[self.homeMember updateHomeMemberInfoWithMemberRequestModel:requestModel success:^{
		NSLog(@"modifyMemberName success");
	} failure:^(NSError *error) {
		NSLog(@"modifyMemberName failure: %@", error);
	}];
}

Swift:

func modifyMember(_ memberModel: TuyaSmartHomeMemberModel, name: String) {
	homeMember?.updateHomeMemberName(withMemberRequestModel:requestModel, success: {
		print("modifyMemberName success")
	}, failure: { (error) in
		if let e = error {
			print("modifyMemberName failure: \(e)")
		}
	})
}

Query the invitation code to add a member

API description

Generates an invitation code by using the instance method of TuyaSmartHomeInvitation.

- (void)createInvitationWithCreateRequestModel:(TuyaSmartHomeInvitationCreateRequestModel *)createRequestModel
									success:(void(^)(TuyaSmartHomeInvitationResultModel *invitationResultModel))success
									failure:(TYFailureError)failure;

The homeID field of TuyaSmartHomeInvitationCreateRequestModel specifies the ID of the home that the member joins.

Parameters

Parameter Description
createRequestModel The request model to generate an invitation code.
success The success callback.
failure The failure callback.

Data model of TuyaSmartHomeInvitationCreateRequestModel

Field Type Description
homeID long long The home ID.
needMsgContent BOOL Specifies whether invitation text is required.

Example

ObjC:

TuyaSmartHomeInvitationCreateRequestModel *requestModel = [[TuyaSmartHomeInvitationCreateRequestModel alloc] init];
requestModel.homeID = homeID;
requestModel.needMsgContent = YES;
self.smartHomeInvitation = [[TuyaSmartHomeInvitation alloc] init];
[self.smartHomeInvitation createInvitationWithCreateRequestModel:requestModel success:success failure:failure];

Swift:

let requestModel = TuyaSmartHomeInvitationCreateRequestModel()
requestModel.homeID = homeID
requestModel.needMsgContent = true
self.smartHomeInvitation = TuyaSmartHomeInvitation()
self.smartHomeInvitation.createInvitation(with: requestModel, success: success, failure: failure)

Join a home with an invitation code

API description

Creates an invitation to join a home by using the class TuyaSmartHomeInvitation.

- joinHomeWithInvitationCode:success:failure:

Parameters

Parameter Description
invitationCode The invitation code.
success The success callback.
failure The failure callback.

Example

ObjC:

- (void)joinHomeWithInvitationCode:(NSString *)invitationCode
						success:(TYSuccessBOOL)success
						failure:(TYFailureError)failure {
	[self.smartHomeInvitation joinHomeWithInvitationCode:invitationCode success:success failure:failure];
}

Swift:

func joinHome(
	withInvitationCode invitationCode: String?,
	success: @escaping (_ result: Bool) -> Void,
	failure: @escaping (_ error: Error?) -> Void
) {
	self.smartHomeInvitation.joinHome(withInvitationCode: invitationCode, success: success, failure: failure)
}

Revoke an invitation to join a home

API description

Revokes an invitation to join a home by using the class TuyaSmartHomeInvitation.

- (void)cancelInvitationWithInvitationID:(NSNumber *)invitationID
								success:(TYSuccessBOOL)success
								failure:(TYFailureError)failure;

Parameters

Parameter Description
invitationID The invitation code.
success The success callback.
failure The failure callback.

Example

ObjC:

- (void)cancelInvitationWithInvitationID:(NSNumber *)invitationID
								success:(TYSuccessBOOL)success
								failure:(TYFailureError)failure {
	[self.smartHomeInvitation cancelInvitationWithInvitationID:invitationID success:success failure:failure];
}

Swift:

func cancelInvitation(
	withInvitationID invitationID: NSNumber?,
	success: @escaping (_ result: Bool) -> Void,
	failure: @escaping (_ error: Error?) -> Void
) {
	self.smartHomeInvitation.cancelInvitation(withInvitationID: invitationID, success: success, failure: failure)
}

Accept or decline an invitation to join a home

API description

Accepts or declines an invitation to join a home. The invitation status is specified by dealStatus of TuyaSmartHomeModel. Valid values: TYHomeStatusPending, TYHomeStatusAccept, and TYHomeStatusReject. The member that declines the invitation can neither access devices for the target home nor query information about the home in the request of a home list.

- (void)joinFamilyWithAccept:(BOOL)accept
					success:(TYSuccessBOOL)success
					failure:(TYFailureError)failure;

Parameters

Parameter Description
accept Specifies whether to accept the invitation.
success The success callback.
failure The failure callback.

Example

ObjC:

- (void)initMemberList {
 //	_home = [TuyaSmartHome homeWithHomeId:homeId];
 	[_home joinFamilyWithAccept:YES success:^(BOOL result) {
		NSLog(@"join success");
	} failure:^(NSError *error) {
		NSLog(@"join failure");
	}];
}

Swift:

func initMemberList(_ memberModel: TuyaSmartHomeMemberModel) {
	home?.joinFamilyWithAccept(true, success: { (result: Bool) in
		print("join success")
	}, failure: { (error) in
		if let e = error {
			print("join failure: \(e)")
		}
	})
}

Query invitation records

API description

Returns invitation records by using the class TuyaSmartHomeInvitation.

- (void)fetchInvitationRecordListWithHomeID:(long long)homeID
									success:(void(^)(NSArray<TuyaSmartHomeInvitationRecordModel *> *invitationRecordList))success
									failure:(TYFailureError)failure;

Parameters

Parameter Description
homeID The home ID.
success The success callback.
failure The failure callback.

Example

ObjC:

- (void)fetchInvitationRecordListWithHomeID:(long long)homeID
									success:(void(^)(NSArray<TuyaSmartHomeInvitationRecordModel *> *invitationRecordList))success
									failure:(TYFailureError)failure {
	[self.smartHomeInvitation fetchInvitationRecordListWithHomeID:homeID success:success failure:failure];
}

Swift:

func fetchInvitationHomeInfo(
	withInvitationCode invitationCode: String?,
	success: @escaping (_ homeModel: TuyaSmartHomeModel?) -> Void,
	failure: @escaping (_ error: Error?) -> Void
) {
	self.smartHomeInvitation.fetchInvitationHomeInfo(withInvitationCode: invitationCode, success: success, failure: failure)
}

Modify invitee information

API description

Modifies an invitee by using the class TuyaSmartHomeInvitation.

- (void)updateInvitationInfoWithInvitationInfoRequestModel:(TuyaSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
												success:(TYSuccessBOOL)success
												failure:(TYFailureError)failure;

Parameters

Parameter Description
TuyaSmartHomeInvitationInfoRequestModel The request model to modify an invitee.
success The success callback.
failure The failure callback.

Example

ObjC:

- (void)updateInvitationInfoWithInvitationInfoRequestModel:(TuyaSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
												success:(TYSuccessBOOL)success
												failure:(TYFailureError)failure {
	[self.smartHomeInvitation updateInvitationInfoWithInvitationInfoRequestModel:invitationInfoRequestModel success:success failure:failure];
}

Swift:

func updateInvitationInfo(
	with invitationInfoRequestModel: TuyaSmartHomeInvitationInfoRequestModel?,
	success: @escaping (_ result: Bool) -> Void,
	failure: @escaping (_ error: Error?) -> Void
) {
	self.smartHomeInvitation.updateInvitationInfo(with: invitationInfoRequestModel, success: success, failure: failure)
}