Last Updated on : 2026-02-26 07:15:08download
All features related to home member management correspond to the TSmartMember class. You can add, modify, query, and delete home members, manage member permissions, and manage home invitations.
| Class name | Description |
|---|---|
| TSmartMember | The home member management class. |
| TSmartHomeMemberBean | The data model for home member information. |
| TSmartHomeRoleType | The enumeration of home member role types. |
API description
static getInstance(): TSmartMember
Sample code
import { TSmartMember } from '@thingsmart/homelib';
const smartMember = TSmartMember.getInstance();
A home owner that is specified by HOME_ROLE_TYPE_OWNER can add an administrator and other members with lower permissions. An administrator that is specified by HOME_ROLE_TYPE_ADMIN can only add common members and other members with lower permissions.
API description
public async addMember(requestParams: AddMemberRequestParams): Promise<TSmartAtopResponse<number>>
Parameters
| Parameter | Description |
|---|---|
| requestParams | The request parameter object for adding a member. |
AddMemberRequestParams data model
| Field | Type | Description |
|---|---|---|
| homeId | number | The home ID. |
| name | string | The nickname set for the invitee. |
| account | string | The invitee’s account. It can be a mobile phone number or an email address. |
| countryCode | string | The country code of the invitee’s account. |
| role | TSmartHomeRoleType | The role of the member. |
| headPic | string | (Optional) The avatar URL of the invitee. If the value is set to null, the invitee’s personal avatar is used. |
| autoAccept | boolean | Specifies whether to accept an invitation automatically. Valid values:
|
Return values
Returns Promise<TSmartAtopResponse<number>>, where result is the member ID.
Sample code
import { TSmartMember, AddMemberRequestParams, TSmartHomeRoleType } from '@thingsmart/homelib';
const smartMember = TSmartMember.getInstance();
const params: AddMemberRequestParams = {
homeId: 123456,
name: 'Alice',
account: '13800138000',
countryCode: '86',
role: TSmartHomeRoleType.HOME_ROLE_TYPE_MEMBER,
autoAccept: false
};
try {
const response = await smartMember.addMember(params);
if (response.success) {
const memberId = response.result;
console.log('Added a member successfully, member ID:', memberId);
} else {
console.error('Failed to add a member:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while adding a member:', error);
}
A home owner that is specified by HOME_ROLE_TYPE_OWNER can remove an administrator and other members with lower permissions. An administrator that is specified by HOME_ROLE_TYPE_ADMIN can only remove common members and other members with lower permissions.
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.API description
public async removeMember(memberId: number): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| memberId | The member ID. |
Sample code
const smartMember = TSmartMember.getInstance();
const memberId = 789;
try {
const response = await smartMember.removeMember(memberId);
if (response.success) {
console.log('Removed the member successfully');
} else {
console.error('Failed to remove the member:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while removing a member:', error);
}
API description
public async getMemberList(homeId: number): Promise<TSmartAtopResponse<Array<TSmartHomeMemberBean>>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
Return values
Returns Promise<TSmartAtopResponse<Array<TSmartHomeMemberBean>>>, containing the list of members.
Sample code
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
try {
const response = await smartMember.getMemberList(homeId);
if (response.success) {
const memberList = response.result;
memberList.forEach((member) => {
console.log('Member ID:', member.memberId, 'Member name:', member.name, 'Role:', member.role);
});
} else {
console.error('Failed to query member list:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while querying the member list:', error);
}
A home owner that is specified by HOME_ROLE_TYPE_OWNER can modify an administrator and other members with lower permissions. An administrator that is specified by HOME_ROLE_TYPE_ADMIN can only modify common members and other members with lower permissions.
API description
public async updateMember(requestParams: MemberRequestParams): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| requestParams | The request parameter object for updating a member. |
MemberRequestParams data model
| Field | Type | Description |
|---|---|---|
| memberId | number | The member ID. |
| name | string | (Optional) The member’s nickname. |
| role | TSmartHomeRoleType | (Optional) The member’s role. |
| headPic | string | (Optional) The avatar URL of the member. |
Sample code
import { TSmartMember, MemberRequestParams, TSmartHomeRoleType } from '@thingsmart/homelib';
const smartMember = TSmartMember.getInstance();
const params: MemberRequestParams = {
memberId: 789,
name: 'James',
role: TSmartHomeRoleType.HOME_ROLE_TYPE_ADMIN
};
try {
const response = await smartMember.updateMember(params);
if (response.success) {
console.log('Updated member information successfully');
} else {
console.error('Failed to update member information:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while updating member information:', error);
}
API description
public async updateMemberName(memberId: number, name: string): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| memberId | The member ID. |
| name | The member’s new nickname. |
Sample code
const smartMember = TSmartMember.getInstance();
const memberId = 789;
try {
const response = await smartMember.updateMemberName(memberId, 'Helen');
if (response.success) {
console.log('Updated member nickname successfully');
} else {
console.error('Failed to update member nickname:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while updating member nickname:', error);
}
API description
Queries the list of devices that are linked with the specified member.
public async getMemberDeviceList(memberId: number): Promise<TSmartAtopResponse<Record<string, Object>>>
Parameters
| Parameter | Description |
|---|---|
| memberId | The member ID. |
Sample code
const smartMember = TSmartMember.getInstance();
const memberId = 789;
try {
const response = await smartMember.getMemberDeviceList(memberId);
if (response.success) {
const deviceList = response.result;
console.log('List of devices linked with the member:', deviceList);
}
} catch (error) {
console.error('An error occurred while querying the list of devices linked with the member:', error);
}
API description
Links an account with a member of the specified role.
public async addMemberAccountRole(requestParams: MemberAccountRoleReqParams): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| requestParams | The request parameter object for linking an account. |
MemberAccountRoleReqParams data model
| Field | Type | Description |
|---|---|---|
| homeId | number | The home ID. |
| memberId | number | The member ID. |
| account | string | The account. It can be a mobile phone number or email address. |
| countryCode | string | The country code. |
| role | TSmartHomeRoleType | The role type. |
Sample code
import { TSmartMember, MemberAccountRoleReqParams, TSmartHomeRoleType } from '@thingsmart/homelib';
const smartMember = TSmartMember.getInstance();
const params: MemberAccountRoleReqParams = {
homeId: 123456,
memberId: 789,
account: '13800138000',
countryCode: '86',
role: TSmartHomeRoleType.HOME_ROLE_TYPE_MEMBER
};
try {
const response = await smartMember.addMemberAccountRole(params);
if (response.success) {
console.log('Linked the account successfully');
} else {
console.error('Failed to link the account:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while linking the account:', error);
}
API description
Gets the authorization status of a specified member for rooms under the current home.
public async getAuthRoomList(homeId: number, memberId: number): Promise<TSmartAtopResponse<Array<RoomAuthBean>>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
| memberId | The member ID. |
Return values
Returns Promise<TSmartAtopResponse<Array<RoomAuthBean>>>, containing the list of room authorizations.
RoomAuthBean data model
| Field | Type | Description |
|---|---|---|
| auth | boolean | Specifies whether the account has operation permissions. |
| name | string | The room name. |
| roomId | number | The room ID. |
| type | number | The room type. |
Sample code
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
const memberId = 789;
try {
const response = await smartMember.getAuthRoomList(homeId, memberId);
if (response.success) {
const authRoomList = response.result;
authRoomList.forEach((room) => {
console.log('Room:', room.name, 'Authorization status:', room.auth);
});
}
} catch (error) {
console.error('An error occurred while querying the room authorization status:', error);
}
API description
Saves the authorization of a specified member for rooms under the current home.
public async saveAuthRoomList(homeId: number, memberId: number, rooms: Array<number>): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
| memberId | The member ID. |
| rooms | The list of room IDs for which you wish to authorize or revoke authorization. |
Sample code
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
const memberId = 789;
const rooms = [101, 102, 103];
try {
const response = await smartMember.saveAuthRoomList(homeId, memberId, rooms);
if (response.success) {
console.log('Saved room authorization successfully');
} else {
console.error('Failed to save room authorization:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while saving room authorization:', error);
}
API description
Gets the authorization status of a specified member for scenes under the current home.
public async getAuthSceneList(homeId: number, memberId: number): Promise<TSmartAtopResponse<Array<SceneAuthBean>>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
| memberId | The member ID. |
Return values
Returns Promise<TSmartAtopResponse<Array<SceneAuthBean>>>, containing the list of scene authorizations.
SceneAuthBean data model
| Field | Type | Description |
|---|---|---|
| auth | boolean | Specifies whether the account has operation permissions. |
| name | string | The scene name. |
| ruleId | string | The scene ID. |
| ruleGenre | number | The scene type. It can be an automation scene or a standard scene. |
| displayColor | string | The background color. |
| background | string | The URL of the background image. |
Sample code
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
const memberId = 789;
try {
const response = await smartMember.getAuthSceneList(homeId, memberId);
if (response.success) {
const authSceneList = response.result;
authSceneList.forEach((scene) => {
console.log('Scene:', scene.name, 'Authorization status:', scene.auth);
});
}
} catch (error) {
console.error('An error occurred while querying the scene authorization status:', error);
}
API description
Saves the authorization of a specified member for scenes under the current home.
public async saveAuthSceneList(homeId: number, memberId: number, ruleIds: Array<string>): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
| memberId | The member ID. |
| ruleIds | The list of scene IDs for which you wish to authorize or revoke authorization. |
Sample code
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
const memberId = 789;
const ruleIds = ['rule_001', 'rule_002', 'rule_003'];
try {
const response = await smartMember.saveAuthSceneList(homeId, memberId, ruleIds);
if (response.success) {
console.log('Saved the scene authorization successfully');
} else {
console.error('Failed to save the scene authorization:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while saving the scene authorization:', error);
}
API description
A member accepts or declines an invitation to join a home.
public async acceptHomeInvitation(homeId: number, accept: boolean): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
| accept |
|
Sample code
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
// Accept the invitation
try {
const response = await smartMember.acceptHomeInvitation(homeId, true);
if (response.success) {
console.log('Accepted the invitation successfully');
}
} catch (error) {
console.error('An error occurred while accepting the invitation:', error);
}
// Decline the invitation
try {
const response = await smartMember.acceptHomeInvitation(homeId, false);
if (response.success) {
console.log('Declined the invitation successfully');
}
} catch (error) {
console.error('An error occurred while declining the invitation:', error);
}
API description
Generates invitation information to join a home, including invitation code and invitation text.
public async getInvitationMessage(homeId: number, role: TSmartHomeRoleType, customRoleId?: number): Promise<TSmartAtopResponse<InviteMessageBean>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
| role | The role of the member. |
| customRoleId | The ID of a custom role. It is only used if the role is HOME_ROLE_TYPE_CUSTOM. |
Return values
Returns Promise<TSmartAtopResponse<InviteMessageBean>>.
InviteMessageBean data model
| Field | Type | Description |
|---|---|---|
| invitationMsgContent | string | The invitation text. |
| invitationCode | string | The invitation code. |
Sample code
import { TSmartMember, TSmartHomeRoleType } from '@thingsmart/homelib';
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
try {
const response = await smartMember.getInvitationMessage(homeId, TSmartHomeRoleType.HOME_ROLE_TYPE_MEMBER);
if (response.success) {
const invitation = response.result;
console.log('Invitation code:', invitation.invitationCode);
console.log('Invitation text:', invitation.invitationMsgContent);
}
} catch (error) {
console.error('An error occurred while getting invitation information:', error);
}
API description
Gets the home information based on the invitation code.
public async getInvitationFamilyInfo(inviteCode: string): Promise<TSmartAtopResponse<InviteFamilyInfoBean>>
Parameters
| Parameter | Description |
|---|---|
| inviteCode | The invitation code. |
Return values
Returns Promise<TSmartAtopResponse<InviteFamilyInfoBean>>.
InviteFamilyInfoBean data model
| Field | Type | Description |
|---|---|---|
| groupId | number | The ID of the home to join. |
| groupName | string | The name of the home to join. |
Sample code
const smartMember = TSmartMember.getInstance();
const inviteCode = 'ABC123';
try {
const response = await smartMember.getInvitationFamilyInfo(inviteCode);
if (response.success) {
const familyInfo = response.result;
console.log('Home ID:', familyInfo.groupId);
console.log('Home name:', familyInfo.groupName);
}
} catch (error) {
console.error('An error occurred while getting the home information:', error);
}
API description
Resends an invitation to join a home.
public async reInviteMember(invitationId: number): Promise<TSmartAtopResponse<InviteMessageBean>>
Parameters
| Parameter | Description |
|---|---|
| invitationId | The ID of a specified invitation. |
Sample code
const smartMember = TSmartMember.getInstance();
const invitationId = 999;
try {
const response = await smartMember.reInviteMember(invitationId);
if (response.success) {
const invitation = response.result;
console.log('Resent an invitation successfully. Invitation code:', invitation.invitationCode);
}
} catch (error) {
console.error('An error occurred while resending an invitation:', error);
}
API description
Cancels an invitation sent to a member.
public async cancelInviteMember(invitationId: number): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| invitationId | The ID of a specified invitation. |
Sample code
const smartMember = TSmartMember.getInstance();
const invitationId = 999;
try {
const response = await smartMember.cancelInviteMember(invitationId);
if (response.success) {
console.log('Canceled the invitation successfully');
}
} catch (error) {
console.error('An error occurred while canceling the invitation:', error);
}
API description
Queries the list of invitation records.
public async getInvitationList(homeId: number): Promise<TSmartAtopResponse<Array<InviteMemberInfoBean>>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
Return values
Returns Promise<TSmartAtopResponse<Array<InviteMemberInfoBean>>>.
InviteMemberInfoBean data model
| Field | Type | Description |
|---|---|---|
| invitationId | number | The ID of a specified invitation. |
| invitationCode | string | The invitation code. |
| validTime | number | The validity period, in hours. |
Sample code
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
try {
const response = await smartMember.getInvitationList(homeId);
if (response.success) {
const invitationList = response.result;
invitationList.forEach((invitation) => {
console.log('Invitation ID:', invitation.invitationId, 'Invitation code:', invitation.invitationCode);
});
}
} catch (error) {
console.error('An error occurred while querying invitation records:', error);
}
API description
Updates the information of invitees in an invitation.
public async updateInvitationMemberInfo(requestParams: MemberInvitationReqParams): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| requestParams | The request parameter object for updating the invitation. |
MemberInvitationReqParams data model
| Field | Type | Description |
|---|---|---|
| invitationId | number | The ID of a specified invitation. |
| name | string | The invitee’s nickname. |
| headPic | string | The avatar URL of the invitee. |
Sample code
import { TSmartMember, MemberInvitationReqParams } from '@thingsmart/homelib';
const smartMember = TSmartMember.getInstance();
const params: MemberInvitationReqParams = {
invitationId: 999,
name: 'Amanda',
headPic: 'https://example.com/avatar.jpg'
};
try {
const response = await smartMember.updateInvitationMemberInfo(params);
if (response.success) {
console.log('Updated invitation information successfully');
}
} catch (error) {
console.error('An error occurred while updating invitation information:', error);
}
API description
Transfers ownership of the home to another member. Only the current owner of the home can perform this action.
public async transferOwner(homeId: number, memberId: number): Promise<TSmartAtopResponse<boolean>>
Parameters
| Parameter | Description |
|---|---|
| homeId | The home ID. |
| memberId | The ID of the target member, who will become the new owner. |
Return values
Returns Promise<TSmartAtopResponse<boolean>>. true is returned on success.
Sample code
import { TSmartMember } from '@thingsmart/homelib';
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
const newOwnerId = 789;
try {
const response = await smartMember.transferOwner(homeId, newOwnerId);
if (response.success) {
console.log('Transferred home ownership permissions successfully');
} else {
console.error('Failed to transfer home ownership permissions:', response.errorMsg);
}
} catch (error) {
console.error('An error occurred while transferring home ownership permissions:', error);
}
Application scenario
// Scenario 1: Before leaving a home, the owner needs to transfer ownership permissions first
async function transferBeforeLeave() {
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
const adminMemberId = 789; // Select an administrator as the new owner
try {
// Transfer owner permissions first
const transferResponse = await smartMember.transferOwner(homeId, adminMemberId);
if (transferResponse.success) {
console.log('Permissions transferred successfully. You can safely leave the home');
// Now you can safely leave the home
// await smartMember.removeMember(myMemberId);
}
} catch (error) {
console.error('Failed to transfer the permissions:', error);
}
}
// Scenario 2: The home owner is unable to continue managing for some reason, and designates a new responsible person
async function designateNewOwner() {
const smartMember = TSmartMember.getInstance();
const homeId = 123456;
const trustedMemberId = 999; // Trusted member
try {
const response = await smartMember.transferOwner(homeId, trustedMemberId);
if (response.success) {
console.log('Home management permissions have been successfully transferred to the new responsible person');
}
} catch (error) {
console.error('Failed to transfer the permissions:', error);
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback