diff --git a/index.js b/index.js index d0a7610..376fce8 100644 --- a/index.js +++ b/index.js @@ -126,6 +126,24 @@ const typeDefs = gql` connected: Boolean } + input NumberValueInput { + name: String! + value: Float! + } + + input NumberInput { + device: String! + property: String! + values: [NumberValueInput!]! + } + + input OneNumberInput { + device: String! + property: String! + name: String! + value: Float! + } + input SwitchValueInput { name: String! value: Boolean! @@ -155,7 +173,9 @@ const typeDefs = gql` connect: Boolean disconnect: Boolean connectDevice(id: String!): Device - sendSwitch(input: SwitchInput): Boolean + sendOneNumber(input: OneNumberInput!): Boolean + sendNumber(input: NumberInput!): Boolean + sendSwitch(input: SwitchInput!): Boolean } `; @@ -231,6 +251,32 @@ const resolvers = { connectDevice(_, { id }) { return indi.connectDevice(id).then(() => indi.getDevice(id)); }, + sendNumber(_, { input: { device, property, values } }) { + const dev = indi.getDevice(device); + const props = dev.getProperty(property); + + if (!props) { + return false; + } + + const vector = props.getValue(); + + for (let i = 0; i < vector.values.length; i++) { + vector.values[i].value = values[i].value; + } + + return indi + .sendNewNumber(vector) + .then(() => true) + .catch(() => false); + }, + sendOneNumber(_, { input: { device, property, name, value } }) { + console.log(value); + return indi + .sendNewNumber(device, property, name, value) + .then(() => true) + .catch(() => false); + }, sendSwitch(_, { input: { device, property, values } }) { const dev = indi.getDevice(device); const props = dev.getProperty(property);