Home Management UI BizBundle

Last Updated on : 2023-09-19 03:01:04download

Home Management UI BizBundle is used to implement features such as management of homes, members, and rooms. It provides the basis to manage paired devices. Each home is the maximum scope in which smart scenes can be run.

Users can assign rooms to devices for homes. Home members can be granted different permissions on preferred operations.

Integrate with the UI BizBundle

Add the components of the Home Management UI BizBundle to the Podfile and run the command pod update.

source 'https://github.com/tuya/tuya-pod-specs.git'
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'

target 'your_target_name' do
  # Adds the Smart Life App SDK.
  pod "ThingSmartHomeKit"
  # Adds the UI BizBundle.
  pod 'ThingSmartFamilyBizBundle'
end

Service protocols

The UI BizBundle relies on the implementation of the protocol ThingFamilyProtocol to provide services. You can view the file ThingFamilyProtocol.h in the component ThingModuleServices.

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef void(^DoneActionBlock)(NSString *changedName);

/// Home Management Service
@protocol ThingFamilyProtocol <NSObject>

@optional

/// jump to Home Management ViewController
- (void)gotoFamilyManagement;

/// update current home id, and make sure call this method whenever you change the current home id
- (void)updateCurrentFamilyId:(long long)familyId;

/// get current home id , you can create a `ThingSmartHome` instance by calling the class method `[ThingSmartHome homeWithHomeId:currentFamilyId]`.
- (long long)currentFamilyId;

/// clear current home id cache
- (void)clearCurrentFamily;

@end

Things to note

  • Before the call of any API method, make sure that the user has logged in to the app.
  • Before - (long long)currentFamilyId; is called to get the current home ID, if home information is updated, you must call - (void)updateCurrentFamilyId:(long long)familyId to update the current home ID.
  • Make sure the value of is_support_home_manager of thing_custom_config.json is ture.

Navigate to the home management page

ObjC:

#import <ThingModuleServices/ThingModuleServices.h>
#import <ThingSmartBizCore/ThingSmartBizCore.h>

id<ThingFamilyProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingFamilyProtocol)];
if ([impl respondsToSelector:@selector(gotoFamilyManagement)]) {
    [impl gotoFamilyManagement];
}

Swift:

guard let impl = ThingSmartBizCore.sharedInstance().service(of: ThingFamilyProtocol.self) as? ThingFamilyProtocol else {
    return
}
impl.gotoFamilyManagement?()

Add home members

The home settings page provides the feature to add home members in the following two ways:

  • Invitation code: Users can tap Me > Home Management > Join a home and enter an invitation code to join a home.
  • Invitation from another user: Users can go to the Home Management page and accept or reject another user’s invitation to a home.

Determine whether home invitation is accepted or rejected

The value of dealStatus for ThingSmartHomeModel can be used to check whether a home invitation is accepted or rejected.

typedef NS_ENUM(NSUInteger, ThingHomeStatus) {
    ThingHomeStatusPending = 1,      /**< To be processed. The invitee has not determined to join a home. */
    ThingHomeStatusAccept,           /**< The invitee has accepted the invitation to a home. */
    ThingHomeStatusReject            /**< The invitee has rejected the invitation to a home. */
};

Display the invitation dialog box

To implement the invitation dialog box that appears after an invitation is sent, you can set the delegate ThingSmartHomeManager:

- (void)homeManager:(ThingSmartHomeManager *)manager didAddHome:(ThingSmartHomeModel *)home;

ObjC:

ThingSmartHomeManager *manager = [ThingSmartHomeManager new];
manager.delegate = self;

//....
// The following sample code shows the implementation of the current controller delegate.

- (void)homeManager:(ThingSmartHomeManager *)manager didAddHome:(ThingSmartHomeModel *)homeModel {
    if (homeModel.dealStatus <= ThingHomeStatusPending && homeModel.name.length > 0) {
    /// Displays the invitation dialog box.

    /// Accepts the invitation.
    ThingSmartHome *home = [ThingSmartHome homeWithHomeId:homeModel.homeId];
    [home joinFamilyWithAccept:YES success:^(BOOL result) {} failure:^(NSError *error) {}];

    /// Rejects the invitation.
    [home joinFamilyWithAccept:NO success:^(BOOL result) {} failure:^(NSError *error) {}];
    }
}

Swift:

let manager = ThingSmartHomeManager()
manager.delegate = self

//....
// The following sample code shows the implementation of the current controller delegate.

func homeManager(_ manager: ThingSmartHomeManager!, didAddHome homeModel: ThingSmartHomeModel!) {
    if (homeModel.dealStatus.rawValue <= ThingHomeStatus.pending.rawValue) && (homeModel.name.isEmpty == false) {
        /// Displays the invitation dialog box.

        /// Accepts the invitation.
        let home = ThingSmartHome(homeId: homeModel.homeId)
        home?.joinFamily(withAccept: true, success: { (result) in

        }, failure: { (error) in

        })

        /// Rejects the invitation.
        home?.joinFamily(withAccept: false, success: { (result) in

        }, failure: { (error) in

        })

    }
}