@eohjsc/react-native-smart-city 0.7.24 → 0.7.26

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.
Files changed (54) hide show
  1. package/index.js +2 -0
  2. package/package.json +1 -1
  3. package/src/Images/Common/search-menu.svg +7 -0
  4. package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplateStyle.js +2 -1
  5. package/src/commons/ActionGroup/OneBigButtonTemplateStyle.js +1 -2
  6. package/src/commons/ActionGroup/SliderRangeTemplate.js +1 -3
  7. package/src/commons/ActionGroup/TerminalBoxTemplate.js +1 -4
  8. package/src/commons/ActionGroup/TextBoxTemplate.js +1 -5
  9. package/src/commons/ActionGroup/ThreeButtonTemplate/components/ThreeButtonDefaultStyles.js +1 -1
  10. package/src/commons/ActionGroup/__test__/index.test.js +51 -0
  11. package/src/commons/ActionGroup/index.js +4 -0
  12. package/src/commons/Dashboard/MyDashboardDevice/__test__/index.test.js +171 -0
  13. package/src/commons/Dashboard/MyDashboardDevice/index.js +218 -0
  14. package/src/commons/Dashboard/MyDashboardDevice/styles.js +60 -0
  15. package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +0 -10
  16. package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +114 -48
  17. package/src/commons/Dashboard/MyUnit/index.js +74 -27
  18. package/src/commons/Dashboard/MyUnit/styles.js +16 -1
  19. package/src/commons/DateTimeRangeChange/index.js +1 -1
  20. package/src/commons/Device/ItemDevice.js +12 -3
  21. package/src/commons/Device/ItemDeviceWrapper.js +10 -2
  22. package/src/commons/SelectUnit/index.js +19 -5
  23. package/src/commons/SelectUnit/styles.js +0 -1
  24. package/src/commons/SubUnit/DeviceTemplate/DeviceTemplate.js +8 -3
  25. package/src/commons/Widgets/IFrame/IFrameStyles.js +1 -0
  26. package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfigStyles.js +1 -0
  27. package/src/configs/API.js +11 -0
  28. package/src/configs/AccessibilityLabel.js +2 -0
  29. package/src/configs/Constants.js +3 -0
  30. package/src/context/actionType.ts +4 -0
  31. package/src/context/mockStore.ts +5 -0
  32. package/src/context/reducer.ts +30 -5
  33. package/src/iot/mqtt.js +163 -47
  34. package/src/navigations/UnitStack.js +22 -0
  35. package/src/screens/Device/__test__/detail.test.js +42 -1
  36. package/src/screens/Device/__test__/mqttDetail.test.js +411 -190
  37. package/src/screens/Device/__test__/sensorDisplayItem.test.js +27 -0
  38. package/src/screens/Device/components/DonutChart.js +5 -14
  39. package/src/screens/Device/components/SensorDisplayItem.js +92 -61
  40. package/src/screens/Device/components/VisualChart.js +0 -12
  41. package/src/screens/Device/detail.js +50 -14
  42. package/src/screens/Device/hooks/useDashboardDevice.js +34 -0
  43. package/src/screens/Device/styles.js +16 -0
  44. package/src/screens/SubUnit/AddSubUnit.js +18 -8
  45. package/src/screens/SubUnit/__test__/AddSubUnit.test.js +5 -3
  46. package/src/screens/Unit/GoToDetailUnit.js +30 -0
  47. package/src/screens/Unit/__test__/GoToDetailUnit.test.js +103 -0
  48. package/src/utils/FactoryGateway.js +105 -0
  49. package/src/utils/I18n/translations/en.js +4 -0
  50. package/src/utils/I18n/translations/vi.js +4 -0
  51. package/src/utils/Route/index.js +1 -0
  52. package/src/utils/Storage.js +18 -4
  53. package/src/utils/Utils.js +2 -1
  54. package/src/utils/Functions/preloadImages.js +0 -38
@@ -1,4 +1,5 @@
1
1
  import { NavigationContext } from '@react-navigation/native';
2
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
3
  import MockAdapter from 'axios-mock-adapter';
3
4
  import mqtt from 'precompiled-mqtt/dist/mqtt.browser';
4
5
  import React from 'react';
@@ -106,6 +107,7 @@ describe('test DeviceDetail', () => {
106
107
  jest.useFakeTimers();
107
108
  mock.reset();
108
109
  watchMultiConfigs.mockClear();
110
+ AsyncStorage.clear();
109
111
  setConfigGlobalState('configValues', {});
110
112
  gatewayData = JSON.parse(JSON.stringify(gatewayDataFactory));
111
113
  });
@@ -270,134 +272,223 @@ describe('test DeviceDetail', () => {
270
272
  expect(watchMultiConfigs).not.toHaveBeenCalled();
271
273
  });
272
274
 
