Member Information Management

Last Updated on : 2024-08-15 10:00:20download

Functional description

The capabilities to manage home member information depend on ThingSmartHomeInvitation and ThingSmartHomeMember of ThingSmartHome. ThingHomeRoleType specifies a type of member role.

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

Add a home member

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

API description

The autoAccept field of the ThingSmartHomeAddMemberRequestModel 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 ThingSmartHome - joinFamilyWithAccept:success:failure:, so the invitee needs to accept the invitation before joining the home.

- (void)addHomeMemberWithAddMemeberRequestModel:(ThingSmartHomeAddMemberRequestModel *)requestModel success:(ThingSuccessDict)success failure:(ThingFailureError)failure;

Parameters

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

Data model of ThingSmartHomeAddMemberRequestModel

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 ThingHomeRoleType 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 ThingHomeRoleType_Owner can remove an administrator and other members with lower permissions. An administrator that is specified by ThingHomeRoleType_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:(ThingSuccessHandler)success
                            failure:(ThingFailureError)failure;

Parameters

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

Example

ObjC:

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

Swift:

func removeMember(_ memberModel: ThingSmartHomeMemberModel) {
    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 <ThingSmartHomeMemberModel *> *memberList))success failure:(ThingFailureError)failure;

Parameters

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

Example

ObjC:

- (void)initMemberList {
 // _home = [ThingSmartHome homeWithHomeId:homeId];
    [_home getHomeMemberListWithSuccess:^(NSArray<ThingSmartHomeMemberModel *> *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 ThingHomeRoleType_Owner can modify an administrator and other members with lower permissions. An administrator that is specified by ThingHomeRoleType_Admin can only modify common members and other members with lower permissions.

API description

- (void)updateHomeMemberInfoWithMemberRequestModel:(ThingSmartHomeMemberRequestModel *)memberRequestModel success:(ThingSuccessHandler)success failure:(ThingFailureError)failure;

Parameters

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

Example

ObjC:

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

Swift:

func modifyMember(_ memberModel: ThingSmartHomeMemberModel, 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 ThingSmartHomeInvitation.

- (void)createInvitationWithCreateRequestModel:(ThingSmartHomeInvitationCreateRequestModel *)createRequestModel
                                    success:(void(^)(ThingSmartHomeInvitationResultModel *invitationResultModel))success
                                    failure:(ThingFailureError)failure;

The homeID field of ThingSmartHomeInvitationCreateRequestModel 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 ThingSmartHomeInvitationCreateRequestModel

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

Example

ObjC:

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

Swift:

let requestModel = ThingSmartHomeInvitationCreateRequestModel()
requestModel.homeID = homeID
requestModel.needMsgContent = true
self.smartHomeInvitation = ThingSmartHomeInvitation()
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 ThingSmartHomeInvitation.

- 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:(ThingSuccessBOOL)success
                        failure:(ThingFailureError)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 ThingSmartHomeInvitation.

- (void)cancelInvitationWithInvitationID:(NSNumber *)invitationID
                                success:(ThingSuccessBOOL)success
                                failure:(ThingFailureError)failure;

Parameters

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

Example

ObjC:

- (void)cancelInvitationWithInvitationID:(NSNumber *)invitationID
                                success:(ThingSuccessBOOL)success
                                failure:(ThingFailureError)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 ThingSmartHomeModel. Valid values: ThingHomeStatusPending, ThingHomeStatusAccept, and ThingHomeStatusReject. 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:(ThingSuccessBOOL)success
                    failure:(ThingFailureError)failure;

Parameters

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

Example

ObjC:

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

Swift:

func initMemberList(_ memberModel: ThingSmartHomeMemberModel) {
    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 ThingSmartHomeInvitation.

- (void)fetchInvitationRecordListWithHomeID:(long long)homeID
                                    success:(void(^)(NSArray<ThingSmartHomeInvitationRecordModel *> *invitationRecordList))success
                                    failure:(ThingFailureError)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<ThingSmartHomeInvitationRecordModel *> *invitationRecordList))success
                                    failure:(ThingFailureError)failure {
    [self.smartHomeInvitation fetchInvitationRecordListWithHomeID:homeID success:success failure:failure];
}

Swift:

func fetchInvitationHomeInfo(
    withInvitationCode invitationCode: String?,
    success: @escaping (_ homeModel: ThingSmartHomeModel?) -> 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 ThingSmartHomeInvitation.

- (void)updateInvitationInfoWithInvitationInfoRequestModel:(ThingSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
                                                success:(ThingSuccessBOOL)success
                                                failure:(ThingFailureError)failure;

Parameters

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

Example

ObjC:

- (void)updateInvitationInfoWithInvitationInfoRequestModel:(ThingSmartHomeInvitationInfoRequestModel *)invitationInfoRequestModel
                                                success:(ThingSuccessBOOL)success
                                                failure:(ThingFailureError)failure {
    [self.smartHomeInvitation updateInvitationInfoWithInvitationInfoRequestModel:invitationInfoRequestModel success:success failure:failure];
}

Swift:

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