diff --git a/package.json b/package.json index 6d4ac8a..636ddbc 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/components/PluginComponent.vue b/src/components/PluginComponent.vue index 5a4621d..093d419 100644 --- a/src/components/PluginComponent.vue +++ b/src/components/PluginComponent.vue @@ -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() @@ -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, "{}"); @@ -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) { @@ -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') {