273
- it('should render device detail, modbus not call updateGlobalValue, configs is empty', async () => {
274
- gatewayData.sensors = [{ id: configDataFactory.sensor, configs: [] }];
275
+ // MODBUS
276
+ const testModbus = async (data, expect1, expect2) => {
275
277
  const valueBoxs = await _receiveDataOnDeviceDetail(
276
278
  [{ id: 128323 }, { id: 128324 }],
277
279
  `eoh/chip/${gatewayData.code}/data`,
278
- {
279
- data: '00010002',
280
- }
280
+ { data }
281
281
  );
282
- expect(valueBoxs[0].props.value).toEqual('--');
283
- expect(valueBoxs[1].props.value).toEqual('--');
282
+ expect(valueBoxs[0].props.value).toEqual(expect1);
283
+ expect(valueBoxs[1].props.value).toEqual(expect2);
284
+ };
285
+
286
+ it('should render device detail, modbus not call updateGlobalValue, configs is empty', async () => {
287
+ gatewayData.sensors = [{ id: configDataFactory.sensor, configs: [] }];
288
+ await testModbus('00010002', '--', '--');
284
289
  });
285
290
 
286
291
  it('should render device detail, modbus not call updateGlobalValue, sensors is empty', async () => {
287
292
  gatewayData.sensors = [];
288
- const valueBoxs = await _receiveDataOnDeviceDetail(
289
- [{ id: 128323 }, { id: 128324 }],
290
- `eoh/chip/${gatewayData.code}/data`,
291
- {
292
- data: '00010002',
293
- }
294
- );
295
- expect(valueBoxs[0].props.value).toEqual('--');
296
- expect(valueBoxs[1].props.value).toEqual('--');
293
+ await testModbus('00010002', '--', '--');
297
294
  });
298
295
 
299
296
  it('should render device detail, modbus call updateGlobalValue, modbus_gateway is empty', async () => {
300
297
  gatewayData.modbus_gateway = null;
301
- const valueBoxs = await _receiveDataOnDeviceDetail(
302
- [{ id: 128323 }, { id: 128324 }],
303
- `eoh/chip/${gatewayData.code}/data`,
304
- {
305
- data: '00012',
306
- }
307
- );
308
- expect(valueBoxs[0].props.value).toEqual('--');
309
- expect(valueBoxs[1].props.value).toEqual('--');
298
+ await testModbus('00012', '--', '--');
310
299
  });
311
300
 
312
301
  it('should render device detail, modbus call updateGlobalValue, func 1', async () => {
313
302
  gatewayData.modbus_gateway.sensors[0].configs[1].func = 1;
314
- const valueBoxs = await _receiveDataOnDeviceDetail(
315
- [{ id: 128323 }, { id: 128324 }],
316
- `eoh/chip/${gatewayData.code}/data`,
317
- {
318
- data: '00012',
319
- }
320
- );
321
- expect(valueBoxs[0].props.value).toEqual(0.1);
322
- expect(valueBoxs[1].props.value).toEqual(0.2);
303
+ await testModbus('00012', 0.1, 0.2);
323
304
  });
324
305
 
325
306
  it('should render device detail, modbus call updateGlobalValue, int_all exceed 32767', async () => {
326
- const valueBoxs = await _receiveDataOnDeviceDetail(
327
- [{ id: 128323 }, { id: 128324 }],
328
- `eoh/chip/${gatewayData.code}/data`,
329
- {
330
- data: '0001F000',
331
- }
307
+ await testModbus('0001F000', 0.1, -409.6);
308
+ });
309
+
310
+ it('should render device detail, modbus call updateGlobalValue, filter zero', async () => {
311
+ gatewayData.sensors[1].configs[0].active_filter = 'zero';
312
+ await testModbus('00000002', '--', 0.2);
313
+ });
314
+
315
+ it('should render device detail, modbus call updateGlobalValue, filter in range', async () => {
316
+ gatewayData.sensors[1].configs[0].active_filter = 'range';
317
+ gatewayData.sensors[1].configs[0].high_level = 0.5;
318
+ await testModbus('00040002', 0.4, 0.2);
319
+ });
320
+
321
+ it('should render device detail, modbus call updateGlobalValue, filter out range', async () => {
322
+ gatewayData.sensors[1].configs[0].active_filter = 'range';
323
+ gatewayData.sensors[1].configs[0].high_level = 0.3;
324
+ await testModbus('00040002', '--', 0.2);
325
+ });
326
+
327
+ it('should render device detail, modbus call updateGlobalValue, with offset', async () => {
328
+ gatewayData.sensors[1].configs[0].ai_trans_offset_value = '1.000';
329
+ await testModbus('00010002', 1.1, 0.2);
330
+ });
331
+
332
+ it('should render device detail, modbus call updateGlobalValue, with average sample first time', async () => {
333
+ const cacheKey = `last_values_${gatewayData.sensors[1].configs[0].id}`;
334
+ gatewayData.sensors[1].configs[0].decimal_behind = 2;
335
+ gatewayData.sensors[1].configs[0].ai_trans_average_sample = 2;
336
+ await testModbus('00010002', 0.1, 0.2);
337
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(cacheKey, '[0.1]');
338
+ });
339
+
340
+ it('should render device detail, modbus call updateGlobalValue, with average sample', async () => {
341
+ const cacheKey = `last_values_${gatewayData.sensors[1].configs[0].id}`;
342
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
343
+ gatewayData.sensors[1].configs[0].decimal_behind = 2;
344
+ gatewayData.sensors[1].configs[0].ai_trans_average_sample = 2;
345
+ await testModbus('00010002', 0.15, 0.2); // (0.1 + 0.2) / 2 = 0.15
346
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
347
+ cacheKey,
348
+ '[0.15,0.2]'
349
+ );
350
+ });
351
+
352
+ it('should render device detail, modbus call updateGlobalValue, with offset and average sample', async () => {
353
+ const cacheKey = `last_values_${gatewayData.sensors[1].configs[0].id}`;
354
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
355
+ gatewayData.sensors[1].configs[0].decimal_behind = 2;
356
+ gatewayData.sensors[1].configs[0].ai_trans_average_sample = 2;
357
+ gatewayData.sensors[1].configs[0].ai_trans_offset_value = '1.000';
358
+ await testModbus('00010002', 0.65, 0.2); // (0.2 + 0.1 + 1) / 2 = 0.65
359
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
360
+ cacheKey,
361
+ '[0.65,0.2]'
332
362
  );
333
- expect(valueBoxs[0].props.value).toEqual(0.1);
334
- expect(valueBoxs[1].props.value).toEqual(-409.6);
335
363
  });
336
364
 
337
- it('should render device detail, modbus call updateGlobalValue, uint_32', async () => {
338
- gatewayData.modbus_gateway.sensors[0].configs[1].transformer = 'uint_32';
365
+ const dataConverterWrongData = async (transformer) => {
366
+ gatewayData.modbus_gateway.sensors[0].configs[1].transformer = transformer;
339
367
  gatewayData.modbus_gateway.sensors[0].configs[1].len = 2;
340
368
  gatewayData.modbus_gateway.sensors[0].configs[1].len2 = 2;
341
369
 
342
- const valueBoxs = await _receiveDataOnDeviceDetail(
343
- [{ id: 128323 }, { id: 128324 }],
344
- `eoh/chip/${gatewayData.code}/data`,
345
- {
346
- data: '0001CCDDBBAA',
347
- }
348
- );
349
- expect(valueBoxs[0].props.value).toEqual(0.1);
350
- expect(valueBoxs[1].props.value).toEqual(343708356.1);
351
- });
370
+ await testModbus('0001P1234567', 0.1, '--');
371
+ };
352
372
 
353
- it('should render device detail, modbus call updateGlobalValue, float_cdba', async () => {
354
- gatewayData.modbus_gateway.sensors[0].configs[1].transformer = 'float_cdba';
373
+ const dataConverterUint32 = async (transformer, data) => {
374
+ gatewayData.modbus_gateway.sensors[0].configs[1].transformer = transformer;
355
375
  gatewayData.modbus_gateway.sensors[0].configs[1].len = 2;
356
376
  gatewayData.modbus_gateway.sensors[0].configs[1].len2 = 2;
357
377
 
358
- const valueBoxs = await _receiveDataOnDeviceDetail(
359
- [{ id: 128323 }, { id: 128324 }],
360
- `eoh/chip/${gatewayData.code}/data`,
361
- {
362
- data: '000101234567',
363
- }
364
- );
378
+ await testModbus(`0001${data}`, 0.1, 405923122.0);
379
+ };
380
+
381
+ it('should render device detail, modbus call updateGlobalValue, uint_32_abcd', async () => {
382
+ await dataConverterUint32('uint_32_abcd', 'F1F2F3F4');
383
+ });
365
384
 
366
- expect(valueBoxs[0].props.value).toEqual(0.1);
367
- expect(valueBoxs[1].props.value).toEqual(369.6);
385
+ it('should render device detail, modbus call updateGlobalValue, uint_32_abcd, data not hex format', async () => {
386
+ await dataConverterWrongData('uint_32_abcd');
368
387
  });
369
388
 
370
- it('should render device detail, modbus call updateGlobalValue, float_cdba, data not hex format', async () => {
371
- gatewayData.modbus_gateway.sensors[0].configs[1].transformer = 'float_cdba';
389
+ it('should render device detail, modbus call updateGlobalValue, uint_32_dcba', async () => {
390
+ await dataConverterUint32('uint_32_dcba', 'F4F3F2F1');
391
+ });
392
+
393
+ it('should render device detail, modbus call updateGlobalValue, uint_32_dcba, data not hex format', async () => {
394
+ await dataConverterWrongData('uint_32_dcba');
395
+ });
396
+
397
+ it('should render device detail, modbus call updateGlobalValue, uint_32_badc', async () => {
398
+ await dataConverterUint32('uint_32_badc', 'F2F1F4F3');
399
+ });
400
+
401
+ it('should render device detail, modbus call updateGlobalValue, uint_32_badc, data not hex format', async () => {
402
+ await dataConverterWrongData('uint_32_badc');
403
+ });
404
+
405
+ it('should render device detail, modbus call updateGlobalValue, uint_32_cdab', async () => {
406
+ await dataConverterUint32('uint_32_cdab', 'F3F4F1F2');
407
+ });
408
+
409
+ it('should render device detail, modbus call updateGlobalValue, uint_32_cdab, data not hex format', async () => {
410
+ await dataConverterWrongData('uint_32_cdab');
411
+ });
412
+
413
+ const dataConverterInt32 = async (transformer, data) => {
414
+ gatewayData.modbus_gateway.sensors[0].configs[1].transformer = transformer;
372
415
  gatewayData.modbus_gateway.sensors[0].configs[1].len = 2;
373
416
  gatewayData.modbus_gateway.sensors[0].configs[1].len2 = 2;
374
417
 
375
- const valueBoxs = await _receiveDataOnDeviceDetail(
376
- [{ id: 128323 }, { id: 128324 }],
377
- `eoh/chip/${gatewayData.code}/data`,
378
- {
379
- data: '0001P1234567',
380
- }
381
- );
418
+ await testModbus(`0001${data}`, 0.1, -23573607.6);
419
+ };
382
420
 
383
- expect(valueBoxs[0].props.value).toEqual(0.1);
384
- expect(valueBoxs[1].props.value).toEqual('--');
421
+ it('should render device detail, modbus call updateGlobalValue, int_32_abcd', async () => {
422
+ await dataConverterInt32('int_32_abcd', 'F1F2F3F4');
385
423
  });
386
424
 
387
- it('should render device detail, modbus call updateGlobalValue, float_abcd, data not hex format', async () => {
388
- gatewayData.modbus_gateway.sensors[0].configs[1].transformer = 'float_abcd';
425
+ it('should render device detail, modbus call updateGlobalValue, int_32_abcd, data not hex format', async () => {
426
+ await dataConverterWrongData('int_32_abcd');
427
+ });
428
+
429
+ it('should render device detail, modbus call updateGlobalValue, int_32_dcba', async () => {
430
+ await dataConverterInt32('int_32_dcba', 'F4F3F2F1');
431
+ });
432
+
433
+ it('should render device detail, modbus call updateGlobalValue, int_32_dcba, data not hex format', async () => {
434
+ await dataConverterWrongData('int_32_dcba');
435
+ });
436
+
437
+ it('should render device detail, modbus call updateGlobalValue, int_32_badc', async () => {
438
+ await dataConverterInt32('int_32_badc', 'F2F1F4F3');
439
+ });
440
+
441
+ it('should render device detail, modbus call updateGlobalValue, int_32_badc, data not hex format', async () => {
442
+ await dataConverterWrongData('int_32_badc');
443
+ });
444
+
445
+ it('should render device detail, modbus call updateGlobalValue, int_32_cdab', async () => {
446
+ await dataConverterInt32('int_32_cdab', 'F3F4F1F2');
447
+ });
448
+
449
+ it('should render device detail, modbus call updateGlobalValue, int_32_cdab, data not hex format', async () => {
450
+ await dataConverterWrongData('int_32_cdab');
451
+ });
452
+
453
+ const dataConverterFloat = async (transformer, data) => {
454
+ gatewayData.modbus_gateway.sensors[0].configs[1].transformer = transformer;
389
455
  gatewayData.modbus_gateway.sensors[0].configs[1].len = 2;
390
456
  gatewayData.modbus_gateway.sensors[0].configs[1].len2 = 2;
457
+ gatewayData.sensors[1].configs[1].decimal_behind = 2;
391
458
 
392
- const valueBoxs = await _receiveDataOnDeviceDetail(
393
- [{ id: 128323 }, { id: 128324 }],
394
- `eoh/chip/${gatewayData.code}/data`,
395
- {
396
- data: '0001P5670123', // reverse for simple
397
- }
398
- );
399
- expect(valueBoxs[0].props.value).toEqual(0.1);
400
- expect(valueBoxs[1].props.value).toEqual('--');
459
+ await testModbus(`0001${data}`, 0.1, 2.76);
460
+ };
461
+
462
+ it('should render device detail, modbus call updateGlobalValue, float_abcd', async () => {
463
+ await dataConverterFloat('float_abcd', '41DCCCCD');
464
+ });
465
+
466
+ it('should render device detail, modbus call updateGlobalValue, float_abcd, data not hex format', async () => {
467
+ await dataConverterWrongData('float_abcd');
468
+ });
469
+
470
+ it('should render device detail, modbus call updateGlobalValue, float_dcba', async () => {
471
+ await dataConverterFloat('float_dcba', 'CDCCDC41');
472
+ });
473
+
474
+ it('should render device detail, modbus call updateGlobalValue, float_dcba, data not hex format', async () => {
475
+ await dataConverterWrongData('float_dcba');
476
+ });
477
+
478
+ it('should render device detail, modbus call updateGlobalValue, float_badc', async () => {
479
+ await dataConverterFloat('float_badc', 'DC41CDCC');
480
+ });
481
+
482
+ it('should render device detail, modbus call updateGlobalValue, float_badc, data not hex format', async () => {
483
+ await dataConverterWrongData('float_badc');
484
+ });
485
+
486
+ it('should render device detail, modbus call updateGlobalValue, float_cdab', async () => {
487
+ await dataConverterFloat('float_cdab', 'CCCD41DC');
488
+ });
489
+
490
+ it('should render device detail, modbus call updateGlobalValue, float_cdab, data not hex format', async () => {
491
+ await dataConverterWrongData('float_cdab');
401
492
  });
402
493
 
403
494
  it('should render device detail, modbus call updateGlobalValue, int_first4', async () => {
@@ -405,32 +496,15 @@ describe('test DeviceDetail', () => {
405
496
  gatewayData.modbus_gateway.sensors[0].configs[1].len = 2;
406
497
  gatewayData.modbus_gateway.sensors[0].configs[1].len2 = 2;
407
498
 
408
- const valueBoxs = await _receiveDataOnDeviceDetail(
409
- [{ id: 128323 }, { id: 128324 }],
410
- `eoh/chip/${gatewayData.code}/data`,
411
- {
412
- data: '0001CCDDBBAA',
413
- }
414
- );
415
- expect(valueBoxs[0].props.value).toEqual(0.1);
416
- expect(valueBoxs[1].props.value).toEqual(5244.5);
499
+ await testModbus('0001CCDDBBAA', 0.1, 5244.5);
417
500
  });
418
501
 
419
- test('should render device detail, modbus call updateGlobalValue, int_last4', async () => {
502
+ it('should render device detail, modbus call updateGlobalValue, int_last4', async () => {
420
503
  gatewayData.modbus_gateway.sensors[0].configs[1].transformer = 'int_last4';
421
504
  gatewayData.modbus_gateway.sensors[0].configs[1].len = 2;
422
505
  gatewayData.modbus_gateway.sensors[0].configs[1].len2 = 2;
423
506
 
424
- const valueBoxs = await _receiveDataOnDeviceDetail(
425
- [{ id: 128323 }, { id: 128324 }],
426
- `eoh/chip/${gatewayData.code}/data`,
427
- {
428
- data: '0001CCDDBBAA',
429
- }
430
- );
431
-
432
- expect(valueBoxs[0].props.value).toEqual(0.1);
433
- expect(valueBoxs[1].props.value).toEqual(4804.2);
507
+ await testModbus('0001CCDDBBAA', 0.1, 4804.2);
434
508
  });
435
509
 
436
510
  it('should render device detail, modbus call updateGlobalValue, convert_ai', async () => {
@@ -440,16 +514,7 @@ describe('test DeviceDetail', () => {
440
514
  gatewayData.modbus_gateway.sensors[0].configs[1].ai_trans_min_value = 0;
441
515
  gatewayData.modbus_gateway.sensors[0].configs[1].ai_trans_max_value = 100;
442
516
 
443
- const valueBoxs = await _receiveDataOnDeviceDetail(
444
- [{ id: 128323 }, { id: 128324 }],
445
- `eoh/chip/${gatewayData.code}/data`,
446
- {
447
- data: '00010FFF',
448
- }
449
- );
450
-
451
- expect(valueBoxs[0].props.value).toEqual(0.1);
452
- expect(valueBoxs[1].props.value).toEqual(10);
517
+ await testModbus('00010FFF', 0.1, 10);
453
518
  });
454
519
 
455
520
  it('should render device detail, modbus call updateGlobalValue, convert_ai min_raw same max_raw', async () => {
@@ -459,90 +524,112 @@ describe('test DeviceDetail', () => {
459
524
  gatewayData.modbus_gateway.sensors[0].configs[1].ai_trans_min_value = 0;
460
525
  gatewayData.modbus_gateway.sensors[0].configs[1].ai_trans_max_value = 100;
461
526
 
462
- const valueBoxs = await _receiveDataOnDeviceDetail(
463
- [{ id: 128323 }, { id: 128324 }],
464
- `eoh/chip/${gatewayData.code}/data`,
465
- {
466
- data: '00010FFF',
467
- }
468
- );
527
+ await testModbus('00010FFF', 0.1, '--');
528
+ });
469
529
 
470
- expect(valueBoxs[0].props.value).toEqual(0.1);
471
- expect(valueBoxs[1].props.value).toEqual('--');
530
+ it('should render device detail, modbus call updateGlobalValue, convert_ai negative value', async () => {
531
+ gatewayData.modbus_gateway.sensors[0].configs[1].transformer = 'convert_ai';
532
+ gatewayData.modbus_gateway.sensors[0].configs[1].ai_trans_min_raw_in = 0;
533
+ gatewayData.modbus_gateway.sensors[0].configs[1].ai_trans_max_raw_in = 4000;
534
+ gatewayData.modbus_gateway.sensors[0].configs[1].ai_trans_min_value = -200;
535
+ gatewayData.modbus_gateway.sensors[0].configs[1].ai_trans_max_value = -100;
536
+
537
+ await testModbus('000107D0', 0.1, -15);
472
538
  });
473
539
 
474
540
  it('should render device detail, modbus call updateGlobalValue, transformer not supported', async () => {
475
541
  gatewayData.modbus_gateway.sensors[0].configs[1].transformer =
476
542
  'WRONG_TRANSFORMER';
477
- const valueBoxs = await _receiveDataOnDeviceDetail(
478
- [{ id: 128323 }, { id: 128324 }],
479
- `eoh/chip/${gatewayData.code}/data`,
480
- {
481
- data: '00012',
482
- }
483
- );
484
543
 
485
- expect(valueBoxs[0].props.value).toEqual(0.1);
486
- expect(valueBoxs[1].props.value).toEqual('--');
544
+ await testModbus('00012', 0.1, '--');
487
545
  });
488
546
 
489
- // // ARDUINO PIN
490
- it('should render device detail, arduino pin call updateGlobalValue', async () => {
547
+ // ARDUINO PIN
548
+ const testArduinoPin = async (url, data, expect1, expect2) => {
491
549
  const valueBoxs = await _receiveDataOnDeviceDetail(
492
550
  [{ id: 128282 }, { id: 128324 }],
493
- 'config/128282/value/',
494
- {
495
- v: 10,
496
- }
551
+ url,
552
+ data
497
553
  );
554
+ expect(valueBoxs[0].props.value).toEqual(expect1);
555
+ expect(valueBoxs[1].props.value).toEqual(expect2);
556
+ };
498
557
 
499
- expect(valueBoxs[0].props.value).toEqual(10);
500
- expect(valueBoxs[1].props.value).toEqual('--');
558
+ it('should render device detail, arduino pin call updateGlobalValue', async () => {
559
+ await testArduinoPin('config/128282/value/', { v: 10 }, 10, '--');
501
560
  });
502
561
 
503
- it('arduino pin submit data type string updateGlobalValue', async () => {
504
- const valueBoxs = await _receiveDataOnDeviceDetail(
505
- [{ id: 128282 }, { id: 128324 }],
506
- 'config/128282/value/',
507
- {
508
- v: 'on',
509
- }
562
+ it('should render device detail, arduino pin call updateGlobalValue, filter zero', async () => {
563
+ gatewayData.sensors[0].configs[0].active_filter = 'zero';
564
+ await testArduinoPin('config/128282/value/', { v: 0 }, '--', '--');
565
+ });
566
+
567
+ it('should render device detail, arduino pin call updateGlobalValue, filter in range', async () => {
568
+ gatewayData.sensors[0].configs[0].active_filter = 'range';
569
+ gatewayData.sensors[0].configs[0].high_level = 11;
570
+ await testArduinoPin('config/128282/value/', { v: 10 }, 10, '--');
571
+ });
572
+
573
+ it('should render device detail, arduino pin call updateGlobalValue, filter out range', async () => {
574
+ gatewayData.sensors[0].configs[0].active_filter = 'range';
575
+ gatewayData.sensors[0].configs[0].high_level = 10;
576
+ await testArduinoPin('config/128282/value/', { v: 11 }, '--', '--');
577
+ });
578
+
579
+ it('should render device detail, arduino pin call updateGlobalValue, with offset', async () => {
580
+ gatewayData.sensors[0].configs[0].ai_trans_offset_value = '1.000';
581
+ await testArduinoPin('config/128282/value/', { v: 10 }, 11, '--');
582
+ });
583
+
584
+ it('should render device detail, arduino pin call updateGlobalValue, with average sample first time', async () => {
585
+ const cacheKey = `last_values_${gatewayData.sensors[0].configs[0].id}`;
586
+ gatewayData.sensors[0].configs[0].decimal_behind = 2;
587
+ gatewayData.sensors[0].configs[0].ai_trans_average_sample = 2;
588
+ await testArduinoPin('config/128282/value/', { v: 10 }, 10, '--');
589
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(cacheKey, '[10]');
590
+ });
591
+
592
+ it('should render device detail, arduino pin call updateGlobalValue, with average sample', async () => {
593
+ const cacheKey = `last_values_${gatewayData.sensors[0].configs[0].id}`;
594
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
595
+ gatewayData.sensors[0].configs[0].decimal_behind = 2;
596
+ gatewayData.sensors[0].configs[0].ai_trans_average_sample = 2;
597
+ await testArduinoPin('config/128282/value/', { v: 10 }, 5.1, '--'); // (10 + 0.2) / 2 = 5.1
598
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
599
+ cacheKey,
600
+ '[5.1,0.2]'
510
601
  );
602
+ });
511
603
 
512
- expect(valueBoxs[0].props.value).toEqual('on');
513
- expect(valueBoxs[1].props.value).toEqual('--');
604
+ it('should render device detail, arduino pin call updateGlobalValue, with offset and average sample', async () => {
605
+ const cacheKey = `last_values_${gatewayData.sensors[0].configs[0].id}`;
606
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
607
+ gatewayData.sensors[0].configs[0].decimal_behind = 2;
608
+ gatewayData.sensors[0].configs[0].ai_trans_average_sample = 2;
609
+ gatewayData.sensors[0].configs[0].ai_trans_offset_value = '1.000';
610
+ await testArduinoPin('config/128282/value/', { v: 10 }, 5.6, '--'); // (10 + 1 + 0.2) / 2 = 5.6
611
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
612
+ cacheKey,
613
+ '[5.6,0.2]'
614
+ );
615
+ });
616
+
617
+ it('arduino pin submit data type string updateGlobalValue', async () => {
618
+ await testArduinoPin('config/128282/value/', { v: 'on' }, 'on', '--');
514
619
  });
515
620
 
516
621
  it('should render device detail, arduino pin not call updateGlobalValue, configs is empty', async () => {
517
622
  gatewayData.sensors = [{ id: configDataFactory.sensor, configs: [] }];
518
- const valueBoxs = await _receiveDataOnDeviceDetail(
519
- [{ id: 128282 }, { id: 128324 }],
520
- 'config/128282/value/',
521
- {
522
- v: 10,
523
- }
524
- );
525
-
526
- expect(valueBoxs[0].props.value).toEqual('--');
527
- expect(valueBoxs[1].props.value).toEqual('--');
623
+ await testArduinoPin('config/128282/value/', { v: 10 }, '--', '--');
528
624
  });
529
625
 
530
626
  it('should render device detail, arduino pin not call updateGlobalValue, sensors is empty', async () => {
531
627
  gatewayData.sensors = [];
532
- const valueBoxs = await _receiveDataOnDeviceDetail(
533
- [{ id: 128282 }, { id: 128324 }],
534
- 'config/128282/value/',
535
- {
536
- v: 10,
537
- }
538
- );
539
-
540
- expect(valueBoxs[0].props.value).toEqual('--');
541
- expect(valueBoxs[1].props.value).toEqual('--');
628
+ await testArduinoPin('config/128282/value/', { v: 10 }, '--', '--');
542
629
  });
543
630
 
544
631
  // ZIGBEE
545
- it('should render device detail, zigbee call updateGlobalValue', async () => {
632
+ const testZigbee = async (expect1, expect2) => {
546
633
  const valueBoxs = await _receiveDataOnDeviceDetail(
547
634
  [{ id: 111 }, { id: 222 }],
548
635
  'zigbee/0x00158d00022fd3c6/data/',
@@ -550,50 +637,184 @@ describe('test DeviceDetail', () => {
550
637
  data: { temperature_measured: 36 },
551
638
  }
552
639
  );
640
+ expect(valueBoxs[0].props.value).toEqual(expect1);
641
+ expect(valueBoxs[1].props.value).toEqual(expect2);
642
+ };
553
643
 
554
- expect(valueBoxs[0].props.value).toEqual(36);
555
- expect(valueBoxs[1].props.value).toEqual('--');
644
+ it('should render device detail, zigbee call updateGlobalValue', async () => {
645
+ await testZigbee(36, '--');
556
646
  });
557
647
 
558
- it('should render device detail, zigbee not call updateGlobalValue, configs is empty', async () => {
559
- gatewayData.sensors = [{ id: configDataFactory.sensor, configs: [] }];
648
+ it('should render device detail, zigbee call updateGlobalValue, filter zero', async () => {
649
+ gatewayData.sensors[2].configs[0].active_filter = 'zero';
560
650
  const valueBoxs = await _receiveDataOnDeviceDetail(
561
651
  [{ id: 111 }, { id: 222 }],
562
652
  'zigbee/0x00158d00022fd3c6/data/',
563
653
  {
564
- data: { temperature_measured: 36 },
654
+ data: { temperature_measured: 0 },
565
655
  }
566
656
  );
567
-
568
657
  expect(valueBoxs[0].props.value).toEqual('--');
569
658
  expect(valueBoxs[1].props.value).toEqual('--');
570
659
  });
571
660
 
661
+ it('should render device detail, zigbee call updateGlobalValue, filter in range', async () => {
662
+ gatewayData.sensors[2].configs[0].active_filter = 'range';
663
+ gatewayData.sensors[2].configs[0].high_level = 37;
664
+ await testZigbee(36, '--');
665
+ });
666
+
667
+ it('should render device detail, zigbee call updateGlobalValue, filter out range', async () => {
668
+ gatewayData.sensors[2].configs[0].active_filter = 'range';
669
+ gatewayData.sensors[2].configs[0].high_level = 35;
670
+ await testZigbee('--', '--');
671
+ });
672
+
673
+ it('should render device detail, zigbee call updateGlobalValue, with offset', async () => {
674
+ gatewayData.sensors[2].configs[0].ai_trans_offset_value = '1.000';
675
+ await testZigbee(37, '--');
676
+ });
677
+
678
+ it('should render device detail, zigbee call updateGlobalValue, with average sample first time', async () => {
679
+ const cacheKey = `last_values_${gatewayData.sensors[2].configs[0].id}`;
680
+ gatewayData.sensors[2].configs[0].decimal_behind = 2;
681
+ gatewayData.sensors[2].configs[0].ai_trans_average_sample = 2;
682
+ await testZigbee(36, '--');
683
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(cacheKey, '[36]');
684
+ });
685
+
686
+ it('should render device detail, zigbee call updateGlobalValue, with average sample', async () => {
687
+ const cacheKey = `last_values_${gatewayData.sensors[2].configs[0].id}`;
688
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
689
+ gatewayData.sensors[2].configs[0].decimal_behind = 2;
690
+ gatewayData.sensors[2].configs[0].ai_trans_average_sample = 2;
691
+ await testZigbee(18.1, '--'); // (36 + 0.2) / 2 = 18.1
692
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
693
+ cacheKey,
694
+ '[18.1,0.2]'
695
+ );
696
+ });
697
+
698
+ it('should render device detail, zigbee call updateGlobalValue, with offset and average sample', async () => {
699
+ const cacheKey = `last_values_${gatewayData.sensors[2].configs[0].id}`;
700
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
701
+ gatewayData.sensors[2].configs[0].decimal_behind = 2;
702
+ gatewayData.sensors[2].configs[0].ai_trans_average_sample = 2;
703
+ gatewayData.sensors[2].configs[0].ai_trans_offset_value = '1.000';
704
+ await testZigbee(18.6, '--'); // (36 + 1 + 0.2) / 2 = 5.6
705
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
706
+ cacheKey,
707
+ '[18.6,0.2]'
708
+ );
709
+ });
710
+
711
+ it('should render device detail, zigbee not call updateGlobalValue, configs is empty', async () => {
712
+ gatewayData.sensors = [{ id: configDataFactory.sensor, configs: [] }];
713
+ await testZigbee('--', '--');
714
+ });
715
+
572
716
  it('should render device detail, zigbee not call updateGlobalValue, sensors is empty', async () => {
573
717
  gatewayData.sensors = [];
718
+ await testZigbee('--', '--');
719
+ });
720
+
721
+ it('should render device detail, zigbee not call updateGlobalValue, zigbee_gateway is empty', async () => {
722
+ gatewayData.zigbee_gateway = null;
723
+ await testZigbee('--', '--');
724
+ });
725
+
726
+ // Third Party
727
+ const testThirdParty = async (expect1, expect2) => {
574
728
  const valueBoxs = await _receiveDataOnDeviceDetail(
575
- [{ id: 111 }, { id: 222 }],
576
- 'zigbee/0x00158d00022fd3c6/data/',
729
+ [{ id: 37 }, { id: 38 }],
730
+ 'third_party/0x00158d00022fd388/data/',
577
731
  {
578
- data: { temperature_measured: 36 },
732
+ led: 1,
579
733
  }
580
734
  );
735
+ expect(valueBoxs[0].props.value).toEqual(expect1);
736
+ expect(valueBoxs[1].props.value).toEqual(expect2);
737
+ };
581
738
 
582
- expect(valueBoxs[0].props.value).toEqual('--');
583
- expect(valueBoxs[1].props.value).toEqual('--');
739
+ it('should render device detail, Third Party call updateGlobalValue', async () => {
740
+ await testThirdParty(1, '--');
584
741
  });
585
742
 
586
- it('should render device detail, zigbee not call updateGlobalValue, zigbee_gateway is empty', async () => {
587
- gatewayData.zigbee_gateway = null;
743
+ it('should render device detail, Third Party call updateGlobalValue, filter zero', async () => {
744
+ gatewayData.sensors[3].configs[0].active_filter = 'zero';
588
745
  const valueBoxs = await _receiveDataOnDeviceDetail(
589
- [{ id: 111 }, { id: 222 }],
590
- 'zigbee/0x00158d00022fd3c6/data/',
746
+ [{ id: 37 }, { id: 38 }],
747
+ 'third_party/0x00158d00022fd388/data/',
591
748
  {
592
- data: { temperature_measured: 36 },
749
+ led: 0,
593
750
  }
594
751
  );
595
-
596
752
  expect(valueBoxs[0].props.value).toEqual('--');
597
753
  expect(valueBoxs[1].props.value).toEqual('--');
598
754
  });
755
+
756
+ it('should render device detail, Third Party call updateGlobalValue, filter in range', async () => {
757
+ gatewayData.sensors[3].configs[0].active_filter = 'range';
758
+ gatewayData.sensors[3].configs[0].high_level = 2;
759
+ await testThirdParty(1, '--');
760
+ });
761
+
762
+ it('should render device detail, Third Party call updateGlobalValue, filter out range', async () => {
763
+ gatewayData.sensors[3].configs[0].active_filter = 'range';
764
+ gatewayData.sensors[3].configs[0].high_level = 0.5;
765
+ await testThirdParty('--', '--');
766
+ });
767
+
768
+ it('should render device detail, Third Party call updateGlobalValue, with offset', async () => {
769
+ gatewayData.sensors[3].configs[0].ai_trans_offset_value = '1.000';
770
+ await testThirdParty(2, '--');
771
+ });
772
+
773
+ it('should render device detail, Third Party call updateGlobalValue, with average sample first time', async () => {
774
+ const cacheKey = `last_values_${gatewayData.sensors[3].configs[0].id}`;
775
+ gatewayData.sensors[3].configs[0].decimal_behind = 2;
776
+ gatewayData.sensors[3].configs[0].ai_trans_average_sample = 2;
777
+ await testThirdParty(1, '--');
778
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(cacheKey, '[1]');
779
+ });
780
+
781
+ it('should render device detail, Third Party call updateGlobalValue, with average sample', async () => {
782
+ const cacheKey = `last_values_${gatewayData.sensors[3].configs[0].id}`;
783
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
784
+ gatewayData.sensors[3].configs[0].decimal_behind = 2;
785
+ gatewayData.sensors[3].configs[0].ai_trans_average_sample = 2;
786
+ await testThirdParty(0.6, '--'); // (1 + 0.2) / 2 = 0.6
787
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
788
+ cacheKey,
789
+ '[0.6,0.2]'
790
+ );
791
+ });
792
+
793
+ it('should render device detail, Third Party call updateGlobalValue, with offset and average sample', async () => {
794
+ const cacheKey = `last_values_${gatewayData.sensors[3].configs[0].id}`;
795
+ await AsyncStorage.setItem(cacheKey, '[0.2, 0.3, 0.4, 0.5]');
796
+ gatewayData.sensors[3].configs[0].decimal_behind = 2;
797
+ gatewayData.sensors[3].configs[0].ai_trans_average_sample = 2;
798
+ gatewayData.sensors[3].configs[0].ai_trans_offset_value = '1.000';
799
+ await testThirdParty(1.1, '--'); // (1 + 1 + 0.2) / 2 = 1.1
800
+ expect(AsyncStorage.setItem).toHaveBeenLastCalledWith(
801
+ cacheKey,
802
+ '[1.1,0.2]'
803
+ );
804
+ });
805
+
806
+ it('should render device detail, Third Party not call updateGlobalValue, configs is empty', async () => {
807
+ gatewayData.sensors = [{ id: configDataFactory.sensor, configs: [] }];
808
+ await testThirdParty('--', '--');
809
+ });
810
+
811
+ it('should render device detail, Third Party not call updateGlobalValue, sensors is empty', async () => {
812
+ gatewayData.sensors = [];
813
+ await testThirdParty('--', '--');
814
+ });
815
+
816
+ it('should render device detail, Third Party not call updateGlobalValue, third_party_gateway is empty', async () => {
817
+ gatewayData.third_party_gateway = null;
818
+ await testThirdParty('--', '--');
819
+ });
599
820
  });