Browse Source

Added sendNumber mutation

master
Anthony Hinsinger 6 years ago
parent
commit
cdeacec160
  1. 48
      index.js

48
index.js

@ -126,6 +126,24 @@ const typeDefs = gql`
connected: Boolean 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 { input SwitchValueInput {
name: String! name: String!
value: Boolean! value: Boolean!
@ -155,7 +173,9 @@ const typeDefs = gql`
connect: Boolean connect: Boolean
disconnect: Boolean disconnect: Boolean
connectDevice(id: String!): Device 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 }) { connectDevice(_, { id }) {
return indi.connectDevice(id).then(() => indi.getDevice(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 } }) { sendSwitch(_, { input: { device, property, values } }) {
const dev = indi.getDevice(device); const dev = indi.getDevice(device);
const props = dev.getProperty(property); const props = dev.getProperty(property);

Loading…
Cancel
Save