Skip to content

Commit

Permalink
Merge pull request #249 from cgiesche/streamdeck-homeassistant-224
Browse files Browse the repository at this point in the history
Improved active-states for image buttons.
  • Loading branch information
cgiesche authored Feb 12, 2024
2 parents 28a5311 + 4b4de54 commit d651b44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
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

0 comments on commit d651b44

Please sign in to comment.