MCPcopy Index your code
hub / github.com/WebThingsIO/webthing-node / constructor

Method constructor

example/multiple-things.js:118–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

116 */
117class FakeGpioHumiditySensor extends Thing {
118 constructor() {
119 super(
120 'urn:dev:ops:my-humidity-sensor-1234',
121 'My Humidity Sensor',
122 ['MultiLevelSensor'],
123 'A web connected humidity sensor'
124 );
125
126 this.level = new Value(0.0);
127 this.addProperty(
128 new Property(
129 this,
130 'level',
131 this.level,
132 {
133 '@type': 'LevelProperty',
134 title: 'Humidity',
135 type: 'number',
136 description: 'The current humidity in %',
137 minimum: 0,
138 maximum: 100,
139 unit: 'percent',
140 readOnly: true,
141 }));
142
143 // Poll the sensor reading every 3 seconds
144 setInterval(() => {
145 // Update the underlying value, which in turn notifies all listeners
146 const newLevel = this.readFromGPIO();
147 console.log('setting new humidity level:', newLevel);
148 this.level.notifyOfExternalUpdate(newLevel);
149 }, 3000);
150 }
151
152 /**
153 * Mimic an actual sensor updating its reading every couple seconds.

Callers

nothing calls this directly

Calls 3

readFromGPIOMethod · 0.95
addPropertyMethod · 0.80

Tested by

no test coverage detected