Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved active-states for image buttons. #249

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
"@mdi/font": "^7.1.96",
"@mdi/js": "^7.1.96",
"@popperjs/core": "^2.11.8",
"axios": "^1.6.7",
"bootstrap": "^5.3.2",
"core-js": "^3.26.1",
"nunjucks": "^3.2.3",
"nunjucks": "3.2.4",
"snapsvg-cjs": "^0.0.6",
"vue": "^3.3.4"
},
Expand Down
38 changes: 22 additions & 16 deletions src/components/PluginComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import nunjucks from "nunjucks"
import {Settings} from "@/modules/common/settings";
import {onMounted, ref} from "vue";
import {EntityConfigFactory} from "@/modules/plugin/entityConfigFactory";

import defaultActiveStates from '../../public/config/active-states.json'
import axios from "axios";

const entityConfigFactory = new EntityConfigFactory()
const buttonImageFactory = new EntityButtonImageFactory()
Expand All @@ -23,11 +24,14 @@ const globalSettings = ref({})
const actionSettings = ref([])
const buttonLongpressTimeouts = ref(new Map()) //context, timeout

const activeStates = ref(defaultActiveStates)

let rotationTimeout = [];
let rotationAmount = [];
let rotationPercent = [];

onMounted(() => {
onMounted(async () => {

window.connectElgatoStreamDeckSocket = (inPort, inPluginUUID, inRegisterEvent, inInfo) => {
$SD.value = new StreamDeck(inPort, inPluginUUID, inRegisterEvent, inInfo, "{}");

Expand Down Expand Up @@ -123,8 +127,18 @@ onMounted(() => {
}
})
}

await fetchActiveStates();
})

async function fetchActiveStates() {
try {
activeStates.value = (await axios.get('https://cdn.jsdelivr.net/gh/cgiesche/streamdeck-homeassistant@master/public/config/active-states.json')).data;
} catch (error) {
console.log(`Failed to download updated active-states.json: ${error}`)
}
}

function connectHomeAssistant() {
console.log("Connecting to Home Assistant")
if (globalSettings.value.serverUrl && globalSettings.value.accessToken) {
Expand Down Expand Up @@ -207,20 +221,12 @@ function updateContextState(currentContext, domain, stateObject) {
entityConfig.hideIcon = contextSettings.display.hideIcon

if (contextSettings.display.useStateImagesForOnOffStates) {
switch (stateObject.state) {
case "on":
case "playing":
case "open":
case "opening":
case "home":
case "locked":
case "active":
console.log("Setting state of " + currentContext + " to 1")
$SD.value.setState(currentContext, 1);
break;
default:
console.log("Setting state of " + currentContext + " to 0")
$SD.value.setState(currentContext, 0);
if (activeStates.value.indexOf(stateObject.state) !== -1) {
console.log("Setting state of " + currentContext + " to 1")
$SD.value.setState(currentContext, 1);
} else {
console.log("Setting state of " + currentContext + " to 0")
$SD.value.setState(currentContext, 0);
}
} else {
if (contextSettings.controllerType === 'Encoder') {
Expand Down
Loading