@robotical/raftjs 2.1.4 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,62 +0,0 @@
1
- import AttributeHandler from "./RaftAttributeHandler";
2
- import RaftChannelSimulated from "./RaftChannelSimulated";
3
- import { DeviceAttributesState, DeviceTimeline } from "./RaftDeviceStates";
4
-
5
- function hexToBytes(hex: string): Uint8Array {
6
- const bytes = new Uint8Array(hex.length / 2);
7
- for (let idx = 0; idx < bytes.length; idx++) {
8
- bytes[idx] = parseInt(hex.slice(idx * 2, idx * 2 + 2), 16);
9
- }
10
- return bytes;
11
- }
12
-
13
- function createTimeline(): DeviceTimeline {
14
- return {
15
- timestampsUs: [],
16
- lastReportTimestampUs: 0,
17
- reportTimestampOffsetUs: 0,
18
- totalSamplesAdded: 0,
19
- emaLastSampleTimeUs: 0,
20
- emaIntervalUs: 0,
21
- emaPrevPollTimeUs: 0,
22
- emaCalibrated: false,
23
- emaCalibrationPolls: 0,
24
- };
25
- }
26
-
27
- describe("RaftChannelSimulated", () => {
28
- test("generates decodable SCD30 CO2, temperature and humidity data", () => {
29
- const channel = new RaftChannelSimulated() as any;
30
- const deviceTypeInfo = channel._deviceTypeInfo.SCD30;
31
- expect(deviceTypeInfo).toBeDefined();
32
-
33
- const msg = channel._createSimulatedDeviceInfoMsg(1000, "SCD30", deviceTypeInfo, 2500) as Uint8Array;
34
- const publishedJson = JSON.parse(new TextDecoder().decode(msg.slice(2)));
35
- const payload = hexToBytes(publishedJson["1"].SCD30.pub);
36
-
37
- const attrs: DeviceAttributesState = {};
38
- const timeline = createTimeline();
39
- const handler = new AttributeHandler();
40
-
41
- const nextIdx = handler.processMsgAttrGroup(payload, 0, timeline, deviceTypeInfo.resp, attrs, 100);
42
- expect(nextIdx).toBe(26);
43
-
44
- expect(attrs.CO2.values).toHaveLength(1);
45
- expect(attrs.temperature.values).toHaveLength(1);
46
- expect(attrs.humidity.values).toHaveLength(1);
47
-
48
- const co2 = attrs.CO2.values[0] as number;
49
- const temperature = attrs.temperature.values[0] as number;
50
- const humidity = attrs.humidity.values[0] as number;
51
-
52
- expect(Number.isFinite(co2)).toBe(true);
53
- expect(Number.isFinite(temperature)).toBe(true);
54
- expect(Number.isFinite(humidity)).toBe(true);
55
- expect(co2).toBeGreaterThanOrEqual(400);
56
- expect(co2).toBeLessThanOrEqual(2000);
57
- expect(temperature).toBeGreaterThanOrEqual(-40);
58
- expect(temperature).toBeLessThanOrEqual(125);
59
- expect(humidity).toBeGreaterThanOrEqual(0);
60
- expect(humidity).toBeLessThanOrEqual(100);
61
- });
62
- });