-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
68 lines (58 loc) · 1.46 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var test = require('tape')
var tessel = require('tessel')
var series = require('async-series')
var lib = require('./')
test('Climate si7020', function (t) {
t.plan(4)
var firstTemp, heatedTemp
var climate = lib.use(tessel.port['A'])
series([
function (cb) {
climate.on('ready', cb)
},
function (cb) {
climate.readHumidity(function (err, humid) {
if (err) return cb(err)
t.ok(humid >= 5 && humid <= 80, 'humid looks ok')
cb(null)
})
},
function (cb) {
climate.readTemperature('c', function(err, temp) {
if (err) return cb(err)
firstTemp = temp
t.ok(temp >= 5 && temp <= 40, 'temp looks ok')
cb(null)
})
},
function (cb) {
climate.setHeater(true, function (err) {
if (err) return cb(err)
setTimeout(cb, 1000, null)
})
},
function (cb) {
climate.readTemperature('c', function (err, temp) {
if (err) return cb(err)
heatedTemp = temp
t.ok(temp > firstTemp, 'heater works')
cb(null)
})
},
function (cb) {
climate.setHeater(false, function (err) {
if (err) return cb(err)
setTimeout(cb, 1000, null)
})
},
function (cb) {
climate.readTemperature('c', function (err, temp) {
if (err) return cb(err)
t.ok(temp < heatedTemp, 'heater turns off')
cb(null)
})
}
], function (err) {
if (err) t.error(err)
})
})