English
English
简体中文
Contact Us
Register
Log In

Lighting Scenario UI BizBundle

Last Updated on : 2023-03-12 16:48:13download

Lighting Scenario UI BizBundle supports the configurations of all smart lights in the same room. It provides abundant color picker styles and a bunch of scenario libraries. You can integrate the UI BizBundle to easily implement desired smart home lighting scenarios.

Feature overview

The Lighting Scenario UI BizBundle supports the following features:

  • Create a lighting scenario
  • Modify a lighting scenario, including the scenario icon, scenario name, and all device scenes.
  • Preview the custom scene of a single device that supports the cool white light (C), cool and warm white light (CW), colored light (RGB), cool white and colored light (RGBC), and white and colored light (RGBCW).
  • Preview the mode, color, and flashing scenes of a single device.
  • Preview a lighting scenario.
  • Adjust the brightness of a single device.
  • Adjust the brightness of all devices in a scenario.

Fast integration

Add the components of the Lighting Scenario 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 Lighting Scenario UI BizBundle.
  pod 'TuyaSmartLightSceneBizBundle'
end

Service protocol

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

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@protocol TYLightSceneProtocol <NSObject>

/// Adds a scenario.
- (void)createNewLightScene;

/// Modifies a scenario.
/// @param scene The lighting scenario model.
- (void)editLightScene:(TuyaLightSceneModel *)scene;

/// Runs the scenario.
- (void)executeLightScene;

/// Returns a list of lighting scenarios.
/// @param homeId The home ID.
/// @param success The success callback.
/// @param failure The failure callback.
- (void)getLightSceneListWithHomeId:(long long)homeId success:(void(^)(NSArray<TuyaLightSceneModel *> * _Nonnull scenes))success failure:(void(^)(NSError * _Nonnull error))failure;

@end

NS_ASSUME_NONNULL_END

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, the getCurrentHome method provided by the protocol TYSmartHomeDataProtocol must be implemented first.

    #import <TuyaSmartBizCore/TuyaSmartBizCore.h>
    #import <TYModuleServices/TYSmartHomeDataProtocol.h>
    
    - (void)initCurrentHome {
        // Registers the protocol to be implemented.
        [[TuyaSmartBizCore sharedInstance] registerService:@protocol(TYSmartHomeDataProtocol) withInstance:self];
    }
    
    // Implements the protocol method.
    - (TuyaSmartHome *)getCurrentHome {
        TuyaSmartHome *home = [TuyaSmartHome homeWithHomeId:@"Current home ID"];
        return home;
    }
    

Usage

Create a lighting scenario

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

- (void)createLightScene {
    id<TYLightSceneProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYLightSceneProtocol)];
    [impl createNewLightScene];
}

Modify a lighting scenario

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

- (void)editLightScene {
    TuyaLightSceneModel *sceneModel = self.sceneList[indexPath.row];
id<TYLightSceneProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYLightSceneProtocol)];
	[impl editLightScene:sceneModel];
}

Run a lighting scenario

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

- (void)executeLightScene {
    TuyaLightSceneModel *sceneModel = self.sceneList[indexPath.row];
id<TYLightSceneProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYLightSceneProtocol)];
	[impl executeLightScene:sceneModel success:^(BOOL success) {

	} failure:^(NSError * _Nonnull error) {

	}];
}

Query a list of lighting scenarios in a home

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

- (void)getLightSceneList {
	id<TYLightSceneProtocol> impl = [[TuyaSmartBizCore sharedInstance] serviceOfProtocol:@protocol(TYLightSceneProtocol)];
	[impl getLightSceneListWithHomeId:'your homeId' success:^(NSArray<TuyaLightSceneModel *> * _Nonnull scenes) {

	} failure:^(NSError * _Nonnull error) {

	}];
}