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.
The Lighting Scenario UI BizBundle supports the following features:
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
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
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;
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:
currentFamilyId
of ThingFamilyProtocol
.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;
}
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingLightSceneProtocol.h>
- (void)addLightScene {
id<ThingLightSceneProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingLightSceneProtocol)];
[impl createNewLightScene];
}
#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];
}
#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) {
}];
}
#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) {
}];
}
kNotificationLightSceneListUpdate
supports notifications of the following events:
/// Notifies to refresh the list when any lighting scenario changes are detected.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadSceneList) name:@"kNotificationLightSceneListUpdate" object:nil];
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback