Device Control UI BizBundle

Last Updated on : 2024-04-07 08:29:30download

Device Control UI BizBundle is the core container of the panels for commercial lighting devices. Based on the Commercial Lighting App SDK, the UI BizBundle encapsulates the APIs to load and control panels and accelerates application development. The following features are supported:

  • Panel loading: supports panels of multiple protocols, such as Wi-Fi, Zigbee, Bluetooth mesh, and Bluetooth.
  • Device control: controls a single device and device groups. Device groups cannot be managed.
  • Scheduled tasks: configures scheduled tasks for specific devices.

Integrate with the UI BizBundle

Add the components of the Device Control 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
  # Commercial Lighting SDK
  pod "ThingCommercialLightingKit"
  # Adds the UI BizBundle.
  pod 'ThingCommercialLightingPanelBizBundle', '~> 1.11.5.1'
  # Depends on the robot vacuum plug-ins to integrate with their features if needed.
  # pod 'RNApi/Sweeper'
end

Things to note

The UI BizBundle includes the open source React Native framework (v0.59.10).

  • If your iOS project does not integrate with React Native, follow the procedure in this topic to integrate with the UI BizBundle.

  • If your iOS project has integrated with React Native, perform the following steps to check whether the UI BizBundle can be integrated:

    • If React Native has been integrated and its version is later than v0.59.10, the UI BizBundle cannot be integrated due to version incompatibility.
    • If React Native has been integrated and its version is later than v0.51 and equal to or earlier than v0.59.10, the Tuya panels cannot be accessed as expected due to the repeated uses of the React Native library. Use either of the following methods to troubleshoot the problem:
      1. Remove React Native from your iOS project and use React Native v0.59.10 that the UI BizBundle depends on.
      2. Rename React Native that is integrated with your iOS project to avoid the repeated React Native library.

    If both methods failed, the UI BizBundle cannot be integrated.

Permissions

The BizBundle encapsulates a bunch of React Native API methods for panels. This requires specific declarations of privacy and permissions from Apple.

  • If a device panel supports album features such as the cloud album, add the following permission declaration to info.plist of your project:

    NSPhotoLibraryAddUsageDescription
    
  • If a device panel supports camera features such as the cloud album, add the following permission declaration to info.plist of your project:

    NSCameraUsageDescription
    
  • If a device panel supports location features, add the following permission declaration to info.plist of your project:

    NSLocationWhenInUseUsageDescription
    
  • If a device panel supports microphone features such as the music light panel, add the following permission declaration to info.plist of your project:

    NSMicrophoneUsageDescription
    
  • If a device panel supports Bluetooth features, add the following permission declaration to info.plist of your project:

    NSBluetoothAlwaysUsageDescription
    NSBluetoothPeripheralUsageDescription
    

Implement service protocols

Provide services

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

@protocol ThingPanelProtocol <NSObject>
NS_ASSUME_NONNULL_BEGIN

// Clears cached data of the panel.
- (void)cleanPanelCache;

/**
 * Returns the device panel controller.
 *
 * @param deviceModel  The device model.
 * @param initialProps  The custom initialization parameter to be set in initialProps of the RN application with the key 'extraInfo'.
 * @param contextProps  The context of the custom panel to be set in Panel Context with the key 'extraInfo'.
 * @param completionHandler The callback returns the view controller.
 */
- (void)getPanelViewControllerWithDeviceModel:(ThingSmartDeviceModel *)deviceModel
                                 initialProps:(nullable NSDictionary *)initialProps
                                 contextProps:(nullable NSDictionary *)contextProps
                            completionHandler:(void (^ _Nullable)(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error))completionHandler;

/**
 * Returns the group panel controller.
 *
 * @param groupModel The group model.
 * @param initialProps  The custom initialization parameter to be set in initialProps of the RN application with the key 'extraInfo'.
 * @param contextProps  The context of the custom panel to be set in Panel Context with the key 'extraInfo'.
 * @param completionHandler The callback returns the view controller.
 */
- (void)getPanelViewControllerWithGroupModel:(ThingSmartGroupModel *)groupModel
                                initialProps:(nullable NSDictionary *)initialProps
                                contextProps:(nullable NSDictionary *)contextProps
                           completionHandler:(void (^ _Nullable)(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error))completionHandler;

// The RN version number.
 - (NSString *_Nonnull)rnVersionForApp;

NS_ASSUME_NONNULL_END
@end

Depend on services

The UI BizBundle is used to load device panels and provide varied features depending on different devices. To ensure the normal use of these features, the UI BizBundle depends on the following protocols: ThingLampProjectDataProtocol, ThingDeviceDetailProtocol, ThingSettingsProtocol, ThingOTAGeneralProtocol, ThingGroupHandleProtocol, ThingRNCameraProtocol, and ThingCameraProtocol.

ThingLampProjectDataProtocol

Provides current project information required by the BizBundle. This protocol must be implemented.

/**
 Clears the current project and its cached data.
 */
