@eohjsc/react-native-smart-city 0.3.73 → 0.3.75
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/Device/HorizontalBarChart.js +1 -1
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +2 -2
- package/src/hooks/IoT/useRemoteControl.js +26 -3
- package/src/iot/RemoteControl/Bluetooth.js +2 -2
- package/src/iot/RemoteControl/__test__/Bluetooth.test.js +10 -10
- package/src/screens/Device/__test__/detail.test.js +38 -3
- package/src/utils/I18n/translations/en.json +1 -1
- package/src/utils/I18n/translations/vi.json +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { memo, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { View, StyleSheet } from 'react-native';
|
|
3
3
|
import { isEmpty } from 'lodash';
|
|
4
|
-
|
|
4
|
+
import HighchartsReactNative from '@eohjsc/highcharts';
|
|
5
5
|
|
|
6
6
|
import { Colors } from '../../configs';
|
|
7
7
|
import { getMaxValueIndex } from '../../utils/chartHelper/getMaxValueIndex';
|
|
@@ -109,7 +109,7 @@ describe('Test useRemoteControl', () => {
|
|
|
109
109
|
data,
|
|
110
110
|
'bluetooth'
|
|
111
111
|
);
|
|
112
|
-
expect(sendCommandOverInternet).toBeCalledTimes(
|
|
112
|
+
expect(sendCommandOverInternet).toBeCalledTimes(6);
|
|
113
113
|
expect(sendCommandOverHomeAssistant).not.toBeCalled();
|
|
114
114
|
});
|
|
115
115
|
|
|
@@ -176,7 +176,7 @@ describe('Test useRemoteControl', () => {
|
|
|
176
176
|
data,
|
|
177
177
|
userId
|
|
178
178
|
);
|
|
179
|
-
expect(sendCommandOverInternet).
|
|
179
|
+
expect(sendCommandOverInternet).toBeCalled();
|
|
180
180
|
expect(sendCommandOverHomeAssistant).not.toBeCalled();
|
|
181
181
|
});
|
|
182
182
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
1
2
|
import { useCallback } from 'react';
|
|
2
3
|
import { useSCContextSelector } from '../../context';
|
|
3
4
|
import { sendCommandOverHomeAssistant } from '../../iot/RemoteControl/HomeAssistant';
|
|
@@ -10,6 +11,15 @@ import { ToastBottomHelper } from '../../utils/Utils';
|
|
|
10
11
|
import { t } from 'i18n-js';
|
|
11
12
|
import NetInfo from '@react-native-community/netinfo';
|
|
12
13
|
|
|
14
|
+
let count = 0;
|
|
15
|
+
|
|
16
|
+
const onRetry = (callback) => {
|
|
17
|
+
const to = setTimeout(() => {
|
|
18
|
+
callback;
|
|
19
|
+
clearTimeout(to);
|
|
20
|
+
}, 200);
|
|
21
|
+
};
|
|
22
|
+
|
|
13
23
|
const useRemoteControl = () => {
|
|
14
24
|
const homeAssistantConnections = useSCContextSelector(
|
|
15
25
|
(state) => state.iot.homeassistant.connections
|
|
@@ -26,10 +36,23 @@ const useRemoteControl = () => {
|
|
|
26
36
|
return result;
|
|
27
37
|
}
|
|
28
38
|
|
|
29
|
-
if (action.command_prefer_over_bluetooth) {
|
|
39
|
+
if (action.command_prefer_over_bluetooth && count < 5) {
|
|
40
|
+
count++;
|
|
30
41
|
try {
|
|
31
|
-
|
|
42
|
+
const res = await sendCommandOverBluetooth(
|
|
43
|
+
device,
|
|
44
|
+
action,
|
|
45
|
+
data,
|
|
46
|
+
userId
|
|
47
|
+
);
|
|
48
|
+
if (res) {
|
|
49
|
+
count = 0;
|
|
50
|
+
return res;
|
|
51
|
+
} else {
|
|
52
|
+
onRetry(sendRemoteCommand(device, action, data, userId));
|
|
53
|
+
}
|
|
32
54
|
} catch (err) {
|
|
55
|
+
onRetry(sendRemoteCommand(device, action, data, userId));
|
|
33
56
|
const netState = await NetInfo.fetch();
|
|
34
57
|
if (netState.isConnected) {
|
|
35
58
|
result = false;
|
|
@@ -53,7 +76,7 @@ const useRemoteControl = () => {
|
|
|
53
76
|
}
|
|
54
77
|
}
|
|
55
78
|
}
|
|
56
|
-
|
|
79
|
+
count = 0;
|
|
57
80
|
// Checking only bluetooth: not other options
|
|
58
81
|
if (action.is_only_bluetooth) {
|
|
59
82
|
ToastBottomHelper.error(
|
|
@@ -156,8 +156,7 @@ export const sendDataOverBluetooth = async (
|
|
|
156
156
|
t('control_device_via_bluetooth_successfully')
|
|
157
157
|
);
|
|
158
158
|
if (!keepConnect) {
|
|
159
|
-
await
|
|
160
|
-
await bleManager.cancelDeviceConnection(device.id);
|
|
159
|
+
await connectedDevice.cancelConnection();
|
|
161
160
|
}
|
|
162
161
|
} else if (notify === BLE.BLE_RESPONSE_FAILED) {
|
|
163
162
|
ToastBottomHelper.error(t('control_device_via_bluetooth_failed'));
|
|
@@ -172,6 +171,7 @@ export const sendDataOverBluetooth = async (
|
|
|
172
171
|
);
|
|
173
172
|
ToastBottomHelper.error(t('command_is_sent_to_device_via_bluetooth'));
|
|
174
173
|
} catch (e) {
|
|
174
|
+
await connectedDevice.cancelConnection();
|
|
175
175
|
ToastBottomHelper.error(t('command_is_fail_to_send_via_bluetooth'));
|
|
176
176
|
throw SEND_COMMAND_OVER_BLUETOOTH_FAIL;
|
|
177
177
|
}
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
scanBluetoothDevices,
|
|
5
5
|
clearNeedToScanDevices,
|
|
6
6
|
sendCommandOverBluetooth,
|
|
7
|
-
SEND_COMMAND_OVER_BLUETOOTH_FAIL,
|
|
8
7
|
clearFoundDevices,
|
|
9
8
|
} from '../Bluetooth';
|
|
10
9
|
|
|
@@ -129,14 +128,12 @@ describe('Test IOT Bluetooth', () => {
|
|
|
129
128
|
expect(bleManager.startDeviceScan).not.toBeCalled();
|
|
130
129
|
});
|
|
131
130
|
|
|
132
|
-
const sendCommandBluetoothFail = async (sensor) => {
|
|
133
|
-
let error = null;
|
|
131
|
+
const sendCommandBluetoothFail = async (sensor, err = undefined) => {
|
|
134
132
|
try {
|
|
135
133
|
await sendCommandOverBluetooth(sensor, {});
|
|
136
134
|
} catch (e) {
|
|
137
|
-
|
|
135
|
+
expect(e.message).toBe(err);
|
|
138
136
|
}
|
|
139
|
-
expect(error).toEqual(SEND_COMMAND_OVER_BLUETOOTH_FAIL);
|
|
140
137
|
};
|
|
141
138
|
|
|
142
139
|
it('Send command over bluetooth do nothing for sensor has no bluetooth', async () => {
|
|
@@ -164,13 +161,16 @@ describe('Test IOT Bluetooth', () => {
|
|
|
164
161
|
);
|
|
165
162
|
await scanBluetoothDevices([device.name], mockOnDeviceFound);
|
|
166
163
|
|
|
167
|
-
await sendCommandBluetoothFail(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
await sendCommandBluetoothFail(
|
|
165
|
+
{
|
|
166
|
+
remote_control_options: {
|
|
167
|
+
bluetooth: {
|
|
168
|
+
address: device.name,
|
|
169
|
+
},
|
|
171
170
|
},
|
|
172
171
|
},
|
|
173
|
-
|
|
172
|
+
"Cannot read properties of null (reading 'cancelConnection')"
|
|
173
|
+
);
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
it('Send command over bluetooth via device success', async () => {
|
|
@@ -142,6 +142,16 @@ describe('test DeviceDetail', () => {
|
|
|
142
142
|
|
|
143
143
|
let data_sensor_display = {
|
|
144
144
|
items: [
|
|
145
|
+
{
|
|
146
|
+
configuration: {
|
|
147
|
+
id: 3,
|
|
148
|
+
name: 'Emergency',
|
|
149
|
+
},
|
|
150
|
+
id: 17,
|
|
151
|
+
order: 1,
|
|
152
|
+
template: 'emergency',
|
|
153
|
+
type: 'emergency',
|
|
154
|
+
},
|
|
145
155
|
{
|
|
146
156
|
configuration: {
|
|
147
157
|
id: 2,
|
|
@@ -247,7 +257,7 @@ describe('test DeviceDetail', () => {
|
|
|
247
257
|
(el) =>
|
|
248
258
|
el.props.accessibilityLabel === AccessibilityLabel.SENSOR_DISPLAY_ITEM
|
|
249
259
|
);
|
|
250
|
-
expect(sensorDisplayItem.length).toEqual(
|
|
260
|
+
expect(sensorDisplayItem.length).toEqual(3);
|
|
251
261
|
|
|
252
262
|
const itemActionGroup = instance.find(
|
|
253
263
|
(el) =>
|
|
@@ -485,6 +495,16 @@ describe('test DeviceDetail', () => {
|
|
|
485
495
|
],
|
|
486
496
|
},
|
|
487
497
|
},
|
|
498
|
+
{
|
|
499
|
+
configuration: {
|
|
500
|
+
id: 3,
|
|
501
|
+
name: 'Emergency',
|
|
502
|
+
},
|
|
503
|
+
id: 17,
|
|
504
|
+
order: 1,
|
|
505
|
+
template: 'emergency',
|
|
506
|
+
type: 'emergency',
|
|
507
|
+
},
|
|
488
508
|
],
|
|
489
509
|
},
|
|
490
510
|
};
|
|
@@ -509,7 +529,7 @@ describe('test DeviceDetail', () => {
|
|
|
509
529
|
(el) =>
|
|
510
530
|
el.props.accessibilityLabel === AccessibilityLabel.SENSOR_DISPLAY_ITEM
|
|
511
531
|
);
|
|
512
|
-
expect(sensorDisplayItem).toHaveLength(
|
|
532
|
+
expect(sensorDisplayItem).toHaveLength(5);
|
|
513
533
|
});
|
|
514
534
|
|
|
515
535
|
it('render SensorDisplayItem emercency', async () => {
|
|
@@ -757,7 +777,7 @@ describe('test DeviceDetail', () => {
|
|
|
757
777
|
|
|
758
778
|
it('Open popup ble when server down', async () => {
|
|
759
779
|
store.bluetooth.isEnabled = false;
|
|
760
|
-
data_sensor_display.items[
|
|
780
|
+
data_sensor_display.items[2].configuration.configuration.action1_data.command_prefer_over_bluetooth = true;
|
|
761
781
|
const responseDisplay = {
|
|
762
782
|
status: 200,
|
|
763
783
|
data: data_sensor_display,
|
|
@@ -781,4 +801,19 @@ describe('test DeviceDetail', () => {
|
|
|
781
801
|
});
|
|
782
802
|
expect(mockAlertShow).not.toBeCalled();
|
|
783
803
|
});
|
|
804
|
+
|
|
805
|
+
it('Test fetchUnitDetail', async () => {
|
|
806
|
+
const unitId = 1;
|
|
807
|
+
mock.onGet(API.UNIT.UNIT_DETAIL(unitId)).reply(200);
|
|
808
|
+
await act(async () => {
|
|
809
|
+
await create(
|
|
810
|
+
wrapComponent(store, account, {
|
|
811
|
+
...route,
|
|
812
|
+
params: { ...route.params, unitData: null, unitId },
|
|
813
|
+
})
|
|
814
|
+
);
|
|
815
|
+
});
|
|
816
|
+
const urls = mock.history.get.map((item) => item.url);
|
|
817
|
+
expect(urls).toContain(API.UNIT.UNIT_DETAIL(unitId));
|
|
818
|
+
});
|
|
784
819
|
});
|
|
@@ -771,7 +771,7 @@
|
|
|
771
771
|
"please_add_your_phone_number_and_chip_name": "Please add your phone number and chip name",
|
|
772
772
|
"Please_add_gateway_name" : "Please add gateway name",
|
|
773
773
|
"phone_number_of_data_sim": "Phone number of data sim",
|
|
774
|
-
"select_a_sub_unit": "Select a sub-unit
|
|
774
|
+
"select_a_sub_unit": "Select a sub-unit",
|
|
775
775
|
"all_camera": "All Cameras",
|
|
776
776
|
"gateway_name": "Gateway name",
|
|
777
777
|
"activated_time": "Activated {time}",
|
|
@@ -781,7 +781,7 @@
|
|
|
781
781
|
"please_add_your_phone_number_and_chip_name": "Vui lòng thêm số điện thoại và tên chip của bạn",
|
|
782
782
|
"Please_add_gateway_name" : "Vui lòng thêm tên gateway",
|
|
783
783
|
"phone_number_of_data_sim": "Số điện thoại của dữ liệu sim",
|
|
784
|
-
"select_a_sub_unit": "Lựa chọn một khu vực
|
|
784
|
+
"select_a_sub_unit": "Lựa chọn một khu vực",
|
|
785
785
|
"all_camera": "All Cameras",
|
|
786
786
|
"gateway_name": "Tên Gateway",
|
|
787
787
|
"activated_time": "Đã kích hoạt {time}",
|