Added sendNumber mutation
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user