Skip to content

Commit

Permalink
Merge pull request #183 from cgiesche/streamdeck-homeassistant-117
Browse files Browse the repository at this point in the history
streamdeck-homeassistant-117 Added configuration for tickMultiplier a…
  • Loading branch information
cgiesche authored Nov 7, 2023
2 parents 2ae26ac + bec911c commit 930eb5c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
30 changes: 29 additions & 1 deletion src/components/PiComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<ServiceCallConfiguration v-model="serviceRotation"
:available-entities="availableEntities"
:available-services="availableServices"></ServiceCallConfiguration>

<details class="mb-2">
<summary>Available variables</summary>
<div class="form-text">
Expand All @@ -159,6 +160,25 @@
that represents the absolute rotation value of the dial.
</div>
</details>

<label class="form-label" for="rotationTickMultiplier">Dial rotation tick multiplier
(x{{ rotationTickMultiplier }})</label>
<input id="rotationTickMultiplier" v-model="rotationTickMultiplier" class="form-range" max="10"
min="0.1" step="0.1" type="range">
<div class="form-text mb-2">
Each tick of the dial will be multiplied with this value. This results in faster or slower value changes.
</div>

<label class="form-label" for="rotationTickBucketSizeMs">Dial rotation tick bucket size
({{ rotationTickBucketSizeMs }} ms)</label>
<input id="rotationTickBucketSizeMs" v-model="rotationTickBucketSizeMs" class="form-range" max="1000"
min="0" step="50" type="range">
<div class="form-text mb-2">
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.
</div>

</AccordeonItem>
</template>

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
})
}
})
Expand Down Expand Up @@ -367,7 +392,10 @@ function saveSettings() {
serviceLongPress: serviceLongPress.value,
serviceTap: serviceTap.value,
serviceRotation: serviceRotation.value
}
},
rotationTickMultiplier: rotationTickMultiplier.value,
rotationTickBucketSizeMs: rotationTickBucketSizeMs.value
}
Expand Down
22 changes: 17 additions & 5 deletions src/components/PluginComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/modules/common/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export class Settings {
serviceData: "",
}
settingsV4.controllerType = "Keypad"
settingsV4.rotationTickMultiplier = 1
settingsV4.rotationTickBucketSizeMs = 300

return this.parse(settingsV4)
}
Expand Down

0 comments on commit 930eb5c

Please sign in to comment.