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

Group Management UI BizBundle

Last Updated on : 2022-06-23 10:36:04download

Group Management UI BizBundle provides the service logic and UI encapsulation for device groups. This allows users to create device groups, and control multiple devices of the same group in each request. You can use the UI BizBundle to implement multiple features. For example, create a group of devices that belong to the same type, and add devices to or delete them from groups.

Integrate with the UI BizBundle

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

source "https://github.com/tuya/TuyaPublicSpecs.git"
source 'https://cdn.cocoapods.org/'

target 'your_target_name' do
  # TuyaSmartResidence SDK
  pod "TuyaSmartResidenceKit"
  # Adds the Group Management UI BizBundle
  pod 'TuyaSmartResidenceGroupHandleBizBundle'
end

Service protocols

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

@protocol TuyaSmartResidenceGroupHandleProtocol <NSObject>
/**
 Creates a group.

 @param deviceId    The device ID.
 @param completion  Indicates whether the device supports group management.
 */
- (void)createGroup:(NSString *_Nonnull)deviceId completion:(void (^ _Nullable)(TYGroupHandleType type))completion;

/**
 Modifies a group.

 @param groupId     The group ID.
 @param completion  The callback.
 */
- (void)editGroup:(NSString *_Nonnull)groupId completion:(void (^ _Nullable)(TYGroupHandleType type))completion;

@end

Usage instruction

Things to note

  • Before the call of any API method, make sure that the user has logged in to the app.
  • Before the UI BizBundle is used, you must first get information about the site specified by site to pass it into the request.
#import <TuyaSmartBizCore/TuyaSmartBizCore.h>
#import <TYModuleServices/TuyaSmartResidenceGroupHandleProtocol.h>

- (void)initCurrentSite {
    self.site = [TuyaResidenceSite siteWithSiteId:@"siteId"];
    [self.site fetchSiteDetailWithSuccess:^(TuyaResidenceSiteModel * _Nonnull siteModel) {

    } failure:^(NSError *error) {

    }];
}

Create a group

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

- (void)createGroup:(NSString *_Nonnull)deviceId completion:(void (^ _Nullable)(TYGroupHandleType type))completion {
    id <TuyaSmartResidenceGroupHandleProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TuyaSmartResidenceGroupHandleProtocol)];
    [impl createGroup:deviceId completion:^(TYGroupHandleType type) {
        switch (type) {
            case TYGroupHandleTypeInvalid:
                NSLog(@"DeviceId is invalid");
                break;
            case TYGroupHandleTypeSupport:
                NSLog(@"Support");
                break;
            case TYGroupHandleTypeNotSupport:
                NSLog(@"Not Support");
                break;
            default:
                break;
        }
    }];
}

Modify a group

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

// The value of `groupId` can be obtained as a sub-element from `site.groupList`.

- (void)editGroup:(NSString *_Nonnull)groupId completion:(void (^ _Nullable)(TYGroupHandleType type))completion {
    id <TuyaSmartResidenceGroupHandleProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TuyaSmartResidenceGroupHandleProtocol)];
    [impl editGroup:groupId completion:^(TYGroupHandleType type) {
        switch (type) {
            case TYGroupHandleTypeInvalid:
                NSLog(@"DeviceId is invalid");
                break;
            case TYGroupHandleTypeSupport:
                NSLog(@"Support");
                break;
            case TYGroupHandleTypeNotSupport:
                NSLog(@"Not Support");
                break;
            default:
                break;
        }
    }];
}