Skip to content

Commit 930eb5c

Browse files
authored
Merge pull request #183 from cgiesche/streamdeck-homeassistant-117
streamdeck-homeassistant-117 Added configuration for tickMultiplier a…
2 parents 2ae26ac + bec911c commit 930eb5c

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

src/components/PiComponent.vue

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<ServiceCallConfiguration v-model="serviceRotation"
145145
:available-entities="availableEntities"
146146
:available-services="availableServices"></ServiceCallConfiguration>
147+
147148
<details class="mb-2">
148149
<summary>Available variables</summary>
149150
<div class="form-text">
@@ -159,6 +160,25 @@
159160
that represents the absolute rotation value of the dial.
160161
</div>
161162
</details>
163+
164+
<label class="form-label" for="rotationTickMultiplier">Dial rotation tick multiplier
165+
(x{{ rotationTickMultiplier }})</label>
166+
<input id="rotationTickMultiplier" v-model="rotationTickMultiplier" class="form-range" max="10"
167+
min="0.1" step="0.1" type="range">
168+
<div class="form-text mb-2">
169+
Each tick of the dial will be multiplied with this value. This results in faster or slower value changes.
170+
</div>
171+
172+
<label class="form-label" for="rotationTickBucketSizeMs">Dial rotation tick bucket size
173+
({{ rotationTickBucketSizeMs }} ms)</label>
174+
<input id="rotationTickBucketSizeMs" v-model="rotationTickBucketSizeMs" class="form-range" max="1000"
175+
min="0" step="50" type="range">
176+
<div class="form-text mb-2">
177+
If greater than zero, ticks are aggregated for the given amount of milliseconds and then passed to your
178+
service call. This results in less service calls. A value of zero will result in a service call for each
179+
tick, which may cause trouble with home assistant.
180+
</div>
181+
162182
</AccordeonItem>
163183
</template>
164184

@@ -199,6 +219,9 @@ const serviceLongPress = ref({})
199219
const serviceTap = ref({})
200220
const serviceRotation = ref({})
201221
222+
const rotationTickMultiplier = ref(1)
223+
const rotationTickBucketSizeMs = ref(300)
224+
202225
const useCustomTitle = ref(false)
203226
const buttonTitle = ref("{{friendly_name}}")
204227
const useStateImagesForOnOffStates = ref(false) // determined by action ID (manifest)
@@ -255,6 +278,8 @@ onMounted(() => {
255278
serviceLongPress.value = settings["button"]["serviceLongPress"]
256279
serviceTap.value = settings["button"]["serviceTap"]
257280
serviceRotation.value = settings["button"]["serviceRotation"]
281+
rotationTickMultiplier.value = settings["rotationTickMultiplier"] || 1
282+
rotationTickBucketSizeMs.value = settings["rotationTickBucketSizeMs"] || 300
258283
})
259284
}
260285
})
@@ -367,7 +392,10 @@ function saveSettings() {
367392
serviceLongPress: serviceLongPress.value,
368393
serviceTap: serviceTap.value,
369394
serviceRotation: serviceRotation.value
370-
}
395+
},
396+
397+
rotationTickMultiplier: rotationTickMultiplier.value,
398+
rotationTickBucketSizeMs: rotationTickBucketSizeMs.value
371399
372400
}
373401

src/components/PluginComponent.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ onMounted(() => {
9090
$SD.value.on("dialRotate", (message) => {
9191
let context = message.context;
9292
let settings = actionSettings.value[context];
93+
let scaledTicks = message.payload.ticks * (settings.rotationTickMultiplier || 1);
94+
let tickBucketSizeMs = settings.rotationTickBucketSizeMs || 300;
9395
94-
rotationAmount[context] += message.payload.ticks;
95-
rotationPercent[context] += (message.payload.ticks * 2);
96+
rotationAmount[context] += scaledTicks;
97+
rotationPercent[context] += scaledTicks;
9698
if (rotationPercent[context] < 0) {
9799
rotationPercent[context] = 0;
98100
} else if (rotationPercent[context] > 100) {
@@ -102,11 +104,21 @@ onMounted(() => {
102104
if (rotationTimeout[context])
103105
return;
104106
105-
rotationTimeout[context] = setTimeout(() => {
106-
callService(context, settings.button.serviceRotation, {ticks: rotationAmount[context], rotationPercent: rotationPercent[context], rotationAbsolute: 2.55 * rotationPercent[context]});
107+
let serviceCall = () => {
108+
callService(context, settings.button.serviceRotation, {
109+
ticks: rotationAmount[context],
110+
rotationPercent: rotationPercent[context],
111+
rotationAbsolute: 2.55 * rotationPercent[context]
112+
});
107113
rotationAmount[context] = 0;
108114
rotationTimeout[context] = null;
109-
}, 300);
115+
};
116+
117+
if (tickBucketSizeMs > 0) {
118+
rotationTimeout[context] = setTimeout(serviceCall, tickBucketSizeMs);
119+
} else {
120+
serviceCall();
121+
}
110122
111123
})
112124

src/modules/common/settings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ export class Settings {
101101
serviceData: "",
102102
}
103103
settingsV4.controllerType = "Keypad"
104+
settingsV4.rotationTickMultiplier = 1
105+
settingsV4.rotationTickBucketSizeMs = 300
104106

105107
return this.parse(settingsV4)
106108
}

0 commit comments

Comments
 (0)