-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigRealtimeDataContainer.ts
517 lines (458 loc) · 13.6 KB
/
BigRealtimeDataContainer.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
import merge from "lodash.merge";
import VantPro2Interface from "../interfaces/VantPro2Interface";
import VantVueInterface from "../interfaces/VantVueInterface";
import { HighsAndLows, RichRealtimeData } from "vant-environment/structures";
import { DeviceModel } from "./settings/DeviceModel";
import RealtimeDataContainer from "./RealtimeDataContainer";
import { MinimumRealtimeDataContainerSettings } from "./settings/MinimumRealtimeDataContainerSettings";
/**
* The bigger version of the realtime data container providing {@link HighsAndLows} and {@link RichRealtimeData}.
* Only works on Vantage Pro 2 and Vue (having firmware dated after April 24, 2002 / v1.90 or above).
*
* **What are realtime data containers?**
*
* Realtime data containers provide another level of abstraction to interact with your weather station. Instead of manually calling methods like
* {@link VantInterface.getHighsAndLows} or {@link VantPro2Interface.getRichRealtimeData}, you just access the properties of an instance of this class.
* E.g. to get the current outside temperature you just create a realtime data container and access it using `container.tempOut`.
*
* Internally this works via an update cycle. Every `container.settings.updateInterval` seconds the container uses an interface to update its properties.
* As the realtime data container is an [EventEmitter](https://nodejs.org/api/events.html#class-eventemitter), you can listen to the `"update"` event. Additionally
* there is the `"valid-update"` event which only fires if no error occurrs.
*
* Realtime data containers provide **another level of stability**. If the console disconnects from your computer the realtime data container stays alive waiting
* for the console to reconnect.
*/
export default class BigRealtimeDataContainer
extends RealtimeDataContainer<
VantPro2Interface | VantVueInterface,
DeviceModel.VantagePro2 | DeviceModel.VantageVue
>
implements RichRealtimeData
{
/**
* Holds daily, monthly and yearly highs and lows for all weather elements / sensors.
*/
public highsAndLows = new HighsAndLows();
/**
* Current pressure
*/
public press: number | null = null;
/**
* The pressure's trend. There are five possible trends:
* - Falling Rapidly
* - Falling Slowly
* - Steady
* - Rising Slowly
* - Rising Rapidly
*/
public pressTrend:
| "Falling Rapidly"
| "Steady"
| "Rising Rapidly"
| "Rising Slowly"
| "Falling Slowly"
| null = null;
/**
* The pressure's trend encoded as number.
* - `-60` stands for *Falling Rapidly*
* - `-20` stands for *Falling Slowly*
* - `0` stands for *Steady*
* - `20` stands for *Rising Slowly*
* - `60` stands for *Rising Rapidly*
*/
public pressTrendID: -60 | -20 | 0 | 20 | 60 | null = null;
/** Current outside temperature */
public tempOut: number | null = null;
/** Current inside temperature (the console's temperature) */
public tempIn: number | null = null;
/**
* Current inside humidity in percent
*/
public humIn: number | null = null;
/**
* Current outside humidity in percent
*/
public humOut: number | null = null;
/**
* Currently measured wind speed
*/
public wind: number | null = null;
/**
* Average wind speed in the recent ten minutes
*/
public windAvg10m: number | null = null;
/**
* Currently measured wind direction encoded as string. Possible values are:
* - NNE
* - NE
* - ENE
* - E
* - ESE
* - SE
* - SSE
* - S
* - SSW
* - SW
* - WSW
* - W
* - WNW
* - NW
* - NNW
* - N
*/
public windDir:
| "NNE"
| "NE"
| "ENE"
| "E"
| "ESE"
| "SE"
| "SSE"
| "S"
| "SSW"
| "SW"
| "WSW"
| "W"
| "WNW"
| "NW"
| "NNW"
| "N"
| null
| null = null;
/**
* The wind speed direction in degrees (from `1` to `360`).
* `90°` is East, `180°` is South, `270°`is West and `360°` is North.
*/
public windDirDeg: number | null = null;
/**
* The current rain rate
*/
public rainRate: number | null = null;
/**
* The amount of rain that fell today
*/
public rainDay: number | null = null;
/**
* The most recent rainstorm's amount of rain
*/
public stormRain: number | null = null;
/**
* The most recent rainstorm's start date (without time)
*/
public stormStartDate: Date | null = null;
/**
* Measured evapotranspiration (ET) of the day
*/
public etDay: number | null = null;
/**
* Currently measured UV index
*/
public uv: number | null = null;
/**
* Currently measured solar radiation
*/
public solarRadiation: number | null = null;
/**
* Measured extra temperatures (from up to 7 sensors)
*/
public tempExtra: [
number | null,
number | null,
number | null,
number | null,
number | null,
number | null,
number | null
] = [null, null, null, null, null, null, null];
/**
* Measured leaf temperatures (from up to 4 sensors)
*/
public leafTemps: [
number | null,
number | null,
number | null,
number | null
] = [null, null, null, null];
/**
* Measured soil temperatures (from up to 4 sensors)
*/
public soilTemps: [
number | null,
number | null,
number | null,
number | null
] = [null, null, null, null];
/**
* Measured extra humidities (from up to 7 sensors)
*/
public humExtra: [
number | null,
number | null,
number | null,
number | null,
number | null,
number | null,
number | null
] = [null, null, null, null, null, null, null];
/**
* The amount of rain that has fallen in this month
*/
public rainMonth: number | null = null;
/**
* The amount of rain that has fallen in this year
*/
public rainYear: number | null = null;
/**
* Measured evapotranspiration (ET) in the current month
*/
public etMonth: number | null = null;
/**
* Measured evapotranspiration (ET) in the current year
*/
public etYear: number | null = null;
/**
* Measured soil moisture from up to 4 sensors
*/
public soilMoistures: [
number | null,
number | null,
number | null,
number | null
] = [null, null, null, null];
/**
* Measured leaf wetness from up to 4 sensors
*/
public leafWetnesses: [
number | null,
number | null,
number | null,
number | null
] = [null, null, null, null];
/**
* Current forecast computed by the connected vantage console
*
* There are the following options:
* - Sun
* - Partly Cloudy
* - Mostly Cloudy
* - Mostly Cloudy, Rain within 12 hours
* - Mostly Cloudy, Snow within 12 hours
* - Partly Cloudy, Rain or Snow within 12 hours
* - Partly Cloudy, Rain within 12 hours
* - Partly Cloudy, Snow within 12 hours
* - Partly Cloudy, Rain or Snow within 12 hours
*/
public forecast:
| "Mostly Clear"
| "Partly Cloudy"
| "Mostly Cloudy"
| "Mostly Cloudy, Rain within 12 hours"
| "Mostly Cloudy, Snow within 12 hours"
| "Mostly Cloudy, Rain or Snow within 12 hours"
| "Partly Cloudy, Rain within 12 hours"
| "Partly Cloudy, Rain or Snow within 12 hours"
| "Partly Cloudy, Snow within 12 hours"
| null = null;
/**
* The calculated forecast encoded as number:
* - `8` => Mostly Clear
* - `6` => Partly Cloudy
* - `2` => Mostly Cloudy
* - `3` => Mostly Cloudy, Rain within 12 hours
* - `18` => Mostly Cloudy, Snow within 12 hours
* - `19` => Partly Cloudy, Rain or Snow within 12 hours
* - `7` => Partly Cloudy, Rain within 12 hours
* - `22` => Partly Cloudy, Snow within 12 hours
* - `23` => Partly Cloudy, Rain or Snow within 12 hours
*/
public forecastID: 7 | 8 | 6 | 2 | 3 | 18 | 19 | 22 | 23 | null = null;
/**
* Not documented. Please create an issue on github if you know more about this.
*/
public forecastRule: number | null = null;
/**
* The transmitter's battery status (poorly documented)
*/
public transmitterBatteryStatus: number | null = null;
/**
* The console's battery voltage
*/
public consoleBatteryVoltage: number | null = null;
/**
* The today's sunrise time (e.g. `"06:35"`)
*/
public sunrise: string | null = null;
/**
* The today's sunset time (e.g. `"19:35"`)
*/
public sunset: string | null = null;
/** Barometric sensor raw reading */
public pressRaw: number | null = null;
/** Absolute barometric pressure. Equals to the raw sensor ({@link pressRaw}) reading plus user entered offset ({@link pressUserOffset}). */
public pressAbs: number | null = null;
/**
* The used barometric reduction method to calculate the ground pressure.
* There are three different settings:
* - user offset
* - altimeter setting
* - NOAA bar reduction
*/
public pressReductionMethod:
| "user offset"
| "altimeter setting"
| "NOAA bar reduction"
| null = null;
/**
* The used barometric reduction method encoded as number.
* `0` is user offset, `1` is altimeter setting and `2` is NOAA bar reduction.
*/
public pressReductionMethodID: 0 | 1 | 2 | null = null;
/**
* The user-entered barometric offset
*/
public pressUserOffset: number | null = null;
/**
* The barometer calibration number
*/
public pressCalibrationOffset: number | null = null;
/**
* The altimeter setting
*/
public altimeter: number | null = null;
/**
* The measured heat index
*/
public heat: number | null = null;
/**
* The calculated dew point
*/
public dewpoint: number | null = null;
/**
* Average wind speed in the recent two minutes
*/
public windAvg2m: number | null = null;
/**
* Speed of the heaviest gust in the recent 10 minutes
*/
public windGust: number | null = null;
/**
* The heaviest wind gust's ({@link windGust}) direction encoded as string. Possible values are:
* - NNE
* - NE
* - ENE
* - E
* - ESE
* - SE
* - SSE
* - S
* - SSW
* - SW
* - WSW
* - W
* - WNW
* - NW
* - NNW
* - N
*/
public windGustDir:
| "NNE"
| "NE"
| "ENE"
| "E"
| "ESE"
| "SE"
| "SSE"
| "S"
| "SSW"
| "SW"
| "WSW"
| "W"
| "WNW"
| "NW"
| "NNW"
| "N"
| null
| null = null;
/**
* The heaviest wind gust's ({@link windGust}) direction in degrees (from `1` to `360`).
* `90°` is East, `180°` is South, `270°`is West and `360°` is North.
*/
public windGustDirDeg: number | null = null;
/**
* The current wind chill
*/
public chill: number | null = null;
/**
* The currently measured THSW index. Requires a solar radiation sensor.
*/
public thsw: number | null = null;
/**
* The amount of rain that has fallen in the recent 15 minutes
*/
public rain15m: number | null = null;
/**
* The amount of rain that has fallen in the recent hour
*/
public rain1h: number | null = null;
/**
* The amount of rain that has fallen in the recent 24 hours
*/
public rain24h: number | null = null;
/**
* The time the record was created
*/
public time: Date = new Date();
/**
* Creates a small realtime container using the passed settings. Your device should be connected serially.
* @param settings the container's settings
*/
public static async create(
settings: MinimumRealtimeDataContainerSettings<
DeviceModel.VantagePro2 | DeviceModel.VantageVue
>
) {
return await this.performOnCreateAction(
new BigRealtimeDataContainer(settings)
);
}
/**
* Creates a new instance of the big realtime container and sets the settings. Doesn't perform the {@link OnContainerCreate} action.
* @param settings
*/
private constructor(
settings: MinimumRealtimeDataContainerSettings<
DeviceModel.VantagePro2 | DeviceModel.VantageVue
>
) {
super(settings);
}
/**
* Sets all sensor values to `null`.
*/
protected onConnectionError = async () => {
merge(this, new RichRealtimeData());
this.highsAndLows = new HighsAndLows();
};
/**
* Updates the big realtime data container. Merges a new RichRealtimeData instance
* into this and updates the highs and lows.
* @param device
*/
protected onUpdate = async (
device: VantPro2Interface | VantVueInterface
) => {
try {
const richRealtimeRecord = await device.getRichRealtimeData();
merge(this, richRealtimeRecord);
} catch (err) {
merge(this, new RichRealtimeData());
throw err;
}
try {
this.highsAndLows = await device.getHighsAndLows();
} catch (err) {
this.highsAndLows = new HighsAndLows();
throw err;
}
};
}