-
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: moonraker power plugin support
- Loading branch information
Showing
15 changed files
with
222 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<template> | ||
<v-card-text class="d-flex flex-wrap align-center justify-start pt-5"> | ||
<v-btn | ||
v-for="(device, index) in devices" | ||
:key="index" | ||
@click="toggleDevice(device, `${waits.onGpio}${device.id}`)" | ||
:loading="hasWait(`${waits.onGpio}${device.id}`)" | ||
color="secondary" | ||
class="me-2 mb-2">Toggle {{ device.name }} {{ (device.state === 1) ? 'Off' : 'On' }}</v-btn> | ||
</v-card-text> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { Component, Mixins } from 'vue-property-decorator' | ||
import UtilsMixin from '@/mixins/utils' | ||
import { Waits } from '@/globals' | ||
import { SocketActions } from '@/socketActions' | ||
import { Device } from '@/store/gpio/types' | ||
@Component({}) | ||
export default class PowerControlWidget extends Mixins(UtilsMixin) { | ||
waits = Waits | ||
get devices () { | ||
return this.$store.state.gpio.devices | ||
} | ||
toggleDevice (device: Device, wait?: string) { | ||
const state = (device.state === 1) ? 0 : 1 | ||
if (wait) this.$store.dispatch('socket/addWait', wait) | ||
SocketActions.machineGpioPowerToggle(device.id, state, wait) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ActionTree } from 'vuex' | ||
import { GpioState } from './types' | ||
import { RootState } from '../types' | ||
import { SocketActions } from '@/socketActions' | ||
|
||
export const actions: ActionTree<GpioState, RootState> = { | ||
|
||
/** | ||
* Inits the list of available devices. | ||
*/ | ||
async init ({ commit }, payload) { | ||
if ( | ||
payload.devices && | ||
payload.devices.length > 0 | ||
) { | ||
commit('onDevices', payload) | ||
SocketActions.machineGpioPowerStatus() | ||
} | ||
}, | ||
|
||
/** | ||
* Loads the current status of each power device defined. | ||
*/ | ||
async onStatus ({ commit }, payload) { | ||
commit('onStatus', payload) | ||
}, | ||
|
||
/** | ||
* On a toggling a power device. | ||
*/ | ||
async onToggle ({ commit, dispatch }, payload) { | ||
dispatch('onStatus', payload) | ||
|
||
// Remove a wait if defined. | ||
if (payload.__request__ && payload.__request__.wait && payload.__request__.wait.length) { | ||
commit('socket/removeWait', payload.__request__.wait, { root: true }) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { GetterTree } from 'vuex' | ||
import { GpioState } from './types' | ||
import { RootState } from '../types' | ||
|
||
export const getters: GetterTree<GpioState, RootState> = { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable @typescript-eslint/camelcase */ | ||
|
||
import { Module } from 'vuex' | ||
import { getters } from './getters' | ||
import { actions } from './actions' | ||
import { mutations } from './mutations' | ||
import { GpioState } from './types' | ||
import { RootState } from '../types' | ||
|
||
export const state: GpioState = { | ||
devices: [] | ||
} | ||
|
||
const namespaced = true | ||
|
||
export const gpio: Module<GpioState, RootState> = { | ||
namespaced, | ||
state, | ||
getters, | ||
actions, | ||
mutations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Vue from 'vue' | ||
import { MutationTree } from 'vuex' | ||
import { GpioState } from './types' | ||
|
||
export const mutations: MutationTree<GpioState> = { | ||
onDevices (state, payload) { | ||
state.devices = payload.devices | ||
}, | ||
|
||
onStatus (state, payload) { | ||
for (const key in payload) { | ||
const i = state.devices.findIndex(device => device.id === key) | ||
if (i >= 0) { | ||
// Vue.set(state.devices, i, payload[key] === 'off' ? 0 : 1) | ||
Vue.set(state.devices[i], 'state', payload[key] === 'off' ? 0 : 1) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface GpioState { | ||
devices: Device[]; | ||
} | ||
|
||
export interface Device { | ||
id: string; | ||
name: string; | ||
state?: 1 | 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters