2018-04-05 15:35:29 -07:00
|
|
|
import Base from '../src/base'
|
|
|
|
|
|
|
|
// const USOCKET = __dirname + '/sample.sock'
|
|
|
|
|
2018-05-20 15:44:31 -07:00
|
|
|
let dy = new Base({id:'dynamic'})
|
|
|
|
|
|
|
|
dy.switch = {
|
|
|
|
on: function(packet){
|
|
|
|
return new Promise( async (resolve) => {
|
|
|
|
console.log(`turning switch on for id ${packet.id||packet.data}`)
|
|
|
|
// call switch on here
|
|
|
|
let res = {}
|
|
|
|
res.cmd='switch/status'
|
|
|
|
res.status='on'
|
|
|
|
res.id = packet.id
|
|
|
|
return resolve(res)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
off: function(packet){
|
|
|
|
return new Promise( async (resolve) => {
|
|
|
|
console.log(packet)
|
|
|
|
console.log(`turning switch off for id ${packet.id||packet.data}`)
|
|
|
|
// call switch on here
|
|
|
|
let res = {}
|
|
|
|
res.cmd='switch/status'
|
|
|
|
res.status='off'
|
|
|
|
res.id = packet.id
|
|
|
|
return resolve(res)
|
|
|
|
})
|
2018-04-05 15:35:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
(async () => {
|
|
|
|
|
2018-05-20 15:44:31 -07:00
|
|
|
await dy.init()
|
|
|
|
console.log('started', dy.started)
|
|
|
|
// await Promise.all([dy.addSocket('mqc','c','m'),dy.addSocket('mqs','s','m')])
|
|
|
|
await dy.addSocket('mqs','s','m')
|
|
|
|
dy.socket.mqs.subscribe(['switch/on','switch/off','switch/toggle'])
|
2018-04-05 15:35:29 -07:00
|
|
|
|
|
|
|
})().catch(err => {
|
|
|
|
console.error('FATAL: UNABLE TO START SYSTEM!\n',err)
|
|
|
|
process.kill(process.pid, 'SIGTERM')
|
|
|
|
})
|