@eohjsc/react-native-smart-city 0.7.3-rc24 → 0.7.3-rc25
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 +3 -2
- package/src/commons/ActionGroup/index.js +2 -2
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +4 -15
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +29 -18
- package/src/configs/API.js +1 -1
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +14 -7
- package/src/hooks/IoT/useRemoteControl.js +18 -7
- package/src/iot/RemoteControl/Bluetooth.js +19 -22
- package/src/iot/RemoteControl/Internet.js +11 -3
- package/src/navigations/UnitStack.js +1 -3
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +4 -4
- package/src/screens/Device/EditDevice/index.js +2 -2
- package/src/screens/Device/__test__/BluetoothDevice.test.js +300 -0
- package/src/screens/Device/components/BluetoothDevice.js +135 -0
- package/src/screens/Device/components/SensorDisplayItem.js +4 -3
- package/src/screens/Device/detail.js +63 -55
- package/src/utils/bluetooth.js +3 -0
|
@@ -60,6 +60,7 @@ import { useReceiveNotifications } from '../../hooks';
|
|
|
60
60
|
import useChipJsonConfiguration, {
|
|
61
61
|
useConnectChipMqtt,
|
|
62
62
|
} from '../../hooks/useMqtt';
|
|
63
|
+
import { useBluetoothDevice } from './components/BluetoothDevice';
|
|
63
64
|
|
|
64
65
|
const DeviceDetail = ({ route }) => {
|
|
65
66
|
const configIdsTemp = useRef([]);
|
|
@@ -81,13 +82,14 @@ const DeviceDetail = ({ route }) => {
|
|
|
81
82
|
});
|
|
82
83
|
const [lastEvent, setLastEvent] = useState({ id: 0, reportedAt: 0 });
|
|
83
84
|
|
|
84
|
-
const { unitData, unitId,
|
|
85
|
+
const { unitData, unitId, sensorId, sensorData, isMyUnitDeviceScreen } =
|
|
85
86
|
route?.params || {};
|
|
87
|
+
|
|
86
88
|
const [unit, setUnit] = useState(unitData || { id: unitId });
|
|
87
|
-
const [
|
|
88
|
-
const [station, setStation] = useState(
|
|
89
|
+
const [device, setDevice] = useState(sensorData || { id: sensorId });
|
|
90
|
+
const [station, setStation] = useState(device?.station);
|
|
89
91
|
const { isOwner } = useIsOwnerOfUnit(unit?.user_id);
|
|
90
|
-
const [sensorName, setSensorName] = useState(
|
|
92
|
+
const [sensorName, setSensorName] = useState(device?.name);
|
|
91
93
|
const [lockShowing, acquireLockShowing, releaseLockShowing] = useBoolean();
|
|
92
94
|
const [showPreventAccess, setShowPreventAccess, setHidePreventAccess] =
|
|
93
95
|
useBoolean(false);
|
|
@@ -112,15 +114,15 @@ const DeviceDetail = ({ route }) => {
|
|
|
112
114
|
});
|
|
113
115
|
|
|
114
116
|
const { isConnected: isEoHBackendConnected } =
|
|
115
|
-
useEoHBackendDeviceConnected(
|
|
117
|
+
useEoHBackendDeviceConnected(device);
|
|
116
118
|
|
|
117
119
|
const {
|
|
118
120
|
isConnected: isHomeAssistantConnected,
|
|
119
121
|
isConnecting: isHomeAssistantConnecting,
|
|
120
|
-
} = useHomeAssistantDeviceConnected(
|
|
122
|
+
} = useHomeAssistantDeviceConnected(device);
|
|
121
123
|
|
|
122
124
|
const { isConnected: isBluetoothConnected } =
|
|
123
|
-
useBluetoothDeviceConnected(
|
|
125
|
+
useBluetoothDeviceConnected(device);
|
|
124
126
|
|
|
125
127
|
const isDeviceHasBle = useMemo(() => {
|
|
126
128
|
if (display.items.length === 0) {
|
|
@@ -147,11 +149,11 @@ const DeviceDetail = ({ route }) => {
|
|
|
147
149
|
const { chips } = useChipJsonConfiguration(unit?.id);
|
|
148
150
|
|
|
149
151
|
const chipFiltered = useMemo(() => {
|
|
150
|
-
return chips?.filter((item) => item?.id ===
|
|
151
|
-
}, [chips,
|
|
152
|
+
return chips?.filter((item) => item?.id === device?.chip_id);
|
|
153
|
+
}, [chips, device?.chip_id]);
|
|
152
154
|
|
|
153
155
|
const { mqttConfigs } = useConnectChipMqtt(chipFiltered);
|
|
154
|
-
useDeviceWatchConfigControl(
|
|
156
|
+
useDeviceWatchConfigControl(device, display, mqttConfigs);
|
|
155
157
|
|
|
156
158
|
const isShowSetupEmergencyContact = useMemo(
|
|
157
159
|
() =>
|
|
@@ -171,7 +173,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
171
173
|
);
|
|
172
174
|
|
|
173
175
|
const { isFavorite, addToFavorites, removeFromFavorites } =
|
|
174
|
-
useFavoriteDevice(
|
|
176
|
+
useFavoriteDevice(device);
|
|
175
177
|
|
|
176
178
|
const currentUserId = useSCContextSelector(
|
|
177
179
|
(state) => state.auth.account.user.id
|
|
@@ -181,6 +183,8 @@ const DeviceDetail = ({ route }) => {
|
|
|
181
183
|
return Number(currentUserId) === Number(unit?.user_id);
|
|
182
184
|
}, [currentUserId, unit]);
|
|
183
185
|
|
|
186
|
+
const bluetoothDevice = useBluetoothDevice(device);
|
|
187
|
+
|
|
184
188
|
const fetchUnitDetail = useCallback(async () => {
|
|
185
189
|
const { success, data } = await axiosGet(API.UNIT.UNIT_DETAIL(unitId));
|
|
186
190
|
if (success) {
|
|
@@ -233,43 +237,40 @@ const DeviceDetail = ({ route }) => {
|
|
|
233
237
|
|
|
234
238
|
const fetchSensorDetail = useCallback(async () => {
|
|
235
239
|
const { success, data, resp_status } = await axiosGet(
|
|
236
|
-
API.DEVICE.
|
|
240
|
+
API.DEVICE.DEVICE_DETAIL(sensorId || sensorData?.id)
|
|
237
241
|
);
|
|
238
242
|
if (success) {
|
|
239
|
-
|
|
243
|
+
setDevice(data);
|
|
240
244
|
setSensorName(data.name);
|
|
241
245
|
setStation(data.station);
|
|
242
246
|
} else if (resp_status === 404) {
|
|
243
247
|
setShowPreventAccess();
|
|
244
248
|
}
|
|
245
|
-
}, [
|
|
249
|
+
}, [sensorId, sensorData?.id, setShowPreventAccess]);
|
|
246
250
|
|
|
247
251
|
useEffect(() => {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
252
|
-
}, [sensorId, sensorData]);
|
|
252
|
+
fetchSensorDetail();
|
|
253
|
+
}, [fetchSensorDetail]);
|
|
253
254
|
|
|
254
255
|
const fetchRemoteControlOptions = useCallback(async () => {
|
|
255
256
|
const { success, data } = await axiosGet(
|
|
256
|
-
API.DEVICE.REMOTE_CONTROL_OPTIONS(
|
|
257
|
+
API.DEVICE.REMOTE_CONTROL_OPTIONS(device?.id),
|
|
257
258
|
{},
|
|
258
259
|
true
|
|
259
260
|
);
|
|
260
261
|
success && setControlOptions(data);
|
|
261
|
-
}, [
|
|
262
|
+
}, [device]);
|
|
262
263
|
|
|
263
264
|
const fetchDataDeviceDetail = useCallback(async () => {
|
|
264
265
|
if (!token) {
|
|
265
266
|
return;
|
|
266
267
|
}
|
|
267
|
-
if (!
|
|
268
|
+
if (!device) {
|
|
268
269
|
return;
|
|
269
270
|
}
|
|
270
271
|
|
|
271
272
|
const { success, data } = await axiosGet(
|
|
272
|
-
API.DEVICE.DISPLAY(
|
|
273
|
+
API.DEVICE.DISPLAY(device?.id),
|
|
273
274
|
{},
|
|
274
275
|
true
|
|
275
276
|
);
|
|
@@ -302,7 +303,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
302
303
|
(item) => item.template.toLowerCase().search('action') !== -1
|
|
303
304
|
) &&
|
|
304
305
|
(await fetchRemoteControlOptions());
|
|
305
|
-
}, [token,
|
|
306
|
+
}, [token, device, setDeviceId, fetchRemoteControlOptions]);
|
|
306
307
|
|
|
307
308
|
const {
|
|
308
309
|
deviceId: emergencyDeviceId,
|
|
@@ -336,7 +337,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
336
337
|
menuItems.push({
|
|
337
338
|
route: Routes.ActivityLog,
|
|
338
339
|
data: {
|
|
339
|
-
id:
|
|
340
|
+
id: device?.id,
|
|
340
341
|
type: 'action',
|
|
341
342
|
share: unit,
|
|
342
343
|
filterEnabled: {
|
|
@@ -352,21 +353,21 @@ const DeviceDetail = ({ route }) => {
|
|
|
352
353
|
text: t('edit'),
|
|
353
354
|
route: Routes.EditDevice,
|
|
354
355
|
data: {
|
|
355
|
-
sensor,
|
|
356
|
+
sensor: device,
|
|
356
357
|
setSensorNameDetail: setSensorName,
|
|
357
358
|
sensorNameDetail: sensorName,
|
|
358
|
-
setSensorDetail:
|
|
359
|
+
setSensorDetail: setDevice,
|
|
359
360
|
},
|
|
360
361
|
});
|
|
361
362
|
menuItems.push({
|
|
362
363
|
route: Routes.ManageAccess,
|
|
363
|
-
data: { unit, sensor },
|
|
364
|
+
data: { unit, sensor: device },
|
|
364
365
|
text: t('manage_access'),
|
|
365
366
|
});
|
|
366
367
|
menuItems.push({
|
|
367
368
|
route: Routes.ChangePosition,
|
|
368
369
|
data: {
|
|
369
|
-
sensor,
|
|
370
|
+
sensor: device,
|
|
370
371
|
display,
|
|
371
372
|
setDisplay,
|
|
372
373
|
evaluate,
|
|
@@ -378,7 +379,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
378
379
|
menuItems.push({
|
|
379
380
|
text: t('move_to_another_sub_unit'),
|
|
380
381
|
route: Routes.MoveToAnotherSubUnit,
|
|
381
|
-
data: { unit, sensor, station, isMyUnitDeviceScreen },
|
|
382
|
+
data: { unit, sensor: device, station, isMyUnitDeviceScreen },
|
|
382
383
|
});
|
|
383
384
|
}
|
|
384
385
|
if (isShowSetupEmergencyContact) {
|
|
@@ -401,7 +402,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
401
402
|
route: Routes.SideMenuDetail,
|
|
402
403
|
data: {
|
|
403
404
|
unit,
|
|
404
|
-
sensor,
|
|
405
|
+
sensor: device,
|
|
405
406
|
side_menu: el,
|
|
406
407
|
},
|
|
407
408
|
text: el.name,
|
|
@@ -462,7 +463,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
462
463
|
t,
|
|
463
464
|
isShowSetUpSmartLock,
|
|
464
465
|
isFavorite,
|
|
465
|
-
|
|
466
|
+
device,
|
|
466
467
|
unit,
|
|
467
468
|
sensorName,
|
|
468
469
|
evaluate,
|
|
@@ -479,11 +480,11 @@ const DeviceDetail = ({ route }) => {
|
|
|
479
480
|
|
|
480
481
|
useEffect(() => {
|
|
481
482
|
fetchDataDeviceDetail();
|
|
482
|
-
}, [
|
|
483
|
+
}, [device, isNetworkConnected, fetchDataDeviceDetail]);
|
|
483
484
|
|
|
484
|
-
const onRefresh = useCallback(() => {
|
|
485
|
-
fetchSensorDetail();
|
|
486
|
-
fetchDataDeviceDetail();
|
|
485
|
+
const onRefresh = useCallback(async () => {
|
|
486
|
+
await fetchSensorDetail();
|
|
487
|
+
await fetchDataDeviceDetail();
|
|
487
488
|
if (
|
|
488
489
|
unit.remote_control_options &&
|
|
489
490
|
unit.remote_control_options.googlehome?.length &&
|
|
@@ -493,9 +494,15 @@ const DeviceDetail = ({ route }) => {
|
|
|
493
494
|
await connectHomeAssistant(unit.remote_control_options.googlehome);
|
|
494
495
|
})();
|
|
495
496
|
}
|
|
496
|
-
checkScanDevicesBLE();
|
|
497
|
-
|
|
498
|
-
|
|
497
|
+
await checkScanDevicesBLE();
|
|
498
|
+
}, [
|
|
499
|
+
fetchSensorDetail,
|
|
500
|
+
fetchDataDeviceDetail,
|
|
501
|
+
unit?.remote_control_options,
|
|
502
|
+
isNetworkConnected,
|
|
503
|
+
checkScanDevicesBLE,
|
|
504
|
+
connectHomeAssistant,
|
|
505
|
+
]);
|
|
499
506
|
|
|
500
507
|
useFocusEffect(
|
|
501
508
|
useCallback(() => {
|
|
@@ -537,7 +544,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
537
544
|
|
|
538
545
|
const fetchValues = async () => {
|
|
539
546
|
const { success, data, resp_status } = await axiosGet(
|
|
540
|
-
API.DEVICE.DISPLAY_VALUES_V2(
|
|
547
|
+
API.DEVICE.DISPLAY_VALUES_V2(device?.id),
|
|
541
548
|
{
|
|
542
549
|
params: params,
|
|
543
550
|
}
|
|
@@ -557,7 +564,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
557
564
|
setDisplayValuesData((prevState) => {
|
|
558
565
|
if (prevState.isConnected !== data.is_connected) {
|
|
559
566
|
setAction(Action.SET_DEVICES_STATUS, [
|
|
560
|
-
{ id:
|
|
567
|
+
{ id: device?.id, is_connected: data.is_connected },
|
|
561
568
|
]);
|
|
562
569
|
}
|
|
563
570
|
const lastUpdated = data.last_updated && moment(data.last_updated);
|
|
@@ -603,16 +610,16 @@ const DeviceDetail = ({ route }) => {
|
|
|
603
610
|
};
|
|
604
611
|
if (
|
|
605
612
|
isNetworkConnected &&
|
|
606
|
-
|
|
607
|
-
|
|
613
|
+
device?.is_managed_by_backend &&
|
|
614
|
+
device?.device_type !== DEVICE_TYPE.LG_THINQ
|
|
608
615
|
) {
|
|
609
616
|
fetchValues();
|
|
610
617
|
} else {
|
|
611
|
-
Object.keys(
|
|
618
|
+
Object.keys(device).length > 1 &&
|
|
612
619
|
setLoading((preState) => ({ ...preState, isConnected: false }));
|
|
613
620
|
}
|
|
614
621
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
615
|
-
}, [display.items, isNetworkConnected,
|
|
622
|
+
}, [display.items, isNetworkConnected, device, mqttConfigs])
|
|
616
623
|
);
|
|
617
624
|
|
|
618
625
|
useWatchConfigs(chipFiltered.length ? [] : configIdsTemp.current);
|
|
@@ -638,12 +645,12 @@ const DeviceDetail = ({ route }) => {
|
|
|
638
645
|
|
|
639
646
|
const getDataFromLocal = async () => {
|
|
640
647
|
const displayData = await getLocalData(
|
|
641
|
-
`@CACHE_REQUEST_${API.DEVICE.DISPLAY(
|
|
648
|
+
`@CACHE_REQUEST_${API.DEVICE.DISPLAY(device?.id)}`
|
|
642
649
|
);
|
|
643
650
|
displayData && setDisplay(JSON.parse(displayData));
|
|
644
651
|
|
|
645
652
|
const controlOptionData = await getLocalData(
|
|
646
|
-
`@CACHE_REQUEST_${API.DEVICE.REMOTE_CONTROL_OPTIONS(
|
|
653
|
+
`@CACHE_REQUEST_${API.DEVICE.REMOTE_CONTROL_OPTIONS(device?.id)}`
|
|
647
654
|
);
|
|
648
655
|
controlOptionData && setControlOptions(JSON.parse(controlOptionData));
|
|
649
656
|
setLoading((preState) => ({ ...preState, displayTemplate: false }));
|
|
@@ -721,8 +728,8 @@ const DeviceDetail = ({ route }) => {
|
|
|
721
728
|
);
|
|
722
729
|
|
|
723
730
|
useEffect(() => {
|
|
724
|
-
SCConfig.setCurrentSensorDisplay(
|
|
725
|
-
}, [
|
|
731
|
+
SCConfig.setCurrentSensorDisplay(device);
|
|
732
|
+
}, [device]);
|
|
726
733
|
|
|
727
734
|
const shouldRender =
|
|
728
735
|
loading.displayTemplate === false &&
|
|
@@ -740,7 +747,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
740
747
|
<View style={styles.wrapTemplate}>
|
|
741
748
|
{shouldRender && (
|
|
742
749
|
<SensorConnectStatusViewHeader
|
|
743
|
-
sensor={
|
|
750
|
+
sensor={device}
|
|
744
751
|
connectedViaNetwork={isEoHBackendConnected}
|
|
745
752
|
connectedViaBle={isBluetoothConnected}
|
|
746
753
|
connectedViaHomeAssistant={isHomeAssistantConnected}
|
|
@@ -751,7 +758,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
751
758
|
}
|
|
752
759
|
showWindDirection={showWindDirection}
|
|
753
760
|
isDeviceHasBle={isDeviceHasBle}
|
|
754
|
-
key={`sensor${
|
|
761
|
+
key={`sensor${device.id}`}
|
|
755
762
|
>
|
|
756
763
|
{display.items.map((item, index) => {
|
|
757
764
|
return (
|
|
@@ -773,7 +780,8 @@ const DeviceDetail = ({ route }) => {
|
|
|
773
780
|
item={item}
|
|
774
781
|
evaluate={evaluate}
|
|
775
782
|
emergency={onEmergencyButtonPress}
|
|
776
|
-
sensor={
|
|
783
|
+
sensor={device}
|
|
784
|
+
bluetoothDevice={bluetoothDevice}
|
|
777
785
|
offsetTitle={offsetTitle}
|
|
778
786
|
setOffsetTitle={setOffsetTitle}
|
|
779
787
|
setShowWindDirection={setShowWindDirection}
|
|
@@ -807,7 +815,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
807
815
|
onSendNowAlert={onSendNowAlert}
|
|
808
816
|
onHide={releaseLockShowing}
|
|
809
817
|
unit={unit}
|
|
810
|
-
station={
|
|
818
|
+
station={device?.station}
|
|
811
819
|
/>
|
|
812
820
|
|
|
813
821
|
<AlertSent
|
|
@@ -816,7 +824,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
816
824
|
onPressMain={onViewDetails}
|
|
817
825
|
onHide={releaseLockShowing}
|
|
818
826
|
unit={unit}
|
|
819
|
-
station={
|
|
827
|
+
station={device?.station}
|
|
820
828
|
/>
|
|
821
829
|
<PreventAccess
|
|
822
830
|
visible={showPreventAccess}
|
|
@@ -865,7 +873,7 @@ const DeviceDetail = ({ route }) => {
|
|
|
865
873
|
type="H4"
|
|
866
874
|
style={styles.textName}
|
|
867
875
|
>
|
|
868
|
-
{unit?.name} - {
|
|
876
|
+
{unit?.name} - {device?.station?.name}
|
|
869
877
|
</Text>
|
|
870
878
|
<IconOutline
|
|
871
879
|
accessibilityLabel={AccessibilityLabel.BUTTON_POPUP_RESOLVED_ICON}
|