Skip to content

Commit

Permalink
fix: Added type for LightArgs.levelConfig (#8724)
Browse files Browse the repository at this point in the history
  • Loading branch information
mccordscvs authored Feb 4, 2025
1 parent ad60fd4 commit 8dc7622
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/lib/exposes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'assert';

import {Access, Range} from './types';
import {Access, LevelConfigFeatures, Range} from './types';
import {getLabelFromName} from './utils';

export type Feature = Numeric | Binary | Enum | Composite | List | Text;
Expand Down Expand Up @@ -376,7 +376,7 @@ export class Light extends Base {
return this;
}

withLevelConfig(disableFeatures: string[] = []) {
withLevelConfig(disableFeatures: LevelConfigFeatures = []) {
let levelConfig = new Composite('level_config', 'level_config', access.ALL);
if (!disableFeatures.includes('on_off_transition_time')) {
levelConfig = levelConfig.withFeature(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ikea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {access, options, presets} from '../lib/exposes';
import * as m from '../lib/modernExtend';
import * as reporting from '../lib/reporting';
import * as globalStore from '../lib/store';
import {Configure, Expose, Fz, KeyValue, KeyValueAny, ModernExtend, OnEvent, Range, Tz} from '../lib/types';
import {Configure, Expose, Fz, KeyValue, KeyValueAny, LevelConfigFeatures, ModernExtend, OnEvent, Range, Tz} from '../lib/types';
import {
assertString,
configureSetPowerSourceWhenUnknown,
Expand Down Expand Up @@ -80,7 +80,7 @@ const bulbOnEvent: OnEvent = async (type, data, device, options, state: KeyValue

export function ikeaLight(args?: Omit<m.LightArgs, 'colorTemp'> & {colorTemp?: true | {range: Range; viaColor: true}}) {
const colorTemp: {range: Range} = args?.colorTemp ? (args.colorTemp === true ? {range: [250, 454]} : args.colorTemp) : undefined;
const levelConfig: {disabledFeatures?: string[]} = args?.levelConfig
const levelConfig: {disabledFeatures?: LevelConfigFeatures} = args?.levelConfig
? args.levelConfig
: {disabledFeatures: ['on_off_transition_time', 'on_transition_time', 'off_transition_time', 'on_level']};
const result = m.light({...args, colorTemp, levelConfig});
Expand Down
3 changes: 2 additions & 1 deletion src/lib/modernExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
KeyValue,
KeyValueAny,
KeyValueString,
LevelConfigFeatures,
ModernExtend,
OnEvent,
Range,
Expand Down Expand Up @@ -981,7 +982,7 @@ export interface LightArgs {
configureReporting?: boolean;
endpointNames?: string[];
ota?: ModernExtend['ota'];
levelConfig?: {disabledFeatures?: string[]};
levelConfig?: {disabledFeatures?: LevelConfigFeatures};
}
export function light(args?: LightArgs): ModernExtend {
args = {effect: true, powerOnBehavior: true, configureReporting: false, ...args};
Expand Down
10 changes: 10 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,20 @@ export namespace Ota {
suppressElementImageParseFailure?: boolean;
};
}

export namespace Reporting {
export interface Override {
min?: number;
max?: number;
change?: number;
}
}

export type LevelConfigFeatures = (
| 'on_off_transition_time'
| 'on_transition_time'
| 'off_transition_time'
| 'execute_if_off'
| 'on_level'
| 'current_level_startup'
)[];

0 comments on commit 8dc7622

Please sign in to comment.