MCPcopy Create free account
hub / github.com/WebThingsIO/webthing-node / makeThing

Function makeThing

example/single-thing.js:37–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35}
36
37function makeThing() {
38 const thing = new Thing('urn:dev:ops:my-lamp-1234',
39 'My Lamp',
40 ['OnOffSwitch', 'Light'],
41 'A web connected lamp');
42
43 thing.addProperty(
44 new Property(thing,
45 'on',
46 new Value(true),
47 {
48 '@type': 'OnOffProperty',
49 title: 'On/Off',
50 type: 'boolean',
51 description: 'Whether the lamp is turned on',
52 }));
53 thing.addProperty(
54 new Property(thing,
55 'brightness',
56 new Value(50),
57 {
58 '@type': 'BrightnessProperty',
59 title: 'Brightness',
60 type: 'integer',
61 description: 'The level of light from 0-100',
62 minimum: 0,
63 maximum: 100,
64 unit: 'percent',
65 }));
66
67 thing.addAvailableAction(
68 'fade',
69 {
70 title: 'Fade',
71 description: 'Fade the lamp to a given level',
72 input: {
73 type: 'object',
74 required: [
75 'brightness',
76 'duration',
77 ],
78 properties: {
79 brightness: {
80 type: 'integer',
81 minimum: 0,
82 maximum: 100,
83 unit: 'percent',
84 },
85 duration: {
86 type: 'integer',
87 minimum: 1,
88 unit: 'milliseconds',
89 },
90 },
91 },
92 },
93 FadeAction);
94

Callers 1

runServerFunction · 0.70

Calls 3

addPropertyMethod · 0.95
addAvailableActionMethod · 0.95
addAvailableEventMethod · 0.95

Tested by

no test coverage detected