mirror of
https://github.com/zyphlar/doorlock.git
synced 2024-04-03 21:36:03 +00:00
Start fleshing out card update code.
- Use node config, - Add logger
This commit is contained in:
parent
260685e25d
commit
a076724f83
|
@ -1,6 +0,0 @@
|
||||||
const ENV = process.env.NODE_ENV || 'development'
|
|
||||||
const DOOR_OPEN_DELAY = ENV === 'test' ? 1 : 6000 // in milliseconds
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
DOOR_OPEN_DELAY,
|
|
||||||
}
|
|
3
config/custom-environment-variables.js
Normal file
3
config/custom-environment-variables.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
env: 'ENV',
|
||||||
|
}
|
5
config/default.js
Normal file
5
config/default.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module.exports = {
|
||||||
|
cardApi: 'https://chimera.cobot.me/api/check_in_tokens',
|
||||||
|
env: 'development',
|
||||||
|
openDelay: 6000,
|
||||||
|
}
|
4
config/test.js
Normal file
4
config/test.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = {
|
||||||
|
env: 'test',
|
||||||
|
openDelay: 1,
|
||||||
|
}
|
403
package-lock.json
generated
403
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -5,11 +5,12 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "t2 run src/boot.js",
|
"start": "t2 run src/boot.js",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"watch-test": "jest --watch"
|
"watch-test": "npm test -- --watch"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "0.17.1",
|
"axios": "0.17.1",
|
||||||
"chalk": "2.3.1",
|
"chalk": "2.3.1",
|
||||||
|
"config": "1.30.0",
|
||||||
"consolidate": "0.15.0",
|
"consolidate": "0.15.0",
|
||||||
"eslint": "4.17.0",
|
"eslint": "4.17.0",
|
||||||
"express": "4.16.2",
|
"express": "4.16.2",
|
||||||
|
@ -22,5 +23,8 @@
|
||||||
"babel-eslint": "8.2.2",
|
"babel-eslint": "8.2.2",
|
||||||
"eslint-plugin-react": "7.7.0",
|
"eslint-plugin-react": "7.7.0",
|
||||||
"jest": "22.4.2"
|
"jest": "22.4.2"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fsevents": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# Chimera Doorlock
|
# Chimera Doorlock
|
||||||
|
|
||||||
|
> A Tessel powered RFID doorlock for the space, interfacing with Cobot
|
||||||
|
|
||||||
Powered by a [Tessel][tessel]
|
Powered by a [Tessel][tessel]
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
10
src/models/cards.js
Normal file
10
src/models/cards.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const axios = require('axios')
|
||||||
|
const config = require('config')
|
||||||
|
|
||||||
|
class Cards {
|
||||||
|
static update() {
|
||||||
|
return axios.get(config.get('cardApi'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Cards
|
9
src/models/cards.test.js
Normal file
9
src/models/cards.test.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
const Cards = require('./cards')
|
||||||
|
|
||||||
|
describe('models/cards', () => {
|
||||||
|
describe('.update', () => {
|
||||||
|
test('should fetch list of RFID cards', () => {
|
||||||
|
return Cards.update().then(cards => expect(cards).toEqual())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -1,5 +1,9 @@
|
||||||
|
const config = require('config')
|
||||||
|
const logger = require('../utils/logger')
|
||||||
const tessel = require('tessel')
|
const tessel = require('tessel')
|
||||||
const constants = require('../../config/constants')
|
|
||||||
|
const DOOR_OPEN_DELAY = config.get('openDelay')
|
||||||
|
|
||||||
// const fs = require('fs')
|
// const fs = require('fs')
|
||||||
// const path = require('path')
|
// const path = require('path')
|
||||||
|
|
||||||
|
@ -8,21 +12,23 @@ const constants = require('../../config/constants')
|
||||||
|
|
||||||
class Door {
|
class Door {
|
||||||
static open() {
|
static open() {
|
||||||
|
logger.log('OPEN DOOR')
|
||||||
|
|
||||||
// TODO: trigger door opening...
|
// TODO: trigger door opening...
|
||||||
tessel.led[2].on()
|
tessel.led[3].on()
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// TODO: trigger door closing
|
// TODO: trigger door closing
|
||||||
Door.close()
|
Door.close()
|
||||||
resolve()
|
resolve()
|
||||||
}, constants.DOOR_OPEN_DELAY)
|
}, DOOR_OPEN_DELAY)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static close() {
|
static close() {
|
||||||
console.log('CLOSE DOOR')
|
logger.log('CLOSE DOOR')
|
||||||
tessel.led[2].off()
|
tessel.led[3].off()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,8 @@ describe('models/door', () => {
|
||||||
describe('.open', () => {
|
describe('.open', () => {
|
||||||
test('opens door', () => {
|
test('opens door', () => {
|
||||||
jest.spyOn(Door, 'close')
|
jest.spyOn(Door, 'close')
|
||||||
// Door.close = jest.fn()
|
|
||||||
return Door.open().then(() => {
|
return Door.open().then(() => {
|
||||||
expect(tessel.led[2].on).toBeCalled()
|
expect(tessel.led[3].on).toBeCalled()
|
||||||
expect(Door.close).toBeCalled()
|
expect(Door.close).toBeCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -18,7 +17,7 @@ describe('models/door', () => {
|
||||||
describe('.close', () => {
|
describe('.close', () => {
|
||||||
test('closes door', () => {
|
test('closes door', () => {
|
||||||
Door.close()
|
Door.close()
|
||||||
expect(tessel.led[2].off).toBeCalled()
|
expect(tessel.led[3].off).toBeCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
10
src/utils/logger.js
Normal file
10
src/utils/logger.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
const config = require('config')
|
||||||
|
const ENV = config.get('env')
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
log() {
|
||||||
|
ENV !== 'test' && console.log(...arguments)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new Logger()
|
Loading…
Reference in New Issue
Block a user