From 5cce4088395350f61300337b4a874a34437d39f0 Mon Sep 17 00:00:00 2001 From: Dennis Twardowsky Date: Fri, 24 Feb 2023 22:04:42 +0100 Subject: [PATCH] Trigger Timeout handling updated --- README.md | 4 +++- src/config.ts | 2 ++ src/platformAccessory.ts | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11c4d89..5d93d10 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,9 @@ The configuration allows the user to add multiple **Multi-Tap-Switches**. The fo | `devices[].resetAfterSwitchOff` | false | | Reset the switch (like after timeout), when it is turned ```OFF```. | | `devices[].logging` | false | | Logging of switch/trigger actions. | -The parameter ```triggerTimeout``` can be changed in the configuration during runtime. So, this is just the initial value. +The parameter ```triggerTimeout``` can be changed in the configuration during runtime. So, this is just the initial value.
+> **NOTE:** If the value is out of sync from the configured value (i.e. updated via Home-App), it will not be updated on later configuration changes. +> It must be set back to the configured value first! The parameter ```numberConfiguredScenes``` just defines how many **programmable** switches are available. The number of really **used** switches can configured during runtime, between 0 and the configured number. diff --git a/src/config.ts b/src/config.ts index ca24f7a..35445a5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -60,6 +60,7 @@ export interface AccessoryState { numberConfiguredScenes: number; triggerTimeout: number; //nextSceneToTrigger: number; + triggerTimeoutManuallyChanged: boolean; } export function initializeAccessoryState(initConfig: PluginDeviceConfig | AccessoryState): AccessoryState { @@ -67,5 +68,6 @@ export function initializeAccessoryState(initConfig: PluginDeviceConfig | Access numberConfiguredScenes: initConfig.numberConfiguredScenes || DEFAULT_NUM_OF_CONFIGURED_SCENES, triggerTimeout: initConfig.triggerTimeout || DEFAULT_TRIGGER_TIMEOUT, //nextSceneToTrigger: 0, + triggerTimeoutManuallyChanged: false, }; } diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index 2f979a8..341a4bb 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -81,6 +81,12 @@ export class DeviceAccessory { .updateValue(this.State.numberConfiguredScenes); // Register handlers for the TriggerTimeout characteristic & restore previous value + if (!this.State.triggerTimeoutManuallyChanged) { + this.State.triggerTimeout = this.Config.TriggerTimeout(); + } else { + this.Log.debug('Current Trigger Timeout [' + this.State.triggerTimeout + '] differs from configured value [' + + this.Config.TriggerTimeout() + ']. It won\'t be updated until it\'s equal again.'); + } (this.serviceIn.getCharacteristic(this.platform.Characteristic.TriggerTimeout) || this.serviceIn.addOptionalCharacteristic(this.platform.Characteristic.TriggerTimeout)) .setProps({ @@ -251,6 +257,15 @@ export class DeviceAccessory { 'Set Trigger Timeout ->', triggerTimeout, '-> Out-of-Range / Value must be greater or equal to 0'); triggerTimeout = 0; } + + this.State.triggerTimeoutManuallyChanged = (this.Config.TriggerTimeout() !== triggerTimeout); + if (!this.State.triggerTimeoutManuallyChanged) { + this.Log.debug('Trigger Timeout in sync with config.'); + } else { + this.Log.warn('Trigger Timeout not in sync with config value [' + this.Config.TriggerTimeout() + '].'); + this.Log.warn('It will not be updated by config changes, until it is in sync again!'); + } + this.State.triggerTimeout = triggerTimeout; }