Group Management UI BizBundle

Last Updated on : 2023-07-13 07:14:43download

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/tuya-private-specs"
source 'https://cdn.cocoapods.org/'
platform :ios, '11.0'

target 'your_target_name' do
  # Adds the Group Management UI BizBundle
  pod 'ThingSmartGroupHandleBizBundle'
end

Service protocols

Provide services

The UI BizBundle relies on the implementation of the protocol ThingGroupHandleProtocol to provide services. In the ThingModuleServices component, you can view the ThingGroupHandleProtocol.h file and navigate to ThingGroupHandlePlugAPI.h. The following code block shows the protocol content:

```objc
typedef enum {
ThingGroupHandleTypeSupport,
ThingGroupHandleTypeNotSupport,
ThingGroupHandleTypeInvalid,
} ThingGroupHandleType;

@protocol ThingGroupHandleProtocol <NSObject>
/**

zh^
创建 Wi-Fi 标准或普通群组
zh$

en^
Create standard or common Wi-Fi groups.
en$

@param deviceId zh^  设备 ID zh$ en^ device ID en$
@param completion zh^ 回调 zh$ en^ call back en$
*/
- (void)createWifiGroupWithDeviceId:(NSString *_Nonnull)deviceId completion:(void (^ _Nullable)(ThingGroupHandleType type))completion
__deprecated_msg("Use createGroup:completion: instead");

/**

zh^
编辑 Wi-Fi 标准或普通群组
zh$

en^
Modify standard or common Wi-Fi groups.
en$

@param groupId zh^  群组 ID zh$ en^ group ID en$
@param completion zh^ 回调 zh$ en^ call back en$
*/
- (void)editWifiGroupWithGroupId:(NSString *_Nonnull)groupId completion:(void (^ _Nullable)(ThingGroupHandleType type))completion
__deprecated_msg("Use editGroup:completion: instead");

/**

zh^
创建群组。
zh$

en^
Create standard or common Wi-Fi groups.
en$

@param deviceId zh^ 设备ID zh$ en^ device ID en$
@param completion zh^ 回调 zh$ en^ call back en$
*/
- (void)createGroup:(NSString *_Nonnull)deviceId completion:(void (^ _Nullable)(ThingGroupHandleType type))completion;

/**

zh^
编辑群组
zh$

en^
Modify standard or common Wi-Fi groups.
en$

@param groupId zh^ 群组ID zh$ en^ group ID en$
@param completion zh^ 回调 zh$ en^ call back en$
*/
- (void)editGroup:(NSString *_Nonnull)groupId completion:(void (^ _Nullable)(ThingGroupHandleType type))completion;


@end
```

Depend on services

The UI BizBundle depends on the method provided by the protocol ThingFamilyProtocol. Before you call the UI BizBundle, you must implement the protocol ThingFamilyProtocol to provide the current home information required by the scene component.

Usage instruction

Things to note

  • Before the call of any API method, make sure that the user has logged in to the app.

Create a group

ObjC:

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

- (void)createGroup:(NSString *)deviceId completion:(void (^)(ThingGroupHandleType type))completion{
    id <ThingGroupHandleProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingGroupHandleProtocol)];
    [impl createGroup:deviceId completion:^(ThingGroupHandleType type) {
        switch (type) {
            case ThingGroupHandleTypeInvalid:
                NSLog(@"DeviceId is invalid");
                break;
            case ThingGroupHandleTypeSupport:
                NSLog(@"Support");
                break;
            case ThingGroupHandleTypeNotSupport:
                NSLog(@"Not Support");
                break;
            default:
                break;
        }
    }];
}

Swift:

func createGroup(deviceId: String, completion: @escaping (ThingGroupHandleType) -> Void) {
        let groupImpl = ThingSmartBizCore.sharedInstance().service(of: ThingGroupHandleProtocol.self) as? ThingGroupHandleProtocol
        groupImpl?.createGroup(deviceId, completion: { (type) in
            switch type {
               case ThingGroupHandleTypeInvalid  :
                    print("DeviceId is invalid")
                    break
               case ThingGroupHandleTypeSupport  :
                    print("Support")
                    break
               case ThingGroupHandleTypeNotSupport  :
                    print("NotSupport")
                    break
               default :
                    break
            }
        })
    }

Modify a group

ObjC:

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

- (void)editGroup:(NSString *)groupId completion:(void (^)(ThingGroupHandleType type))completion;{
    id <ThingGroupHandleProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingGroupHandleProtocol)];
    [impl editGroup:groupId completion:^(ThingGroupHandleType type) {
        switch (type) {
            case ThingGroupHandleTypeInvalid:
                NSLog(@"DeviceId is invalid");
                break;
            case ThingGroupHandleTypeSupport:
                NSLog(@"Support");
                break;
            case ThingGroupHandleTypeNotSupport:
                NSLog(@"Not Support");
                break;
            default:
                break;
        }
    }];
}

Swift:

    func editGroup(groupId: String, completion: @escaping (ThingGroupHandleType) -> Void) {
        let groupImpl = ThingSmartBizCore.sharedInstance().service(of: ThingGroupHandleProtocol.self) as? ThingGroupHandleProtocol
        groupImpl?.editGroup(groupId, completion: { (type) in
            switch type {
               case ThingGroupHandleTypeInvalid  :
                    print("DeviceId is invalid")
                    break
               case ThingGroupHandleTypeSupport  :
                    print("Support")
                    break
               case ThingGroupHandleTypeNotSupport  :
                    print("NotSupport")
                    break
               default :
                    break
            }
        })
    }