()
| 116 | */ |
| 117 | class 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. |
nothing calls this directly
no test coverage detected