-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlamp.js
More file actions
71 lines (65 loc) · 1.47 KB
/
lamp.js
File metadata and controls
71 lines (65 loc) · 1.47 KB
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
69
70
71
import Thing from '../src/thing.js';
import ThingServer from '../src/thing-server.js';
const partialTD = {
title: 'My Lamp',
description: 'A web connected lamp',
properties: {
on: {
type: 'boolean',
title: 'On/Off',
description: 'Whether the lamp is turned on',
},
level: {
type: 'integer',
title: 'Brightness',
description: 'The level of light from 0-100',
unit: 'percent',
minimum: 0,
maximum: 100,
},
},
actions: {
fade: {
title: 'Fade',
description: 'Fade the lamp to a given level',
synchronous: false,
input: {
type: 'object',
properties: {
level: {
title: 'Brightness',
type: 'integer',
minimum: 0,
maximum: 100,
unit: 'percent',
},
duration: {
title: 'Duration',
type: 'integer',
minimum: 0,
unit: 'milliseconds',
},
},
},
},
},
events: {
overheated: {
title: 'Overheated',
data: {
type: 'number',
unit: 'degree celsius',
},
description: 'The lamp has exceeded its safe operating temperature',
},
},
};
const thing = new Thing(partialTD);
thing.setPropertyReadHandler('on', async function () {
return true;
});
thing.setPropertyReadHandler('level', async function () {
return 50;
});
const server = new ThingServer(thing);
server.start(8080);