Lighting Scenario UI BizBundle

Last Updated on : 2024-07-16 06:28:45download

Lighting scenarios enable users to customize lighting colors for their homes with a color palette and a scene library.

Features

The Lighting Scenario UI BizBundle supports the following features:

  • Create a lighting scenario.
  • Edit a lighting scenario, including the icon, name, and all device scenes.
  • Preview the custom scene for a single device that supports the cool white light, cool and warm white light, colored light, cool white and colored light, and white and colored light.
  • Preview the mode, color, and flashing scenes for a single device.
  • Preview a lighting scenario.
  • Adjust brightness, color temperature, and hue on a single device.
  • Adjust the overall brightness and color temperature.

Fast integration

Add the components of the Lighting Scenario UI BizBundle to 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 'ThingSmartLightSceneBizBundle'
end

Service protocol

The Lighting Scenario UI BizBundle implements ThingLightSceneProtocol and ThingLightSceneBizProtocol to provide the required services.

  • The ThingLightSceneProtocol.h file includes:

    @class ThingLightSceneModel;
    
    @protocol ThingLightSceneProtocol <NSObject>
    
    /// Navigates to the page of "creating a lighting scenario".
    - (void)createNewLightScene;
    
    /// Navigates to the page of "editing a lighting scenario".
    - (void)editLightScene:(ThingLightSceneModel *)scene;
    @end
    
  • The ThingLightSceneBizProtocol.h file includes:

    @class ThingLightSceneModel;
    
    @protocol ThingLightSceneBizProtocol <NSObject>
    
    @optional
    
    /// Runs the lighting scenario.
    - (void)executeLightScene:(ThingLightSceneModel *)sceneModel
                    success:(void(^)(BOOL success))success
                    failure:(void(^)(NSError * _Nonnull error))failure;
    
    /// Returns a list of lighting scenarios.
    - (void)getLightSceneListWithSuccess:(void(^)(NSArray<ThingLightSceneModel *> * _Nonnull scenes))success
                                failure:(void(^)(NSError * _Nonnull error))failure;
    @end
    

Depend on services

To call the Lighting Scenario UI BizBundle, you must implement the following protocols:

  • Protocol 1: ThingFamilyProtocol

    Provides the current home ID required by the BizBundle.

    /// Returns the current home ID.
    - (long long)currentFamilyId;
    

    You can also integrate both the Home Management UI BizBundle and Scene UI BizBundle. For more information, see Home Management UI BizBundle.

  • Protocol 2 (deprecated): ThingSmartHomeDataProtocol

    Provides current home information required by the UI BizBundle.

    We recommend that you implement the method ThingFamilyProtocol to provide the current home ID.

    /**
    Returns the current home. If the current user does not have a home, nil is returned.
    
    
    @return ThingSmartHome
    */
    - (ThingSmartHome *)getCurrentHome;
    
  • Protocol 3: ThingSmartHouseIndexProtocol

    Provides the administrator information required by the UI BizBundle. If non-administrator users are allowed to edit scenes, YES is returned.

    /**
    * Indicates whether the user is the administrator of the current home.
    *
    * @return YES indicates an administrator.
    */
    - (BOOL)homeAdminValidation;
    

API protocols

Things to note

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

  • Before the Scenario UI BizBundle is used, you must implement:

    • The method currentFamilyId of ThingFamilyProtocol.
    • The method homeAdminValidation of ThingSmartHouseIndexProtocol.
    #import <ThingSmartBizCore/ThingSmartBizCore.h>
    #import <ThingModuleServices/ThingModuleServices.h>
    #import <ThingSmartDeviceKit/ThingSmartDeviceKit.h>
    
    - (void)registerProtocol {
        // Registers the protocol to be implemented.
        [[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingSmartHomeDataProtocol) withInstance:self];
        [[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingSmartHouseIndexProtocol) withInstance:self];
        [[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingFamilyProtocol) withInstance:self];
    }
    
    // Implements the protocol method.
    - (ThingSmartHome *)getCurrentHome {
        ThingSmartHome *home = [ThingSmartHome homeWithHomeId:@"Current home ID"];
        return home;
    }
    
    - (BOOL)homeAdminValidation {
        // Returns a specific user information, or returns YES to allow all users to edit scenes.
        return YES;
    }
    
    /// Returns the current home ID.
    - (long long)currentFamilyId {
        return [ThingDemoSmartHomeManager sharedInstance].currentHomeModel.homeId;
    }
    

Create a lighting scenario

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

- (void)addLightScene {
    id<ThingLightSceneProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingLightSceneProtocol)];
    [impl createNewLightScene];
}

Edit a lighting scenario

#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingLightSceneProtocol.h>
#import <ThingLightSceneKit/ThingLightSceneModel.h>

- (void)editLightScene:(ThingLightSceneModel *)scene {
    id<ThingLightSceneProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingLightSceneProtocol)];
    [impl editLightScene:scene];
}

Get a list of lighting scenarios

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

- (void)getLightSceneList {
    id<ThingLightSceneBizProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingLightSceneBizProtocol)];
    [impl getAllLightSceneListWithSuccess:^(NSArray<ThingLightSceneModel *> * _Nonnull scenes) {
      } failure:^(NSError * _Nonnull error) {
    }];
}

Run a lighting scenario

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

- (void)executeLightScene:(ThingLightSceneModel *)scene {
    ThingLightSceneModel *sceneModel = self.sceneList[indexPath.row];
    id<ThingLightSceneBizProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingLightSceneBizProtocol)];
    [impl executeLightScene:scene success:^(BOOL success) {
    } failure:^(NSError * _Nonnull error) {
    }];
}

Notification center

kNotificationLightSceneListUpdate supports notifications of the following events:

  • A lighting scenario is added.
  • A lighting scenario is edited.
  • A lighting scenario is deleted.
/// Notifies to refresh the list when any lighting scenario changes are detected.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadSceneList) name:@"kNotificationLightSceneListUpdate" object:nil];