- (void)clearCurrentProject;

/**
 To use this API method to get the current project data, you must use 'updateCurrentProjectId:' API of the protocol when the current project ID is updated.
 Returns the current project data. If no project is created, nil is returned.
 
 @return ThingSmartProject
  */
- (ThingLightingProject *)getCurrentProject;

/**
 Updates the current project ID and writes it to the cached data of GroupUserDefault.
 @param projectId The project ID.
 */
- (void)updateCurrentProjectId:(long long)projectId;

/// Returns the current project ID.
- (long long)currentProjectId;

ThingDeviceDetailProtocol

Implements the activity of tapping and navigation in the top right corner of the device panel.

/**
 Tap the button in the top right corner of the device panel to navigate to the device details page.

@param device The device.
  @param group The group if any. It is optional.
 */
- (void)gotoDeviceDetailDetailViewControllerWithDevice:(ThingSmartDeviceModel *)device group:(ThingSmartGroupModel *)group;

ThingSettingsProtocol

Provides the optional switch to enable a certain sound effect on the app when device control DPs are sent. The following API method is implemented to return whether the sound effect is enabled:

/**
 * Indicates whether the sound effect is enabled.
 */
- (BOOL)soundEnabled;

ThingOTAGeneralProtocol

Enters the device panel and checks for device firmware updates. The following API method is implemented to check for device firmware updates:

/**
 Checks for device firmware updates, and if any, shows the update prompt.

 @param deviceModel The device that checks for firmware updates.
 @param isManual Specifies whether to enable manual checks for firmware updates.
  @param theme The theme color.
 YES: Manually check for updates. A loading dialog box appears during the check. If a new update is found (check for updates, forced updates, and update notifications), OTA VC is displayed.
 NO: Automatically check for updates. A loading dialog box does not appear during the check. When forced updates and update notifications are enabled, the firmware update prompt appears. Click OK to show OTA VC.  */
- (void)checkFirmwareUpgrade:(ThingSmartDeviceModel *)deviceModel isManual:(BOOL)isManual theme:(ThingOTAControllerTheme)theme;

ThingGroupHandleProtocol

Implements the activity of navigation to a mesh group page on the panel for a Bluetooth mesh device. The following API method is implemented:

/**
Navigates to a local mesh group.

@available 1.0.0
 @param params
@param success
@param failure
*/
- (void)impl_jumpToMeshLocalGroup:(NSDictionary*)params success:(RCTResponseSenderBlock)success failure:(RCTResponseErrorBlock)failure ;

Usage guide

  • Before the call of any API method, make sure that the user has logged in to the app.
  • Before the UI BizBundle is used, the getCurrentProject and currentProjectId methods provided by the protocol ThingLampProjectDataProtocol must be implemented first.

Example for Objective-C

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

- (void)initCurrentProject {
     // Registers the protocols to be implemented.
    [[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingLampProjectDataProtocol) withInstance:self];
}

// Implements the protocol method.
 - (ThingLightingProject *)getCurrentProject {
    ThingLightingProject *project = [ThingLightingProject projectWithProjectId:@"Current project ID"];
    return project;
}

- (long long)currentProjectId {
         return 111;
}

Example for Swift

import ThingCommercialLightingKit

class ThingActivatorTest: NSObject,ThingLampProjectDataProtocol{

    func test() {
         ThingSmartBizCore.sharedInstance().registerService(ThingLampProjectDataProtocol.self, withInstance: self)
    }
    func getCurrentProject() -> ThingLightingProject! {         let project = ThingLightingProject.init(projectId: 111)
        return project
    }
    func currentProjectId() -> CLongLong {
            return 111
    }

}

Clear cached data of the panel

Example for Objective-C

id<ThingPanelProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingPanelProtocol)];
[impl cleanPanelCache];

Example for Swift

let impl = ThingSmartBizCore.sharedInstance().service(of: ThingPanelProtocol.self) as?ThingPanelProtocol impl?.cleanPanelCache()

Open a device panel

Example for Objective-C

id<ThingPanelProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingPanelProtocol)];
// Returns the panel view controller and enables automatic navigation.
if (deviceModel) {
    [impl getPanelViewControllerWithDeviceModel:deviceModel initialProps:nil contextProps:nil completionHandler:^(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error) {
    }];
} else if (groupModel) {
    [impl getPanelViewControllerWithGroupModel:groupModel initialProps:nil contextProps:nil completionHandler:^(__kindof UIViewController * _Nullable panelViewController, NSError * _Nullable error) {
    }];
}

Example for Swift

let impl = ThingSmartBizCore.sharedInstance().service(of: ThingPanelProtocol.self) as?ThingPanelProtocol
// Returns the panel view controller and enables automatic navigation.
impl?.getPanelViewController(with: deviceModel, initialProps: nil, contextProps: nil, completionHandler: { (vc, err) in

})
 impl?.getPanelViewController(with: groupModel, initialProps: nil, contextProps: nil, completionHandler: { (vc, err) in

})