Skip to content

Commit

Permalink
added subscriptions for service and device updates (mqtt updates on l…
Browse files Browse the repository at this point in the history
…og) others update on connect & disconnect
  • Loading branch information
joyja committed Mar 23, 2020
1 parent b1cf2e6 commit 51139a3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/device/ethernetip.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ class EthernetIP extends Model {
} else {
this.connected = false
}
this.pubsub.publish('deviceUpdate', {
deviceUpdate: this.device
})
}
}
async disconnect() {
this.client.destroy()
this.connected = false
this.pubsub.publish('deviceUpdate', {
deviceUpdate: this.device
})
}
get host() {
this.checkInit()
Expand Down
6 changes: 6 additions & 0 deletions src/device/modbus.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class Modbus extends Model {
`Connection failed to modbus device ${this.device.name}, host: ${this.host}, port: ${this.port}, with error: ${this.error}.`
)
}
this.pubsub.publish('deviceUpdate', {
deviceUpdate: this.device
})
}
}
async disconnect() {
Expand All @@ -100,6 +103,9 @@ class Modbus extends Model {
}
})
this.connected = false
this.pubsub.publish('deviceUpdate', {
deviceUpdate: this.device
})
}
get host() {
this.checkInit()
Expand Down
4 changes: 3 additions & 1 deletion src/relations.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ MqttSource.prototype.log = async function(scanClassId) {
sql = `${sql} VALUES (?,?);`
params = [host.id, result.lastID]
await this.constructor.executeUpdate(sql, params)
this.pubsub.publish('mqttUpdate', { mqttUpdate: this.mqtt.service })
this.pubsub.publish('serviceUpdate', {
serviceUpdate: this.mqtt.service
})
}
resolve()
})
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/Subscription/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const tag = require('./tag')
const mqttUpdate = require('./mqttUpdate')
const service = require('./service')

module.exports = {
...mqttUpdate,
...service,
...tag
}
3 changes: 2 additions & 1 deletion src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,6 @@ type Mutation {

type Subscription {
tagUpdate: Tag,
mqttUpdate: Service
deviceUpdate: Device,
serviceUpdate: Service
}

0 comments on commit 51139a3

Please sign in to comment.