Skip to content

Commit

Permalink
streamdeck-homeassistant-117 Added rotationPercent and rotationAbsolu…
Browse files Browse the repository at this point in the history
…te to available variables.
  • Loading branch information
cgiesche committed Nov 5, 2023
1 parent dd1dbe4 commit 7d875f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/components/PiComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@
<summary>Available variables</summary>
<div class="form-text">
<span v-pre class="text-info font-monospace">{{ ticks }}</span> - The number of ticks the dial was
rotated
rotated (negative value for left turn, positive value for right turn).
</div>
<div class="form-text">
<span v-pre class="text-info font-monospace">{{ rotationPercent }}</span> - A number between 0 and 100
that represents the rotation percentage value of the dial.
</div>
<div class="form-text">
<span v-pre class="text-info font-monospace">{{ rotationAbsolute }}</span> - A number between 0 and 255
that represents the absolute rotation value of the dial.
</div>
</details>
</AccordeonItem>
Expand Down
10 changes: 9 additions & 1 deletion src/components/PluginComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const buttonLongpressTimeouts = ref(new Map()) //context, timeout
let rotationTimeout = [];
let rotationAmount = [];
let rotationPercent = [];
onMounted(() => {
window.connectElgatoStreamDeckSocket = (inPort, inPluginUUID, inRegisterEvent, inInfo) => {
Expand Down Expand Up @@ -74,6 +75,7 @@ onMounted(() => {
$SD.value.on("willAppear", (message) => {
let context = message.context;
rotationAmount[context] = 0;
rotationPercent[context] = 0;
actionSettings.value[context] = Settings.parse(message.payload.settings)
if ($HA.value) {
$HA.value.getStates(entitiyStatesChanged)
Expand All @@ -90,12 +92,18 @@ onMounted(() => {
let settings = actionSettings.value[context];
rotationAmount[context] += message.payload.ticks;
rotationPercent[context] += (message.payload.ticks * 2);
if (rotationPercent[context] < 0) {
rotationPercent[context] = 0;
} else if (rotationPercent[context] > 100) {
rotationPercent[context] = 100;
}
if (rotationTimeout[context])
return;
rotationTimeout[context] = setTimeout(() => {
callService(context, settings.button.serviceRotation, {ticks: rotationAmount[context]});
callService(context, settings.button.serviceRotation, {ticks: rotationAmount[context], rotationPercent: rotationPercent[context], rotationAbsolute: 2.55 * rotationPercent[context]});
rotationAmount[context] = 0;
rotationTimeout[context] = null;
}, 300);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ServiceCallConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const serviceDataInvalidFeedback = computed(() => {
return "";
}
try {
const renderedServiceData = nunjucks.renderString(serviceDataString, {ticks: 5});
const renderedServiceData = nunjucks.renderString(serviceDataString, {ticks: 5, rotationPercent: 100, rotationAbsolute: 100});
const json = JSON.parse(renderedServiceData);
return (typeof json === "object") ? "" : "Service data must be an JSON object."
Expand Down

0 comments on commit 7d875f4

Please sign in to comment.