English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Home Management UI BizBundle

Last Updated on : 2022-03-15 07:44:55download

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/TuyaInc/TuyaPublicSpecs.git"
source 'https://cdn.cocoapods.org/'

target 'your_target_name' do
  # Adds the Smart Life App SDK.
  pod "TuyaSmartHomeKit"
  # Adds the UI BizBundle.
  pod 'TuyaSmartFamilyBizBundle', '~> 3.22.0'
end

Service protocols

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

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

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

/// Home Management Service
@protocol TYFamilyProtocol <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 `TuyaSmartHome` instance by calling the class method `[TuyaSmartHome 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 ty_custom_config.json is ture.

Navigate to the home management page

ObjC:

#import <TYModuleServices/TYModuleServices.h>
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>

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

Swift:

guard let impl = TuyaSmartBizCore.sharedInstance().service(of: TYFamilyProtocol.self) as? TYFamilyProtocol 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 TuyaSmartHomeModel can be used to check whether a home invitation is accepted or rejected.

typedef NS_ENUM(NSUInteger, TYHomeStatus) {
    TYHomeStatusPending = 1,      /**< To be processed. The invitee has not determined to join a home. */
    TYHomeStatusAccept,           /**< The invitee has accepted the invitation to a home. */
    TYHomeStatusReject            /**< 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 TuyaSmartHomeManager:

- (void)homeManager:(TuyaSmartHomeManager *)manager didAddHome:(TuyaSmartHomeModel *)home;

ObjC:

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

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

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

    /// Accepts the invitation.
    TuyaSmartHome *home = [TuyaSmartHome 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 = TuyaSmartHomeManager()
manager.delegate = self

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

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

        /// Accepts the invitation.
        let home = TuyaSmartHome(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

        })

    }
}