Skip to content

Commit

Permalink
Disable Adaptive Lighting by default.
Browse files Browse the repository at this point in the history
0x5e committed May 4, 2023
1 parent 5fe7cc2 commit e455d70
Showing 3 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions ADVANCED_OPTIONS.md
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ Before configuring, you may need to:
- `id` - **required**: Device ID, Product ID, Scene ID, or `global`.
- `category` - **optional**: Device category code. See [SUPPORTED_DEVICES.md](./SUPPORTED_DEVICES.md). Also you can use `hidden` to hide the device, product, or scene. **⚠️Overriding this property may lead to unexpected behaviors and exceptions, so please remove the accessory cache after making changes.**
- `unbridged` - **optional**: Unbridge accessories. Defaults to `false`.
- `adaptiveLighting` - **optional**: Adaptive Lighting. Defaults to `false`. Not all light device support this feature, please use it on demand.
- `schema` - **optional**: An array of schema overriding config objects, used for describing datapoint (DP). When your device has non-standard DP, you need to transform them manually with configuration. Each element in the schema array is described as follows:
- `code` - **required**: DP code.
- `newCode` - **optional**: New DP code.
30 changes: 24 additions & 6 deletions src/accessory/characteristic/Light.ts
Original file line number Diff line number Diff line change
@@ -323,12 +323,30 @@ export function configureLight(
break;
}

// Adaptive Lighting
if (brightSchema && tempSchema) {
const { AdaptiveLightingController } = accessory.platform.api.hap;
const controller = new AdaptiveLightingController(service);
accessory.accessory.configureController(controller);
accessory.adaptiveLightingController = controller;
configureAdaptiveLighting(accessory, service, brightSchema, tempSchema);

}

function configureAdaptiveLighting(
accessory: BaseAccessory,
service: Service,
brightSchema?: TuyaDeviceSchema,
tempSchema?: TuyaDeviceSchema,
) {
const config = accessory.platform.getDeviceConfig(accessory.device);
if (!config || config.adaptiveLighting !== true) {
accessory.log.info('Adaptive Lighting disabled.');
return;
}
accessory.log.info('Adaptive Lighting enabled.');

if (!brightSchema || !tempSchema) {
accessory.log.warn('Adaptive Lighting not supported. Missing brightness or color temperature schema.');
return;
}

const { AdaptiveLightingController } = accessory.platform.api.hap;
const controller = new AdaptiveLightingController(service);
accessory.accessory.configureController(controller);
accessory.adaptiveLightingController = controller;
}
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -12,10 +12,11 @@ export interface TuyaPlatformDeviceSchemaConfig {
}

export interface TuyaPlatformDeviceConfig {
unbridged?: boolean;
id: string;
category?: string;
schema?: Array<TuyaPlatformDeviceSchemaConfig>;
unbridged?: boolean;
adaptiveLighting?: boolean;
}

export interface TuyaPlatformCustomConfigOptions {

0 comments on commit e455d70

Please sign in to comment.