From bec911cf2f5f7f5ab3ad934e8df2b84224813925 Mon Sep 17 00:00:00 2001 From: Christoph Giesche Date: Tue, 7 Nov 2023 15:08:51 +0100 Subject: [PATCH] streamdeck-homeassistant-117 Added configuration for tickMultiplier and tickBucketSize --- src/components/PiComponent.vue | 30 +++++++++++++++++++++++++++++- src/components/PluginComponent.vue | 22 +++++++++++++++++----- src/modules/common/settings.js | 2 ++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/components/PiComponent.vue b/src/components/PiComponent.vue index 34485c1..12d21d8 100644 --- a/src/components/PiComponent.vue +++ b/src/components/PiComponent.vue @@ -144,6 +144,7 @@ +
Available variables
@@ -159,6 +160,25 @@ that represents the absolute rotation value of the dial.
+ + + +
+ Each tick of the dial will be multiplied with this value. This results in faster or slower value changes. +
+ + + +
+ If greater than zero, ticks are aggregated for the given amount of milliseconds and then passed to your + service call. This results in less service calls. A value of zero will result in a service call for each + tick, which may cause trouble with home assistant. +
+ @@ -199,6 +219,9 @@ const serviceLongPress = ref({}) const serviceTap = ref({}) const serviceRotation = ref({}) +const rotationTickMultiplier = ref(1) +const rotationTickBucketSizeMs = ref(300) + const useCustomTitle = ref(false) const buttonTitle = ref("{{friendly_name}}") const useStateImagesForOnOffStates = ref(false) // determined by action ID (manifest) @@ -255,6 +278,8 @@ onMounted(() => { serviceLongPress.value = settings["button"]["serviceLongPress"] serviceTap.value = settings["button"]["serviceTap"] serviceRotation.value = settings["button"]["serviceRotation"] + rotationTickMultiplier.value = settings["rotationTickMultiplier"] || 1 + rotationTickBucketSizeMs.value = settings["rotationTickBucketSizeMs"] || 300 }) } }) @@ -367,7 +392,10 @@ function saveSettings() { serviceLongPress: serviceLongPress.value, serviceTap: serviceTap.value, serviceRotation: serviceRotation.value - } + }, + + rotationTickMultiplier: rotationTickMultiplier.value, + rotationTickBucketSizeMs: rotationTickBucketSizeMs.value } diff --git a/src/components/PluginComponent.vue b/src/components/PluginComponent.vue index e7ae11c..de502f6 100644 --- a/src/components/PluginComponent.vue +++ b/src/components/PluginComponent.vue @@ -90,9 +90,11 @@ onMounted(() => { $SD.value.on("dialRotate", (message) => { let context = message.context; let settings = actionSettings.value[context]; + let scaledTicks = message.payload.ticks * (settings.rotationTickMultiplier || 1); + let tickBucketSizeMs = settings.rotationTickBucketSizeMs || 300; - rotationAmount[context] += message.payload.ticks; - rotationPercent[context] += (message.payload.ticks * 2); + rotationAmount[context] += scaledTicks; + rotationPercent[context] += scaledTicks; if (rotationPercent[context] < 0) { rotationPercent[context] = 0; } else if (rotationPercent[context] > 100) { @@ -102,11 +104,21 @@ onMounted(() => { if (rotationTimeout[context]) return; - rotationTimeout[context] = setTimeout(() => { - callService(context, settings.button.serviceRotation, {ticks: rotationAmount[context], rotationPercent: rotationPercent[context], rotationAbsolute: 2.55 * rotationPercent[context]}); + let serviceCall = () => { + callService(context, settings.button.serviceRotation, { + ticks: rotationAmount[context], + rotationPercent: rotationPercent[context], + rotationAbsolute: 2.55 * rotationPercent[context] + }); rotationAmount[context] = 0; rotationTimeout[context] = null; - }, 300); + }; + + if (tickBucketSizeMs > 0) { + rotationTimeout[context] = setTimeout(serviceCall, tickBucketSizeMs); + } else { + serviceCall(); + } }) diff --git a/src/modules/common/settings.js b/src/modules/common/settings.js index b45ab4b..9902b67 100644 --- a/src/modules/common/settings.js +++ b/src/modules/common/settings.js @@ -101,6 +101,8 @@ export class Settings { serviceData: "", } settingsV4.controllerType = "Keypad" + settingsV4.rotationTickMultiplier = 1 + settingsV4.rotationTickBucketSizeMs = 300 return this.parse(settingsV4) }