diff --git a/config.schema.json b/config.schema.json index 3ccd45b..72ddf14 100644 --- a/config.schema.json +++ b/config.schema.json @@ -43,12 +43,19 @@ "required": true, "default": 10, "minimum": 0, - "maximum": 30 + "maximum": 60 }, "resetAfterSwitchOff": { - "title": "Reset when switch turned `Off`", + "title": "Reset when switch is turned `Off`", "type": "boolean", - "description": "Reset the switch and trigger index, when the trigger switch is turned Off (independent from timeout)", + "description": "Reset the switch and trigger index, when the stateless switch is turned Off", + "required": true, + "default": false + }, + "triggerSceneAfterSwitchOff": { + "title": "Trigger scene, when switch is turned `Off`", + "type": "boolean", + "description": "Trigger scene 0 (so called Off-scene), when the stateless switch is turned Off (independent from timeout).
Note: If this is enabled, rotation starts from switch 1, otherwise 0.", "required": true, "default": false }, @@ -57,6 +64,15 @@ "type": "boolean", "required": true, "default": false + }, + "debounceTimerMs": { + "title": "Debounce Timer (in milliseconds)", + "type": "number", + "description": "Time to wait before the next switch trigger is accepted.
Only change this value, if you encounter problems using the HomeKit slider in the Home App", + "required": true, + "minimum": 10, + "maximum": 1000, + "default": 150 } } } diff --git a/src/config.ts b/src/config.ts index 8c05619..a55c534 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,14 +3,19 @@ import { PlatformConfig } from 'homebridge'; const DEFAULT_NUM_OF_CONFIGURED_SCENES = 5; const DEFAULT_TRIGGER_TIMEOUT = 10; const DEFAULT_RESET_AFTER_SWITCH_OFF = false; +const DEFAULT_TRIGGER_SCENE_AFTER_SWITCH_OFF = false; +const DEFAULT_TRIGGER_SCENE_OFF = 0; const DEFAULT_LOGGING = false; +const DEFAULT_DEBOUNCE_TIMEOUT_MS = 150; export interface PluginDeviceConfig { readonly name: string; readonly numberConfiguredScenes?: number; readonly triggerTimeout?: number; readonly resetAfterSwitchOff?: boolean; + readonly triggerSceneAfterSwitchOff?: boolean; readonly logging?: boolean; + readonly debounceTimerMs?: number; } export class PluginConfig { @@ -50,10 +55,29 @@ export class DeviceConfig { || DEFAULT_RESET_AFTER_SWITCH_OFF; } + isTriggerSceneWhenOff(): boolean { + return this.device.triggerSceneAfterSwitchOff + || DEFAULT_TRIGGER_SCENE_AFTER_SWITCH_OFF; + } + + // When triggerSceneAfterSwitchOff is 'true', start at 1, otherwise 0 (normal behavior) + FirstTriggerScene(): number { + return this.isTriggerSceneWhenOff() ? 1 : 0; + } + + TriggerOffSceneIndex(): number { + return DEFAULT_TRIGGER_SCENE_OFF; + } + isLogging(): boolean { return this.device.logging || DEFAULT_LOGGING; } + + DebounceTimeoutMs(): number { + return this.device.debounceTimerMs + || DEFAULT_DEBOUNCE_TIMEOUT_MS; + } } export interface AccessoryState { diff --git a/test/hbConfig/config.json b/test/hbConfig/config.json index 347b0c8..3578622 100644 --- a/test/hbConfig/config.json +++ b/test/hbConfig/config.json @@ -34,6 +34,7 @@ "numberConfiguredScenes": 5, "triggerTimeout": 10, "resetAfterSwitchOff": false, + "triggerSceneAfterSwitchOff": true, "logging": true } ]