Last Updated on : 2024-08-23 09:47:59download
The BizBundle SDK is developed based on the unit of home where users can add, edit, remove devices, and monitor their status changes. After logging in to the app, users can create and manage multiple homes, including creating rooms and adding members to each home.
After successful login, users will be redirected to the app’s homepage. Tapping on home management will display the current home.
if let home = ThingSmartFamilyBiz.sharedInstance().getCurrentFamily() {
currentHomeName.text = home.name
} else {
currentHomeName.text = "No Selection"
}
If there are no homes, use ThingSmartFamilyBiz
to create and manage a home. Users must name the created home. The location and rooms can be set later.
let requestModel = ThingSmartFamilyRequestModel()
requestModel.name = homeName
requestModel.geoName = geoName
requestModel.latitude = latitude
requestModel.longitude = longitude
ThingSmartFamilyBiz.sharedInstance().addFamily(with: requestModel) {[weak self] homeId in
guard let self = self else { return }
let action = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default) { [weak self] _ in
guard let self = self else { return }
self.navigationController?.popViewController(animated: true)
}
Alert.showBasicAlert(on: self, with: NSLocalizedString("Success", comment: ""), message: NSLocalizedString("Successfully added new home.", comment: ""), actions: [action])
} failure: {[weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: NSLocalizedString("Failed to Add New Home", comment: ""), message: errorMessage)
}
Retrieve all homes under the current account.
accept
: Accepted homepending
: Pending acceptancereject
: Declined homeGet the list of homes. Users should select the home they want to delete from their joined homes.
ThingSmartFamilyBiz.sharedInstance().getFamilyList(success: { [weak self] homeList in
guard let self = self else {return}
if let homeList = homeList {
for home in homeList {
switch home.dealStatus {
case .accept :
self.homes.append(home)
case .pending:
print("pending")
case .reject:
print("reject")
@unknown default:
fatalError()
}
}
}
Pass in the homeId
of the home to be deleted. If there are members other than the owner in the home, this method call will fail.
After a home is deleted, all devices in the home will be reset.
ThingSmartFamilyBiz.sharedInstance().deleteFamily(withHomeId: homeModel.homeId) {[weak self] in
guard let self = self else {return}
Alert.showBasicAlert(on: self, with: "Success", message: "Delete home \(homeModel.name!)")
self.homes.remove(at: indexPath.row)
self.selectHomeModel = nil
self.index = nil
tableView.reloadData()
} failure: { [weak self] error in
guard let self = self else {return}
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: "Failed to delete home", message: "\(errorMessage)")
}
Get the home details. A success callback returns the home model that contains the list of devices.
ThingSmartFamilyBiz.sharedInstance().getFamilyDetail(withHomeId: homeModel!.homeId) { [weak self] home in
guard let self = self else {return}
deviceList = home?.deviceList ?? []
self.tableView.reloadData()
} failure: { [weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: "Failed to Fetch home detail", message: errorMessage)
}
Implement ThingSmartFamilyBizDelegate
. Implement the callback as needed. For more information, see the API reference documentation.
extension BEHomeDetailViewController : ThingSmartFamilyBizDelegate {
func familyBiz(_ familyBiz: ThingSmartFamilyBiz!, didUpdateHome homeModel: ThingSmartHomeModel!) {
if let home = homeModel {
self.homeModel = home
setupUI()
}
}
}
Up to 200 rooms can be created in a home. The room name and the associated home ID are the required parameters. After a device is paired, it can be assigned to a room.
ThingSmartRoomBiz.sharedInstance().addHomeRoom(withName: roomName, homeId: currentHome.homeId) { [weak self] roomModel in
guard let self = self else { return }
let action = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default) { [weak self] _ in
guard let self = self else { return }
self.navigationController?.popViewController(animated: true)
}
Alert.showBasicAlert(on: self, with: NSLocalizedString("Success", comment: ""), message: "Add Room", actions: [action])
} failure: {[weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: "Failed to Add Room", message: errorMessage)
}
You can also retrieve the list of recommended room names for easy assignment.
ThingSmartRoomBiz.sharedInstance().getRecommendRooms {[weak self] rooms in
guard let self = self else {return}
self.recommendRoomNames = rooms ?? []
self.tableView.reloadData()
} failure: {[weak self] error in
guard let self = self else {return}
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: "Failed to Get Recommend Room", message: errorMessage)
}
Get the list of rooms in a home.
ThingSmartRoomBiz.sharedInstance().getRoomList(withHomeId: model.homeId) {[weak self] rooms in
guard let self = self else {return}
self.roomList = rooms ?? []
self.tableView.reloadData()
} failure: { [weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: "Failed to Get Room", message: errorMessage)
}
To delete a room, select the room to be deleted and pass in the homeId
and roomId
.
ThingSmartRoomBiz.sharedInstance().removeHomeRoom(withRoomId: room.roomId, homeId: home.homeId) {[weak self] in
guard let self = self else { return }
let action = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default) { [weak self] _ in
guard let self = self else { return }
self.navigationController?.popViewController(animated: true)
}
Alert.showBasicAlert(on: self, with: NSLocalizedString("Success", comment: ""), message: "Delete Room", actions: [action])
} failure: { error in
}
A home owner can add admins and common members, while an admin can only add common members.
Add a member by app account
To add a member, pass in the member name, country code, account, and role (0
for common member and 1
for admin).
let requestModel = ThingSmartHomeAddMemberRequestModel()
requestModel.name = nameField.text ?? ""
requestModel.account = accountField.text ?? ""
requestModel.countryCode = codeField.text ?? ""
if role == "0" {
requestModel.role = .member
} else if role == "1" {
requestModel.role = .admin
} else {
Alert.showBasicAlert(on: self, with: "Failed to Add Member", message: "role value is invalid, input 0 or 1")
return
}
ThingSmartMemberBiz.sharedInstance().addHomeMember(with: requestModel, homeId: homeId) {[weak self] member in
guard let self = self else { return }
let action = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default) { [weak self] _ in
guard let self = self else { return }
self.navigationController?.popViewController(animated: true)
}
Alert.showBasicAlert(on: self, with: NSLocalizedString("Success", comment: ""), message: "Add Member", actions: [action])
} failure: { [weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: "Failed to Add Member", message: errorMessage)
}
After a successful method call, switch to the account that is invited to join the home. A new home will be created under the invitee’s account, with the home status being pending
. The invitee can choose to accept or decline this home invitation.
Accept a home invitation:
ThingSmartFamilyBiz.sharedInstance().acceptJoinFamily(withHomeId: model.homeId) {[weak self] _ in
guard let self = self else {return}
homes.remove(at: indexPath.row)
self.tableView.reloadData()
} failure: {[weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: NSLocalizedString("Failed to Accept Home", comment: ""), message: errorMessage)
}
Decline a home invitation:
ThingSmartFamilyBiz.sharedInstance().rejectJoinFamily(withHomeId: model.homeId) {[weak self] _ in
guard let self = self else {return}
homes.remove(at: indexPath.row)
self.tableView.reloadData()
} failure: {[weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: NSLocalizedString("Failed to Reject Home", comment: ""), message: errorMessage)
}
Get the list of members in a home.
ThingSmartMemberBiz.sharedInstance().getHomeMemberList(withHomeId: model.homeId) {[weak self] members in
guard let self = self else { return }
self.memberList = members
self.tableView.reloadData()
} failure: {[weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: "Failed to get member list", message: errorMessage)
}
To delete a member, select the member to be deleted and pass in the memberId
.
ThingSmartMemberBiz.sharedInstance().removeHomeMember(withMemberId: member!.memberId) {[weak self] in
guard let self = self else { return }
let action = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default) { [weak self] _ in
guard let self = self else { return }
self.navigationController?.popViewController(animated: true)
}
Alert.showBasicAlert(on: self, with: NSLocalizedString("Success", comment: ""), message: "Delete Member", actions: [action])
} failure: {[weak self] error in
guard let self = self else { return }
let errorMessage = error?.localizedDescription ?? ""
Alert.showBasicAlert(on: self, with: "Failed to Delete Member", message: errorMessage)
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback