@eohjsc/react-native-smart-city 0.7.40 → 0.7.42
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.
- package/package.json +1 -1
- package/src/commons/Dashboard/MyDashboardDevice/index.js +14 -12
- package/src/commons/Dashboard/MyUnit/index.js +4 -3
- package/src/commons/DateTimeRangeChange/index.js +5 -5
- package/src/commons/Device/HorizontalBarChart.js +11 -24
- package/src/commons/Device/PowerConsumptionChart.js +195 -103
- package/src/commons/FieldTemplate/ChooseUserField/index.js +5 -1
- package/src/commons/Form/CurrencyInput.js +9 -18
- package/src/commons/SelectGateway/index.js +2 -1
- package/src/commons/SelectSubUnit/index.js +5 -1
- package/src/commons/SelectUnit/index.js +1 -1
- package/src/commons/SubUnit/Favorites/index.js +35 -10
- package/src/commons/SubUnit/ShortDetail.js +17 -4
- package/src/commons/SubUnit/__test__/Favorites.test.js +90 -0
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +45 -2
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +17 -9
- package/src/hooks/IoT/__test__/useValueEvaluation.test.js +12 -12
- package/src/hooks/IoT/useValueEvaluation.js +7 -3
- package/src/hooks/IoT/useWatchSharedChips.js +8 -4
- package/src/hooks/useMqtt.js +8 -4
- package/src/iot/UpdateStates.js +37 -16
- package/src/iot/mqtt.js +23 -0
- package/src/navigations/AutomateStack.js +5 -1
- package/src/screens/ActivityLog/hooks/index.js +12 -4
- package/src/screens/AddLocationMaps/index.js +6 -3
- package/src/screens/AddNewGateway/RenameNewDevices.js +2 -1
- package/src/screens/Automate/AddNewAction/ChooseConfig.js +2 -1
- package/src/screens/Automate/AddNewAction/ReceiverSelect.js +5 -1
- package/src/screens/Automate/MultiUnits.js +2 -1
- package/src/screens/Automate/ScriptDetail/index.js +11 -3
- package/src/screens/Automate/hooks/useAction.js +3 -1
- package/src/screens/Device/__test__/DeviceDetail-3rdparty.test.js +16 -5
- package/src/screens/Device/__test__/DeviceDetail-arduino.test.js +10 -0
- package/src/screens/Device/__test__/DeviceDetail-modbus.test.js +37 -8
- package/src/screens/Device/__test__/DeviceDetail-zigbee.test.js +16 -5
- package/src/screens/Device/__test__/DeviceDetail.test.js +17 -6
- package/src/screens/Device/__test__/sensorDisplayItem.test.js +47 -11
- package/src/screens/Device/components/SensorDisplayItem.js +23 -5
- package/src/screens/Device/detail.js +10 -3
- package/src/screens/Device/hooks/useEvaluateValue.js +7 -3
- package/src/screens/Device/styles.js +4 -0
- package/src/screens/SelectUnit/index.js +3 -1
- package/src/screens/Sharing/InfoMemberUnit.js +3 -1
- package/src/screens/SideMenuDetail/index.js +3 -1
- package/src/screens/Unit/SelectAddToFavorites.js +6 -2
- package/src/screens/UnitSummary/components/3PPowerConsumption/index.js +8 -48
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +121 -6
- package/src/screens/UnitSummary/components/PowerConsumption/index.js +6 -46
- package/src/screens/UnitSummary/index.js +2 -1
- package/src/utils/I18n/translations/en.js +1 -0
- package/src/utils/I18n/translations/vi.js +1 -0
- package/src/utils/chartHelper/index.js +53 -0
- package/src/utils/chartHelper/getMaxValueIndex.js +0 -11
|
@@ -277,7 +277,9 @@ const ScriptDetail = ({ route }) => {
|
|
|
277
277
|
|
|
278
278
|
const fetchAutomateActions = useCallback(async () => {
|
|
279
279
|
const { success, data: automateData } = await axiosGet(
|
|
280
|
-
API.AUTOMATE.SCRIPT_ITEMS(automateId)
|
|
280
|
+
API.AUTOMATE.SCRIPT_ITEMS(automateId),
|
|
281
|
+
{},
|
|
282
|
+
true
|
|
281
283
|
);
|
|
282
284
|
if (success) {
|
|
283
285
|
setData(automateData.script_items || []);
|
|
@@ -286,7 +288,9 @@ const ScriptDetail = ({ route }) => {
|
|
|
286
288
|
|
|
287
289
|
const fetchAutomate = useCallback(async () => {
|
|
288
290
|
const { success, data: automateData } = await axiosGet(
|
|
289
|
-
API.AUTOMATE.FETCH_AUTOMATE(automateId)
|
|
291
|
+
API.AUTOMATE.FETCH_AUTOMATE(automateId),
|
|
292
|
+
{},
|
|
293
|
+
true
|
|
290
294
|
);
|
|
291
295
|
if (success) {
|
|
292
296
|
setAutomate(automateData);
|
|
@@ -427,7 +431,11 @@ const ScriptDetail = ({ route }) => {
|
|
|
427
431
|
max_conditions_per_automation - conditions.length
|
|
428
432
|
);
|
|
429
433
|
} else {
|
|
430
|
-
const { success, data: perms } = await axiosGet(
|
|
434
|
+
const { success, data: perms } = await axiosGet(
|
|
435
|
+
API.AUTH.PERMISSIONS(),
|
|
436
|
+
{},
|
|
437
|
+
true
|
|
438
|
+
);
|
|
431
439
|
if (success) {
|
|
432
440
|
setNumberConditionsUsed(
|
|
433
441
|
perms.max_conditions_per_automation - conditions.length
|
|
@@ -43,7 +43,9 @@ const useAction = (device, scriptItems, activatedScript = {}) => {
|
|
|
43
43
|
|
|
44
44
|
const fetchDisplayActions = useCallback(async () => {
|
|
45
45
|
const { success, data } = await axiosGet(
|
|
46
|
-
API.DEVICE.DISPLAY_ACTIONS(device.id)
|
|
46
|
+
API.DEVICE.DISPLAY_ACTIONS(device.id),
|
|
47
|
+
{},
|
|
48
|
+
true
|
|
47
49
|
);
|
|
48
50
|
|
|
49
51
|
success && setDisplayActions(data);
|
|
@@ -120,6 +120,12 @@ describe('test DeviceDetail', () => {
|
|
|
120
120
|
mock.onGet(API.CHIP.SHARED_CONFIGURATION).reply(200, []);
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
afterEach(() => {
|
|
124
|
+
act(() => {
|
|
125
|
+
jest.runOnlyPendingTimers();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
123
129
|
const _receiveDataOnDeviceDetail = async (widgetConfigs, topic, message) => {
|
|
124
130
|
mock.onGet(API.CHIP.JSON_CONFIGURATION).reply(200, [gatewayData]);
|
|
125
131
|
|
|
@@ -168,6 +174,10 @@ describe('test DeviceDetail', () => {
|
|
|
168
174
|
await client.trigger('message', topic, JSON.stringify(message), 'packet');
|
|
169
175
|
});
|
|
170
176
|
|
|
177
|
+
await act(async () => {
|
|
178
|
+
jest.runOnlyPendingTimers();
|
|
179
|
+
});
|
|
180
|
+
|
|
171
181
|
const valueBox = instance.findAllByType(QualityIndicatorItem);
|
|
172
182
|
return valueBox;
|
|
173
183
|
};
|
|
@@ -370,11 +380,6 @@ describe('test DeviceDetail', () => {
|
|
|
370
380
|
);
|
|
371
381
|
});
|
|
372
382
|
|
|
373
|
-
const instance = tree.root;
|
|
374
|
-
const valueBoxs = instance.findAllByType(QualityIndicatorItem);
|
|
375
|
-
expect(valueBoxs[0].props.value).toEqual(expect1);
|
|
376
|
-
expect(valueBoxs[1].props.value).toEqual(expect2);
|
|
377
|
-
|
|
378
383
|
expect(
|
|
379
384
|
mock.history.post.filter(
|
|
380
385
|
(req) => req.url === API.IOT.CHIP_MANAGER.WATCH_DATA_CHIPS()
|
|
@@ -384,6 +389,7 @@ describe('test DeviceDetail', () => {
|
|
|
384
389
|
await act(async () => {
|
|
385
390
|
jest.runOnlyPendingTimers();
|
|
386
391
|
});
|
|
392
|
+
|
|
387
393
|
expect(
|
|
388
394
|
mock.history.post.filter(
|
|
389
395
|
(req) => req.url === API.IOT.CHIP_MANAGER.WATCH_DATA_CHIPS()
|
|
@@ -391,6 +397,11 @@ describe('test DeviceDetail', () => {
|
|
|
391
397
|
).toHaveLength(2);
|
|
392
398
|
expect(unwatchMultiDataChips).not.toHaveBeenCalled();
|
|
393
399
|
|
|
400
|
+
const instance = tree.root;
|
|
401
|
+
const valueBoxs = instance.findAllByType(QualityIndicatorItem);
|
|
402
|
+
expect(valueBoxs[0].props.value).toEqual(expect1);
|
|
403
|
+
expect(valueBoxs[1].props.value).toEqual(expect2);
|
|
404
|
+
|
|
394
405
|
await act(async () => {
|
|
395
406
|
await tree.unmount();
|
|
396
407
|
});
|
|
@@ -120,6 +120,12 @@ describe('test DeviceDetail', () => {
|
|
|
120
120
|
mock.onGet(API.CHIP.SHARED_CONFIGURATION).reply(200, []);
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
afterEach(() => {
|
|
124
|
+
act(() => {
|
|
125
|
+
jest.runOnlyPendingTimers();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
123
129
|
const _receiveDataOnDeviceDetail = async (widgetConfigs, topic, message) => {
|
|
124
130
|
mock.onGet(API.CHIP.JSON_CONFIGURATION).reply(200, [gatewayData]);
|
|
125
131
|
|
|
@@ -168,6 +174,10 @@ describe('test DeviceDetail', () => {
|
|
|
168
174
|
await client.trigger('message', topic, JSON.stringify(message), 'packet');
|
|
169
175
|
});
|
|
170
176
|
|
|
177
|
+
await act(async () => {
|
|
178
|
+
jest.runOnlyPendingTimers();
|
|
179
|
+
});
|
|
180
|
+
|
|
171
181
|
const valueBox = instance.findAllByType(QualityIndicatorItem);
|
|
172
182
|
return valueBox;
|
|
173
183
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { NavigationContext } from '@react-navigation/native';
|
|
2
1
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
|
+
import { NavigationContext } from '@react-navigation/native';
|
|
3
3
|
import MockAdapter from 'axios-mock-adapter';
|
|
4
4
|
import moment from 'moment';
|
|
5
5
|
import mqtt from 'precompiled-mqtt/dist/mqtt.browser';
|
|
6
|
-
import React from 'react';
|
|
7
6
|
import { Alert } from 'react-native';
|
|
8
7
|
import { act, create } from 'react-test-renderer';
|
|
9
8
|
|
|
@@ -120,6 +119,12 @@ describe('test DeviceDetail', () => {
|
|
|
120
119
|
mock.onGet(API.CHIP.SHARED_CONFIGURATION).reply(200, []);
|
|
121
120
|
});
|
|
122
121
|
|
|
122
|
+
afterEach(() => {
|
|
123
|
+
act(() => {
|
|
124
|
+
jest.runOnlyPendingTimers();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
123
128
|
const _receiveDataOnDeviceDetail = async (widgetConfigs, topic, message) => {
|
|
124
129
|
mock.onGet(API.CHIP.JSON_CONFIGURATION).reply(200, [gatewayData]);
|
|
125
130
|
|
|
@@ -168,6 +173,10 @@ describe('test DeviceDetail', () => {
|
|
|
168
173
|
await client.trigger('message', topic, JSON.stringify(message), 'packet');
|
|
169
174
|
});
|
|
170
175
|
|
|
176
|
+
await act(async () => {
|
|
177
|
+
jest.runOnlyPendingTimers();
|
|
178
|
+
});
|
|
179
|
+
|
|
171
180
|
const valueBox = instance.findAllByType(QualityIndicatorItem);
|
|
172
181
|
return valueBox;
|
|
173
182
|
};
|
|
@@ -500,6 +509,25 @@ describe('test DeviceDetail', () => {
|
|
|
500
509
|
await testModbus('00012', 0.1, '--');
|
|
501
510
|
});
|
|
502
511
|
|
|
512
|
+
it('should render device detail, modbus call updateGlobalValue, power_factor_4q_fp_pf > 1', async () => {
|
|
513
|
+
gatewayData.sensors[1].configs[1].scale = 0.1;
|
|
514
|
+
gatewayData.sensors[1].configs[1].decimal_behind = 1;
|
|
515
|
+
gatewayData.sensors[1].configs[1].value_converter = 'power_factor_4q_fp_pf';
|
|
516
|
+
await testModbus('0001000F', 0.1, 0.5);
|
|
517
|
+
});
|
|
518
|
+
it('should render device detail, modbus call updateGlobalValue, power_factor_4q_fp_pf < -1', async () => {
|
|
519
|
+
gatewayData.sensors[1].configs[1].scale = 0.1;
|
|
520
|
+
gatewayData.sensors[1].configs[1].decimal_behind = 1;
|
|
521
|
+
gatewayData.sensors[1].configs[1].value_converter = 'power_factor_4q_fp_pf';
|
|
522
|
+
await testModbus('0001FFF1', 0.1, -0.5);
|
|
523
|
+
});
|
|
524
|
+
it('should render device detail, modbus call updateGlobalValue, power_factor_4q_fp_pf in range [-1, 1]', async () => {
|
|
525
|
+
gatewayData.sensors[1].configs[1].scale = 0.1;
|
|
526
|
+
gatewayData.sensors[1].configs[1].decimal_behind = 1;
|
|
527
|
+
gatewayData.sensors[1].configs[1].value_converter = 'power_factor_4q_fp_pf';
|
|
528
|
+
await testModbus('00010005', 0.1, 0.5);
|
|
529
|
+
});
|
|
530
|
+
|
|
503
531
|
const dataConverterWrongData64 = async (transformer) => {
|
|
504
532
|
gatewayData.mqtt_server.is_wss = false;
|
|
505
533
|
gatewayData.modbus_gateway.sensors[0].configs[1].transformer = transformer;
|
|
@@ -688,11 +716,6 @@ describe('test DeviceDetail', () => {
|
|
|
688
716
|
);
|
|
689
717
|
});
|
|
690
718
|
|
|
691
|
-
const instance = tree.root;
|
|
692
|
-
const valueBoxs = instance.findAllByType(QualityIndicatorItem);
|
|
693
|
-
expect(valueBoxs[0].props.value).toEqual(expect1);
|
|
694
|
-
expect(valueBoxs[1].props.value).toEqual(expect2);
|
|
695
|
-
|
|
696
719
|
expect(
|
|
697
720
|
mock.history.post.filter(
|
|
698
721
|
(req) => req.url === API.IOT.CHIP_MANAGER.WATCH_DATA_CHIPS()
|
|
@@ -702,6 +725,7 @@ describe('test DeviceDetail', () => {
|
|
|
702
725
|
await act(async () => {
|
|
703
726
|
jest.runOnlyPendingTimers();
|
|
704
727
|
});
|
|
728
|
+
|
|
705
729
|
expect(
|
|
706
730
|
mock.history.post.filter(
|
|
707
731
|
(req) => req.url === API.IOT.CHIP_MANAGER.WATCH_DATA_CHIPS()
|
|
@@ -709,6 +733,11 @@ describe('test DeviceDetail', () => {
|
|
|
709
733
|
).toHaveLength(2);
|
|
710
734
|
expect(unwatchMultiDataChips).not.toHaveBeenCalled();
|
|
711
735
|
|
|
736
|
+
const instance = tree.root;
|
|
737
|
+
const valueBoxs = instance.findAllByType(QualityIndicatorItem);
|
|
738
|
+
expect(valueBoxs[0].props.value).toEqual(expect1);
|
|
739
|
+
expect(valueBoxs[1].props.value).toEqual(expect2);
|
|
740
|
+
|
|
712
741
|
await act(async () => {
|
|
713
742
|
await tree.unmount();
|
|
714
743
|
});
|
|
@@ -783,5 +812,5 @@ describe('test DeviceDetail', () => {
|
|
|
783
812
|
0.2,
|
|
784
813
|
'2025-09-09T12:00:00.123456Z'
|
|
785
814
|
);
|
|
786
|
-
});
|
|
815
|
+
}, 10000);
|
|
787
816
|
});
|
|
@@ -120,6 +120,12 @@ describe('test DeviceDetail', () => {
|
|
|
120
120
|
mock.onGet(API.CHIP.SHARED_CONFIGURATION).reply(200, []);
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
afterEach(() => {
|
|
124
|
+
act(() => {
|
|
125
|
+
jest.runOnlyPendingTimers();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
123
129
|
const _receiveDataOnDeviceDetail = async (widgetConfigs, topic, message) => {
|
|
124
130
|
mock.onGet(API.CHIP.JSON_CONFIGURATION).reply(200, [gatewayData]);
|
|
125
131
|
|
|
@@ -168,6 +174,10 @@ describe('test DeviceDetail', () => {
|
|
|
168
174
|
await client.trigger('message', topic, JSON.stringify(message), 'packet');
|
|
169
175
|
});
|
|
170
176
|
|
|
177
|
+
await act(async () => {
|
|
178
|
+
jest.runOnlyPendingTimers();
|
|
179
|
+
});
|
|
180
|
+
|
|
171
181
|
const valueBox = instance.findAllByType(QualityIndicatorItem);
|
|
172
182
|
return valueBox;
|
|
173
183
|
};
|
|
@@ -374,11 +384,6 @@ describe('test DeviceDetail', () => {
|
|
|
374
384
|
);
|
|
375
385
|
});
|
|
376
386
|
|
|
377
|
-
const instance = tree.root;
|
|
378
|
-
const valueBoxs = instance.findAllByType(QualityIndicatorItem);
|
|
379
|
-
expect(valueBoxs[0].props.value).toEqual(expect1);
|
|
380
|
-
expect(valueBoxs[1].props.value).toEqual(expect2);
|
|
381
|
-
|
|
382
387
|
expect(
|
|
383
388
|
mock.history.post.filter(
|
|
384
389
|
(req) => req.url === API.IOT.CHIP_MANAGER.WATCH_DATA_CHIPS()
|
|
@@ -388,6 +393,7 @@ describe('test DeviceDetail', () => {
|
|
|
388
393
|
await act(async () => {
|
|
389
394
|
jest.runOnlyPendingTimers();
|
|
390
395
|
});
|
|
396
|
+
|
|
391
397
|
expect(
|
|
392
398
|
mock.history.post.filter(
|
|
393
399
|
(req) => req.url === API.IOT.CHIP_MANAGER.WATCH_DATA_CHIPS()
|
|
@@ -395,6 +401,11 @@ describe('test DeviceDetail', () => {
|
|
|
395
401
|
).toHaveLength(2);
|
|
396
402
|
expect(unwatchMultiDataChips).not.toHaveBeenCalled();
|
|
397
403
|
|
|
404
|
+
const instance = tree.root;
|
|
405
|
+
const valueBoxs = instance.findAllByType(QualityIndicatorItem);
|
|
406
|
+
expect(valueBoxs[0].props.value).toEqual(expect1);
|
|
407
|
+
expect(valueBoxs[1].props.value).toEqual(expect2);
|
|
408
|
+
|
|
398
409
|
await act(async () => {
|
|
399
410
|
await tree.unmount();
|
|
400
411
|
});
|
|
@@ -117,6 +117,12 @@ describe('test DeviceDetail', () => {
|
|
|
117
117
|
mock.onGet(API.CHIP.SHARED_CONFIGURATION).reply(200, []);
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
afterEach(() => {
|
|
121
|
+
act(() => {
|
|
122
|
+
jest.runOnlyPendingTimers();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
120
126
|
it('should render device detail, connect will call subscribe', async () => {
|
|
121
127
|
mock.onGet(API.CHIP.JSON_CONFIGURATION).reply(200, [gatewayData]);
|
|
122
128
|
const client = mqtt.connect();
|
|
@@ -328,6 +334,10 @@ describe('test DeviceDetail', () => {
|
|
|
328
334
|
await client.trigger('message', topic, JSON.stringify(message), 'packet');
|
|
329
335
|
});
|
|
330
336
|
|
|
337
|
+
await act(async () => {
|
|
338
|
+
jest.runOnlyPendingTimers();
|
|
339
|
+
});
|
|
340
|
+
|
|
331
341
|
const valueBox = instance.findAllByType(QualityIndicatorItem);
|
|
332
342
|
expect(valueBox.length).toBe(widgetConfigs.length);
|
|
333
343
|
return valueBox;
|
|
@@ -442,12 +452,6 @@ describe('test DeviceDetail', () => {
|
|
|
442
452
|
);
|
|
443
453
|
});
|
|
444
454
|
|
|
445
|
-
const instance = tree.root;
|
|
446
|
-
const valueBoxs = instance.findAllByType(QualityIndicatorItem);
|
|
447
|
-
for (let i = 0; i < widgetConfigs.length; i++) {
|
|
448
|
-
expect(valueBoxs[i].props.value).toEqual(expects[i]);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
455
|
expect(
|
|
452
456
|
mock.history.post.filter(
|
|
453
457
|
(req) => req.url === API.IOT.CHIP_MANAGER.WATCH_DATA_CHIPS()
|
|
@@ -457,6 +461,7 @@ describe('test DeviceDetail', () => {
|
|
|
457
461
|
await act(async () => {
|
|
458
462
|
jest.runOnlyPendingTimers();
|
|
459
463
|
});
|
|
464
|
+
|
|
460
465
|
expect(
|
|
461
466
|
mock.history.post.filter(
|
|
462
467
|
(req) => req.url === API.IOT.CHIP_MANAGER.WATCH_DATA_CHIPS()
|
|
@@ -464,6 +469,12 @@ describe('test DeviceDetail', () => {
|
|
|
464
469
|
).toHaveLength(2);
|
|
465
470
|
expect(unwatchMultiDataChips).not.toHaveBeenCalled();
|
|
466
471
|
|
|
472
|
+
const instance = tree.root;
|
|
473
|
+
const valueBoxs = instance.findAllByType(QualityIndicatorItem);
|
|
474
|
+
for (let i = 0; i < widgetConfigs.length; i++) {
|
|
475
|
+
expect(valueBoxs[i].props.value).toEqual(expects[i]);
|
|
476
|
+
}
|
|
477
|
+
|
|
467
478
|
await act(async () => {
|
|
468
479
|
await tree.unmount();
|
|
469
480
|
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import MockAdapter from 'axios-mock-adapter';
|
|
2
|
-
import React from 'react';
|
|
3
2
|
import renderer, { act } from 'react-test-renderer';
|
|
4
3
|
|
|
5
|
-
import { SCProvider } from '../../../context';
|
|
6
|
-
import { mockSCStore } from '../../../context/mockStore';
|
|
7
|
-
import { SensorDisplayItem } from '../components/SensorDisplayItem';
|
|
8
4
|
import ActionGroup from '../../../commons/ActionGroup';
|
|
9
|
-
import
|
|
5
|
+
import DeviceAlertStatus from '../../../commons/Device/DeviceAlertStatus';
|
|
10
6
|
import FlatListItems from '../../../commons/Device/FlatListItems';
|
|
11
|
-
import VisualChart from '../components/VisualChart';
|
|
12
7
|
import FooterInfo from '../../../commons/Device/FooterInfo';
|
|
13
|
-
import
|
|
8
|
+
import LabelValue from '../../../commons/Device/LabelValue';
|
|
9
|
+
import PowerConsumptionChart from '../../../commons/Device/PowerConsumptionChart';
|
|
14
10
|
import ProgressBar from '../../../commons/Device/ProgressBar';
|
|
15
|
-
import Compass from '../../../commons/Device/WindDirection/Compass';
|
|
16
|
-
import DeviceAlertStatus from '../../../commons/Device/DeviceAlertStatus';
|
|
17
11
|
import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
|
|
18
|
-
import
|
|
12
|
+
import Compass from '../../../commons/Device/WindDirection/Compass';
|
|
13
|
+
import Anemometer from '../../../commons/Device/WindSpeed/Anemometer';
|
|
14
|
+
import MediaPlayerDetail from '../../../commons/MediaPlayerDetail';
|
|
19
15
|
import Text from '../../../commons/Text';
|
|
20
|
-
import
|
|
16
|
+
import { SCProvider } from '../../../context';
|
|
17
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
21
18
|
import api from '../../../utils/Apis/axios';
|
|
19
|
+
import SmartIr from '../../SmartIr';
|
|
20
|
+
import { SensorDisplayItem } from '../components/SensorDisplayItem';
|
|
21
|
+
import VisualChart from '../components/VisualChart';
|
|
22
22
|
|
|
23
23
|
const mockIncrementReviewTrigger = jest.fn();
|
|
24
24
|
const mockAskReview = jest.fn();
|
|
@@ -484,4 +484,40 @@ describe('Test SensorDisplayItem', () => {
|
|
|
484
484
|
const labels = instance.findAllByType(Text);
|
|
485
485
|
expect(labels[0].props.children).toEqual('Label');
|
|
486
486
|
});
|
|
487
|
+
|
|
488
|
+
it('test render power_consume', async () => {
|
|
489
|
+
const item = {
|
|
490
|
+
id: 10452,
|
|
491
|
+
order: 0,
|
|
492
|
+
template: 'summary',
|
|
493
|
+
configuration: {
|
|
494
|
+
template: 'power_consume',
|
|
495
|
+
configs: [
|
|
496
|
+
{
|
|
497
|
+
id: 78,
|
|
498
|
+
color: 'green',
|
|
499
|
+
},
|
|
500
|
+
],
|
|
501
|
+
aggregation_period: 'month',
|
|
502
|
+
},
|
|
503
|
+
label: 'Power Consume',
|
|
504
|
+
is_configuration_ready: true,
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
const sensor = {
|
|
508
|
+
name: 'Sensor name',
|
|
509
|
+
is_managed_by_backend: false,
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
await act(async () => {
|
|
513
|
+
tree = await renderer.create(wrapComponent({ item, sensor }));
|
|
514
|
+
});
|
|
515
|
+
const instance = tree.root;
|
|
516
|
+
const powerConsumptionChart = instance.findAllByType(PowerConsumptionChart);
|
|
517
|
+
expect(powerConsumptionChart).toHaveLength(1);
|
|
518
|
+
expect(powerConsumptionChart[0].props.label).toEqual('Power Consume');
|
|
519
|
+
expect(powerConsumptionChart[0].props.powerConfigId).toEqual(78);
|
|
520
|
+
expect(powerConsumptionChart[0].props.defaultPeriod).toEqual('month');
|
|
521
|
+
expect(powerConsumptionChart[0].props.color).toEqual('green');
|
|
522
|
+
});
|
|
487
523
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
import ActionGroup from '../../../commons/ActionGroup';
|
|
4
4
|
import DeviceAlertStatus from '../../../commons/Device/DeviceAlertStatus';
|
|
@@ -6,16 +6,17 @@ import EmergencyButton from '../../../commons/Device/Emergency/EmergencyButton';
|
|
|
6
6
|
import EmergencyDetail from '../../../commons/Device/Emergency/EmergencyDetail';
|
|
7
7
|
import FlatListItems from '../../../commons/Device/FlatListItems';
|
|
8
8
|
import FooterInfo from '../../../commons/Device/FooterInfo';
|
|
9
|
+
import LabelValue from '../../../commons/Device/LabelValue';
|
|
9
10
|
import PMSensorIndicator from '../../../commons/Device/PMSensor/PMSensorIndicator';
|
|
11
|
+
import PowerConsumptionChart from '../../../commons/Device/PowerConsumptionChart';
|
|
10
12
|
import ProgressBar from '../../../commons/Device/ProgressBar';
|
|
11
|
-
import LabelValue from '../../../commons/Device/LabelValue';
|
|
12
13
|
import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
|
|
13
14
|
import ListQualityIndicator from '../../../commons/Device/WaterQualitySensor/ListQualityIndicator';
|
|
14
15
|
import Compass from '../../../commons/Device/WindDirection/Compass';
|
|
15
16
|
import Anemometer from '../../../commons/Device/WindSpeed/Anemometer';
|
|
16
17
|
import MediaPlayerDetail from '../../../commons/MediaPlayerDetail';
|
|
17
|
-
import IFrame from '../../../commons/Widgets/IFrame/IFrame';
|
|
18
18
|
import Text from '../../../commons/Text';
|
|
19
|
+
import IFrame from '../../../commons/Widgets/IFrame/IFrame';
|
|
19
20
|
import { Device } from '../../../configs';
|
|
20
21
|
import { AccessibilityLabel, WIDGET_TYPE } from '../../../configs/Constants';
|
|
21
22
|
import { useSCContextSelector } from '../../../context';
|
|
@@ -47,14 +48,12 @@ export const SensorDisplayItem = ({
|
|
|
47
48
|
const { configuration = {}, id: idTemplate, label } = item;
|
|
48
49
|
const { type, template, uri, id, name, title, value_evaluation } =
|
|
49
50
|
configuration;
|
|
50
|
-
|
|
51
51
|
const sendRemoteCommand = useRemoteControl(bluetoothDevice);
|
|
52
52
|
const [processing, setProcessing] = useState(false);
|
|
53
53
|
// eslint-disable-next-line no-unused-vars
|
|
54
54
|
const [configValues, setConfigValues] = useConfigGlobalState('configValues');
|
|
55
55
|
|
|
56
56
|
const evaluateValue = useEvaluateValue();
|
|
57
|
-
|
|
58
57
|
const checkConfigValue = (configValue) => {
|
|
59
58
|
if (configValue === null || configValue === undefined) {
|
|
60
59
|
return false;
|
|
@@ -322,6 +321,25 @@ export const SensorDisplayItem = ({
|
|
|
322
321
|
return <FooterInfo data={configuration} />;
|
|
323
322
|
case 'smart_ir':
|
|
324
323
|
return <SmartIr item={item} />;
|
|
324
|
+
case 'summary':
|
|
325
|
+
switch (item?.configuration?.template) {
|
|
326
|
+
case 'power_consume':
|
|
327
|
+
return (
|
|
328
|
+
<View>
|
|
329
|
+
{configuration?.configs[0]?.id && (
|
|
330
|
+
<PowerConsumptionChart
|
|
331
|
+
label={label}
|
|
332
|
+
powerConfigId={configuration?.configs[0]?.id}
|
|
333
|
+
defaultPeriod={configuration?.aggregation_period}
|
|
334
|
+
color={configuration?.configs[0]?.color}
|
|
335
|
+
style={styles.powerConsumption}
|
|
336
|
+
/>
|
|
337
|
+
)}
|
|
338
|
+
</View>
|
|
339
|
+
);
|
|
340
|
+
default:
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
325
343
|
default:
|
|
326
344
|
break;
|
|
327
345
|
}
|
|
@@ -198,7 +198,11 @@ const DeviceDetail = ({ route }) => {
|
|
|
198
198
|
const bluetoothDevice = useBluetoothDevice(device);
|
|
199
199
|
|
|
200
200
|
const fetchUnitDetail = useCallback(async () => {
|
|
201
|
-
const { success, data } = await axiosGet(
|
|
201
|
+
const { success, data } = await axiosGet(
|
|
202
|
+
API.UNIT.UNIT_DETAIL(unitId),
|
|
203
|
+
{},
|
|
204
|
+
true
|
|
205
|
+
);
|
|
202
206
|
if (success) {
|
|
203
207
|
setUnit(data);
|
|
204
208
|
}
|
|
@@ -249,7 +253,9 @@ const DeviceDetail = ({ route }) => {
|
|
|
249
253
|
|
|
250
254
|
const fetchSensorDetail = useCallback(async () => {
|
|
251
255
|
const { success, data, resp_status } = await axiosGet(
|
|
252
|
-
API.DEVICE.DEVICE_DETAIL(sensorId || sensorData?.id)
|
|
256
|
+
API.DEVICE.DEVICE_DETAIL(sensorId || sensorData?.id),
|
|
257
|
+
{},
|
|
258
|
+
true
|
|
253
259
|
);
|
|
254
260
|
if (success) {
|
|
255
261
|
setDevice(data);
|
|
@@ -611,7 +617,8 @@ const DeviceDetail = ({ route }) => {
|
|
|
611
617
|
API.DEVICE.DISPLAY_VALUES_V2(device?.id),
|
|
612
618
|
{
|
|
613
619
|
params: params,
|
|
614
|
-
}
|
|
620
|
+
},
|
|
621
|
+
true
|
|
615
622
|
);
|
|
616
623
|
|
|
617
624
|
setLoading((preState) => {
|
|
@@ -128,9 +128,13 @@ export const useGetEvaluateValue = (configId, unitId) => {
|
|
|
128
128
|
|
|
129
129
|
if (configId && valueEvaluations[configId] === undefined) {
|
|
130
130
|
(async () => {
|
|
131
|
-
const { success, data } = await axiosGet(
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const { success, data } = await axiosGet(
|
|
132
|
+
API.VALUE_EVALUATIONS(),
|
|
133
|
+
{
|
|
134
|
+
params: { configs__id: configId },
|
|
135
|
+
},
|
|
136
|
+
true
|
|
137
|
+
);
|
|
134
138
|
if (success) {
|
|
135
139
|
setAction(Action.INIT_VALUE_EVALUATIONS, {
|
|
136
140
|
configId: configId,
|
|
@@ -40,7 +40,9 @@ const SelectUnit = () => {
|
|
|
40
40
|
|
|
41
41
|
const getAllUnits = useCallback(async () => {
|
|
42
42
|
const { success, data: automateData } = await axiosGet(
|
|
43
|
-
API.AUTOMATE.GET_ALL_UNITS()
|
|
43
|
+
API.AUTOMATE.GET_ALL_UNITS(),
|
|
44
|
+
{},
|
|
45
|
+
true
|
|
44
46
|
);
|
|
45
47
|
if (success) {
|
|
46
48
|
setData(automateData);
|
|
@@ -89,7 +89,9 @@ const InfoMemberUnit = memo(({ route }) => {
|
|
|
89
89
|
const fetchMemberInfo = useCallback(async () => {
|
|
90
90
|
setIsLoading(true);
|
|
91
91
|
const { success, data } = await axiosGet(
|
|
92
|
-
API.SHARE.UNIT_MEMBER_INFO(unit?.id, member?.id)
|
|
92
|
+
API.SHARE.UNIT_MEMBER_INFO(unit?.id, member?.id),
|
|
93
|
+
{},
|
|
94
|
+
true
|
|
93
95
|
);
|
|
94
96
|
if (success) {
|
|
95
97
|
setIsLoading(false);
|
|
@@ -117,7 +117,9 @@ const SideMenuDetail = memo(({ route }) => {
|
|
|
117
117
|
|
|
118
118
|
const fetchSideMenuDetail = useCallback(async () => {
|
|
119
119
|
const { success, data } = await axiosGet(
|
|
120
|
-
API.DEVICE.SIDE_MENU_DETAIL(sensor.id, side_menu.id)
|
|
120
|
+
API.DEVICE.SIDE_MENU_DETAIL(sensor.id, side_menu.id),
|
|
121
|
+
{},
|
|
122
|
+
true
|
|
121
123
|
);
|
|
122
124
|
if (success) {
|
|
123
125
|
setSideMenu(data);
|
|
@@ -42,10 +42,14 @@ const SelectAddToFavorites = memo(({ route }) => {
|
|
|
42
42
|
const fetchData = useCallback(async () => {
|
|
43
43
|
setLoading(true);
|
|
44
44
|
const { success: successDevice, data: dataDevice } = await axiosGet(
|
|
45
|
-
API.UNIT.DEVICES_NOT_FAVORITES(unitId)
|
|
45
|
+
API.UNIT.DEVICES_NOT_FAVORITES(unitId),
|
|
46
|
+
{},
|
|
47
|
+
true
|
|
46
48
|
);
|
|
47
49
|
const { success: successAutomate, data: dataAutomate } = await axiosGet(
|
|
48
|
-
API.UNIT.AUTOMATE_SCRIPTS_NOT_STARRED(unitId)
|
|
50
|
+
API.UNIT.AUTOMATE_SCRIPTS_NOT_STARRED(unitId),
|
|
51
|
+
{},
|
|
52
|
+
true
|
|
49
53
|
);
|
|
50
54
|
if (successDevice && successAutomate) {
|
|
51
55
|
const newData = dataDevice.filter((item) => item.devices.length > 0);
|