@eohjsc/react-native-smart-city 0.7.3 → 0.7.4
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/assets/images/Automation-fill.svg +85 -0
- package/assets/images/Map/LocationPin.svg +10 -0
- package/assets/images/Scenario-filled.svg +22 -0
- package/assets/images/schedule-fill.svg +48 -0
- package/package.json +20 -17
- package/src/commons/Action/ItemQuickAction.js +1 -1
- package/src/commons/Action/__test__/ItemQuickAction.test.js +6 -6
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +3 -3
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/ButtonWrapper.js +3 -3
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/index.test.js +5 -5
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +3 -3
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/ButtonWrapper.js +2 -2
- package/src/commons/ActionGroup/OnOffTemplate/OnOffSimpleTemplate.js +2 -2
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +2 -2
- package/src/commons/ActionGroup/SliderRangeTemplate.js +7 -7
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +2 -2
- package/src/commons/ActionGroup/SmartTiviActionTemplate/component/CircleButton.js +5 -5
- package/src/commons/ActionGroup/SmartTiviActionTemplate/component/ControlPlay.js +5 -5
- package/src/commons/ActionGroup/TerminalBoxTemplate.js +2 -2
- package/src/commons/ActionGroup/TextBoxTemplate.js +2 -2
- package/src/commons/ActionGroup/ThreeButtonTemplate/__test__/ThreeButtonCircle.test.js +2 -2
- package/src/commons/ActionGroup/ThreeButtonTemplate/__test__/ThreeButtonDefault.test.js +2 -2
- package/src/commons/ActionGroup/TimerActionTemplate.js +6 -3
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +2 -2
- package/src/commons/ActionGroup/__test__/ColorPickerTemplate.test.js +9 -10
- package/src/commons/ActionGroup/__test__/OnOffSmartLock.test.js +5 -5
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +5 -5
- package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +8 -8
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +3 -3
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +6 -6
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +1 -1
- package/src/commons/ActionGroup/__test__/index.test.js +6 -6
- package/src/commons/ActionGroup/index.js +2 -2
- package/src/commons/ActionTemplate/__test__/index.test.js +4 -4
- package/src/commons/Automate/ItemAutomate.js +9 -41
- package/src/commons/Automate/ItemConditionScriptDetail.js +109 -0
- package/src/commons/Automate/ItemConditionScriptDetailStyles.js +46 -0
- package/src/commons/Automate/__test__/ItemAutomate.test.js +0 -21
- package/src/commons/BackDefault/index.js +2 -2
- package/src/commons/BottomButtonView/index.js +1 -0
- package/src/commons/ButtonPopup/index.js +3 -2
- package/src/commons/ChartAggregationOption/__test__/FourButtonFilterHistory.test.js +2 -2
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +8 -9
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +7 -7
- package/src/commons/DateTimeRangeChange/DateTimeButton.js +3 -3
- package/src/commons/DateTimeRangeChange/index.js +1 -1
- package/src/commons/Device/ConnectedViewHeader.js +2 -2
- package/src/commons/Device/Emergency/EmergencyDetail.js +3 -3
- package/src/commons/Device/Emergency/__test__/EmergencyButton.test.js +1 -1
- package/src/commons/Device/FlatListItems.js +20 -19
- package/src/commons/Device/Hanet/ItemHanetDevice.js +3 -3
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +3 -3
- package/src/commons/Device/HorizontalBarChart.js +54 -34
- package/src/commons/Device/ItemAddNew/index.js +2 -2
- package/src/commons/Device/ItemDevice.js +5 -21
- package/src/commons/Device/SonosSpeaker/index.js +3 -3
- package/src/commons/Device/WaterPurifierStatus/AlertStatusMachine.js +2 -2
- package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +6 -2
- package/src/commons/DisplayChecking/index.js +2 -2
- package/src/commons/EmergencyButton/AlertSendConfirm.js +2 -2
- package/src/commons/FieldTemplate/ChooseUserField/index.js +2 -2
- package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +3 -3
- package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +6 -6
- package/src/commons/FlatListDnD/__test__/index.test.js +4 -4
- package/src/commons/FlatListDnD/index.js +12 -9
- package/src/commons/Grid/GridItem.js +10 -2
- package/src/commons/GroupCheckBox/__test__/GroupCheckBox.test.js +3 -3
- package/src/commons/Header/HeaderCustom.js +2 -2
- package/src/commons/Header/__test__/HeaderCT.test.js +3 -3
- package/src/commons/HeaderAni/index.js +2 -2
- package/src/commons/IconComponent/index.js +3 -3
- package/src/commons/ImagePicker/__test__/ImagePicker.test.js +5 -5
- package/src/commons/MediaPlayerDetail/__test__/MediaPlayerDetail.test.js +6 -4
- package/src/commons/MenuActionMore/MenuActionMoreStyles.js +2 -1
- package/src/commons/MenuActionMore/index.js +1 -1
- package/src/commons/NavBar/NavBarStyles.js +1 -1
- package/src/commons/NavBar/index.js +2 -2
- package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +3 -3
- package/src/commons/OneTapTemplate/__test__/StatesGridActionTemplate.test.js +1 -1
- package/src/commons/Popover/__test__/index.test.js +3 -3
- package/src/commons/Processing/__test__/Connecting.test.js +4 -4
- package/src/commons/SearchLocation/index.js +3 -3
- package/src/commons/SelectActionCard/index.js +2 -2
- package/src/commons/SelectSubUnit/index.js +6 -2
- package/src/commons/SelectUnit/__test__/SelectUnit.test.js +5 -5
- package/src/commons/Sharing/BtnRemoveMember.js +2 -2
- package/src/commons/Sharing/StationDevicePermissions.js +2 -2
- package/src/commons/SubUnit/DeviceTemplate/ConfigAndEvaluation/ConfigAndEvaluation.js +2 -2
- package/src/commons/SubUnit/DeviceTemplate/ConfigValue/ConfigValue.js +2 -2
- package/src/commons/SubUnit/DeviceTemplate/EvaluationOverConfig/EvaluationOverConfig.js +2 -2
- package/src/commons/SubUnit/OneTap/ItemOneTap.js +6 -7
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +0 -2
- package/src/commons/SubUnit/OneTap/index.js +9 -8
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +8 -8
- package/src/commons/Unit/HeaderUnit/index.js +30 -22
- package/src/commons/Unit/SharedUnit.js +7 -7
- package/src/commons/Widgets/IFrame/__tests__/IFrame.test.js +9 -13
- package/src/commons/Widgets/IFrameWithConfig/IFrameWithConfig.js +34 -2
- package/src/commons/Widgets/IFrameWithConfig/__tests__/IFrameWithConfig.test.js +88 -8
- package/src/commons/WrapParallaxScrollView/index.js +9 -10
- package/src/configs/API.js +1 -1
- package/src/configs/AccessibilityLabel.js +1 -0
- package/src/configs/Constants.js +3 -3
- package/src/configs/Theme.js +1 -1
- package/src/hooks/Common/__test__/useAndroidTranslucentStatusBar.test.js +5 -5
- package/src/hooks/IoT/__test__/useHomeAssistantConnection.test.js +12 -12
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +14 -7
- package/src/hooks/IoT/__test__/useWatchConfigs.test.js +3 -3
- package/src/hooks/IoT/useRemoteControl.js +24 -13
- package/src/hooks/useMqtt.js +2 -2
- package/src/iot/RemoteControl/Bluetooth.js +19 -22
- package/src/iot/RemoteControl/Internet.js +13 -5
- package/src/iot/RemoteControl/__test__/Internet.test.js +7 -7
- package/src/navigations/EmergencyContactsStack.js +4 -3
- package/src/navigations/SharedStack.js +2 -0
- package/src/navigations/UnitStack.js +56 -57
- package/src/screens/AQIGuide/index.js +0 -2
- package/src/screens/ActivityLog/index.js +2 -2
- package/src/screens/AddLocationMaps/__test__/index.test.js +12 -12
- package/src/screens/AddLocationMaps/index.js +16 -19
- package/src/screens/AddLocationMaps/indexStyle.js +1 -0
- package/src/screens/AddNewGateway/RenameNewDevices.js +2 -2
- package/src/screens/AddNewGateway/SelectDeviceType.js +1 -1
- package/src/screens/AddNewGateway/ShareWifiPassword.js +16 -15
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +7 -7
- package/src/screens/AddNewGateway/__test__/ConnectingWifiDevice.test.js +8 -8
- package/src/screens/AddNewGateway/__test__/ConnectingZigbeeDevice.test.js +7 -7
- package/src/screens/AddNewGateway/__test__/RenameNewDevices.test.js +8 -8
- package/src/screens/AddNewGateway/__test__/ScanGatewayQR.test.js +5 -5
- package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +4 -4
- package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +6 -6
- package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -6
- package/src/screens/AddNewGateway/__test__/ShareWifiPassword.test.js +0 -4
- package/src/screens/AddNewGateway/hooks/__Tests__/useWifiManage.test.js +2 -2
- package/src/screens/AllGateway/DetailConfigActionModbus/__test__/index.test.js +6 -6
- package/src/screens/AllGateway/DeviceInternalDetail/__test__/index.test.js +19 -17
- package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +19 -17
- package/src/screens/AllGateway/DeviceZigbeeDetail/__test__/index.test.js +18 -16
- package/src/screens/AllGateway/GatewayDetail/__test__/index.test.js +43 -35
- package/src/screens/AllGateway/GatewayInfo/__test__/index.test.js +38 -22
- package/src/screens/AllGateway/__test__/index.test.js +6 -6
- package/src/screens/AllGateway/components/Detail/__test__/index.test.js +3 -5
- package/src/screens/AllGateway/components/GatewayItem/__test__/index.test.js +3 -3
- package/src/screens/AllGateway/components/TabPaneCT/__test__/index.test.js +6 -6
- package/src/screens/AllGateway/hooks/__test__/index.test.js +2 -2
- package/src/screens/AllGateway/test-utils.js +3 -4
- package/src/screens/Automate/AddNewAction/ChooseAction.js +17 -3
- package/src/screens/Automate/AddNewAction/ChooseConfig.js +7 -6
- package/src/screens/Automate/AddNewAction/NewActionWrapper.js +8 -8
- package/src/screens/Automate/AddNewAction/SelectControlDevices.js +30 -20
- package/src/screens/Automate/AddNewAction/SelectMonitorDevices.js +17 -10
- package/src/screens/Automate/AddNewAction/SetupConfigCondition.js +58 -44
- package/src/screens/Automate/AddNewAction/SetupScriptDelay.js +1 -1
- package/src/screens/Automate/AddNewAction/SetupScriptNotify.js +3 -3
- package/src/screens/Automate/AddNewAction/Styles/SetupSensorStyles.js +20 -4
- package/src/screens/Automate/AddNewAction/__test__/ChooseAction.test.js +12 -12
- package/src/screens/Automate/AddNewAction/__test__/SelectControlDevices.test.js +14 -8
- package/src/screens/Automate/AddNewAction/__test__/SelectMonitorDevices.test.js +13 -7
- package/src/screens/Automate/AddNewAction/__test__/SetupConfigCondition.test.js +54 -15
- package/src/screens/Automate/AddNewAction/__test__/SetupScriptDelay.test.js +9 -9
- package/src/screens/Automate/AddNewAction/__test__/SetupScriptNotify.test.js +39 -10
- package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +10 -10
- package/src/screens/Automate/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +13 -8
- package/src/screens/Automate/Components/InputName.js +10 -7
- package/src/screens/Automate/EditActionsList/__tests__/UpdateActionScript.test.js +8 -8
- package/src/screens/Automate/EditActionsList/__tests__/UpdateDelayScript.test.js +6 -6
- package/src/screens/Automate/EditActionsList/__tests__/UpdateNotifyScript.test.js +7 -7
- package/src/screens/Automate/EditActionsList/index.js +19 -17
- package/src/screens/Automate/MultiUnits.js +19 -22
- package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +18 -8
- package/src/screens/Automate/Scenario/__test__/AddNewOneTap.test.js +15 -7
- package/src/screens/Automate/ScriptDetail/Components/AddActionScript.js +14 -6
- package/src/screens/Automate/ScriptDetail/Components/RenameScript.js +4 -7
- package/src/screens/Automate/ScriptDetail/__test__/index.test.js +42 -17
- package/src/screens/Automate/ScriptDetail/__test__/useStarredScript.test.js +6 -6
- package/src/screens/Automate/ScriptDetail/index.js +51 -40
- package/src/screens/Automate/SetSchedule/__test__/SelectWeekday.test.js +4 -4
- package/src/screens/Automate/SetSchedule/__test__/index.test.js +29 -18
- package/src/screens/Automate/SetSchedule/components/RowItem.js +5 -5
- package/src/screens/Automate/SetSchedule/index.js +8 -7
- package/src/screens/Automate/Styles/indexStyles.js +1 -1
- package/src/screens/Automate/__test__/MultiUnits.test.js +1 -4
- package/src/screens/Automate/__test__/index.test.js +0 -1
- package/src/screens/Automate/index.js +36 -34
- package/src/screens/ChangePosition/__test__/index.test.js +6 -6
- package/src/screens/ChangePosition/index.js +2 -1
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +13 -13
- package/src/screens/Device/EditDevice/index.js +4 -4
- package/src/screens/Device/__test__/BluetoothDevice.test.js +300 -0
- package/src/screens/Device/__test__/detail.test.js +14 -14
- package/src/screens/Device/__test__/mqttDetail.test.js +9 -9
- package/src/screens/Device/components/BluetoothDevice.js +135 -0
- package/src/screens/Device/components/SensorDisplayItem.js +9 -8
- package/src/screens/Device/detail.js +70 -62
- package/src/screens/Device/hooks/useEvaluateValue.js +1 -1
- package/src/screens/Drawer/Drawer.test.js +2 -2
- package/src/screens/Drawer/index.js +3 -3
- package/src/screens/EmergencyContacts/EmergencyContactsList.js +8 -4
- package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +3 -3
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +7 -7
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +8 -8
- package/src/screens/GuestInfo/components/RowGuestInfo.js +2 -2
- package/src/screens/GuestInfo/components/__test__/AccessScheduleSheet.test.js +3 -3
- package/src/screens/GuestInfo/index.js +2 -2
- package/src/screens/HanetCamera/ManageAccess.js +3 -3
- package/src/screens/HanetCamera/MemberInfo.js +2 -2
- package/src/screens/HanetCamera/__test__/Detail.test.js +9 -9
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -10
- package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +2 -2
- package/src/screens/ManageAccess/index.js +3 -3
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +9 -9
- package/src/screens/Notification/__test__/Notification.test.js +9 -9
- package/src/screens/Notification/components/NotificationItem.js +3 -4
- package/src/screens/Notification/index.js +3 -3
- package/src/screens/Notification/styles/NotificationItemStyles.js +0 -1
- package/src/screens/PlayBackCamera/__test__/index.test.js +1 -1
- package/src/screens/ScanChipQR/components/QRScan/__test__/QRScan.test.js +1 -1
- package/src/screens/ScanChipQR/components/QRScan/index.js +3 -3
- package/src/screens/SelectUnit/__test__/index.test.js +8 -8
- package/src/screens/SelectUnit/index.js +4 -4
- package/src/screens/SharedUnit/TabHeader.js +2 -2
- package/src/screens/Sharing/Components/EndDevice.js +3 -3
- package/src/screens/Sharing/UnitMemberList.js +2 -2
- package/src/screens/Sharing/__test__/UpdateShareDevice.test.js +7 -7
- package/src/screens/SideMenuDetail/__test__/index.test.js +8 -8
- package/src/screens/SmartAccount/Connecting/index.js +5 -5
- package/src/screens/SmartAccount/ListDevice/__test__/ListDevice.test.js +8 -8
- package/src/screens/SmartAccount/SuccessfullyConnected/__test__/SuccessfullyConnected.test.js +7 -7
- package/src/screens/SmartAccount/SuccessfullyConnected/index.js +2 -2
- package/src/screens/SmartAccount/__test__/Connecting.test.js +6 -6
- package/src/screens/SmartAccount/__test__/SmartAccount.test.js +10 -10
- package/src/screens/SmartIr/__test__/GroupButtonByType.test.js +3 -2
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +2 -2
- package/src/screens/SmartIr/components/SelectBrand.js +2 -2
- package/src/screens/SubUnit/AddSubUnit.js +28 -26
- package/src/screens/SubUnit/AddSubUnitStyles.js +10 -4
- package/src/screens/SubUnit/EditSubUnit.js +12 -11
- package/src/screens/SubUnit/ManageSubUnit.js +3 -3
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +13 -13
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +3 -3
- package/src/screens/Template/EditTemplate.js +6 -4
- package/src/screens/Template/__test__/EditTemplate.test.js +7 -7
- package/src/screens/Template/__test__/detail.test.js +4 -4
- package/src/screens/Template/__test__/index.test.js +1 -1
- package/src/screens/UVIndexGuide/index.js +2 -4
- package/src/screens/Unit/Detail.js +1 -5
- package/src/screens/Unit/MoreMenu.js +6 -5
- package/src/screens/Unit/SelectAddToFavorites.js +2 -2
- package/src/screens/Unit/SelectAddress.js +16 -12
- package/src/screens/Unit/Station/__test__/index.test.js +1 -1
- package/src/screens/Unit/__test__/MoreMenu.test.js +5 -1
- package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +9 -9
- package/src/screens/Unit/__test__/SelectAddress.test.js +11 -17
- package/src/screens/Unit/__test__/Summaries.test.js +7 -7
- package/src/screens/Unit/components/AutomateScript/index.js +5 -5
- package/src/screens/Unit/components/ButtonWrapper/index.js +3 -3
- package/src/screens/Unit/components/Header/index.js +2 -2
- package/src/screens/Unit/components/SharedUnit/index.js +5 -5
- package/src/screens/Unit/components/__test__/AutomateScript.test.js +3 -3
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +8 -8
- package/src/screens/Unit/hook/__test__/useUnitConnectRemoteDevices.test.js +2 -2
- package/src/screens/UnitSummary/components/AirQuality/index.js +6 -11
- package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +5 -5
- package/src/screens/UnitSummary/index.js +6 -2
- package/src/utils/Apis/axios.js +5 -5
- package/src/utils/Functions/ShortEmail.js +1 -0
- package/src/utils/I18n/translations/en.js +6 -3
- package/src/utils/I18n/translations/vi.js +8 -4
- package/src/utils/__test__/Utils.test.js +16 -16
- package/src/utils/bluetooth.js +3 -0
- package/assets/images/OneTap.svg +0 -14
- package/assets/images/Schedule.svg +0 -39
- package/assets/images/ValueChange.svg +0 -49
|
@@ -2,7 +2,7 @@ import React, { memo, useState, useCallback } from 'react';
|
|
|
2
2
|
import { View, TouchableOpacity } from 'react-native';
|
|
3
3
|
import { useTranslations } from '../../../hooks/Common/useTranslations';
|
|
4
4
|
import { HeaderCustom } from '../../../commons/Header';
|
|
5
|
-
import
|
|
5
|
+
import { IconOutline } from '@ant-design/icons-react-native';
|
|
6
6
|
import { Colors } from '../../../configs';
|
|
7
7
|
import Text from '../../../commons/Text';
|
|
8
8
|
import { useRoute } from '@react-navigation/native';
|
|
@@ -30,7 +30,7 @@ const EditDevice = memo(() => {
|
|
|
30
30
|
useEditDevice();
|
|
31
31
|
const renameSensor = useCallback(async () => {
|
|
32
32
|
const { success, data } = await axiosPatch(
|
|
33
|
-
API.DEVICE.
|
|
33
|
+
API.DEVICE.DEVICE_DETAIL(sensor?.id),
|
|
34
34
|
{
|
|
35
35
|
name: inputName,
|
|
36
36
|
}
|
|
@@ -55,7 +55,7 @@ const EditDevice = memo(() => {
|
|
|
55
55
|
|
|
56
56
|
const deleteSensor = useCallback(async () => {
|
|
57
57
|
hideAlertAction();
|
|
58
|
-
const { success } = await axiosDelete(API.DEVICE.
|
|
58
|
+
const { success } = await axiosDelete(API.DEVICE.DEVICE_DETAIL(sensor?.id));
|
|
59
59
|
|
|
60
60
|
if (success) {
|
|
61
61
|
navigation.pop(2);
|
|
@@ -92,7 +92,7 @@ const EditDevice = memo(() => {
|
|
|
92
92
|
<Text type="Body" Reugular color={Colors.Grey7}>
|
|
93
93
|
{sensorName}
|
|
94
94
|
</Text>
|
|
95
|
-
<
|
|
95
|
+
<IconOutline
|
|
96
96
|
name="right"
|
|
97
97
|
size={18}
|
|
98
98
|
color={Colors.Gray7}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Alert } from 'react-native';
|
|
3
|
+
import { act } from 'react-test-renderer';
|
|
4
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
5
|
+
import { NavigationContext } from '@react-navigation/native';
|
|
6
|
+
|
|
7
|
+
import DeviceDetail from '../detail';
|
|
8
|
+
import { API } from '../../../configs';
|
|
9
|
+
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
10
|
+
import { SCProvider } from '../../../context';
|
|
11
|
+
import { mockSCStore } from '../../../context/mockStore';
|
|
12
|
+
import api from '../../../utils/Apis/axios';
|
|
13
|
+
import { useWatchConfigs } from '../../../hooks/IoT';
|
|
14
|
+
import { render } from '../../../../jest/render';
|
|
15
|
+
import { BleManager } from 'react-native-ble-plx';
|
|
16
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
+
import base64 from 'react-native-base64';
|
|
18
|
+
|
|
19
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
20
|
+
|
|
21
|
+
jest.mock('../../../hooks/IoT', () => {
|
|
22
|
+
return {
|
|
23
|
+
...jest.requireActual('../../../hooks/IoT'),
|
|
24
|
+
useWatchConfigs: jest.fn(),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
jest.mock('../../../hooks/Common', () => {
|
|
29
|
+
return {
|
|
30
|
+
...jest.requireActual('../../../hooks/Common'),
|
|
31
|
+
useHomeAssistantDeviceConnected: () => ({ isConnected: true }),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
let store = mockSCStore({});
|
|
36
|
+
|
|
37
|
+
const navContextValue = {
|
|
38
|
+
isFocused: () => false,
|
|
39
|
+
addListener: jest.fn(() => jest.fn()),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const wrapComponent = (state, account, route) => (
|
|
43
|
+
<SCProvider initState={state}>
|
|
44
|
+
<NavigationContext.Provider
|
|
45
|
+
value={{
|
|
46
|
+
...navContextValue,
|
|
47
|
+
isFocused: () => true,
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<DeviceDetail account={account} route={route} />
|
|
51
|
+
</NavigationContext.Provider>
|
|
52
|
+
</SCProvider>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const mockAlertShow = jest.fn();
|
|
56
|
+
Alert.alert = mockAlertShow;
|
|
57
|
+
|
|
58
|
+
describe('test DeviceDetail', () => {
|
|
59
|
+
let route;
|
|
60
|
+
let account;
|
|
61
|
+
const address = uuidv4();
|
|
62
|
+
const password = uuidv4();
|
|
63
|
+
const device = {
|
|
64
|
+
connect: jest.fn(() => Promise.resolve(device)),
|
|
65
|
+
discoverAllServicesAndCharacteristics: jest.fn(() =>
|
|
66
|
+
Promise.resolve(device)
|
|
67
|
+
),
|
|
68
|
+
writeCharacteristicWithoutResponseForService: jest.fn(),
|
|
69
|
+
writeCharacteristicWithResponseForService: jest.fn(),
|
|
70
|
+
cancelConnection: jest.fn(),
|
|
71
|
+
readCharacteristicForService: jest.fn((service, characteristic) => ({
|
|
72
|
+
value: base64.encode('confirmed'),
|
|
73
|
+
})),
|
|
74
|
+
};
|
|
75
|
+
const bleManager = new BleManager();
|
|
76
|
+
bleManager.startDeviceScan.mockImplementation((uuids, options, handler) =>
|
|
77
|
+
handler(null, device)
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
device.connect.mockClear();
|
|
82
|
+
device.cancelConnection.mockClear();
|
|
83
|
+
device.discoverAllServicesAndCharacteristics.mockClear();
|
|
84
|
+
device.writeCharacteristicWithoutResponseForService.mockClear();
|
|
85
|
+
device.writeCharacteristicWithResponseForService.mockClear();
|
|
86
|
+
device.readCharacteristicForService.mockClear();
|
|
87
|
+
|
|
88
|
+
mock.onGet(API.DEVICE.DEVICE_DETAIL(1)).reply(200, {
|
|
89
|
+
id: 1,
|
|
90
|
+
is_enable_bluetooth: true,
|
|
91
|
+
remote_control_options: {
|
|
92
|
+
bluetooth: {
|
|
93
|
+
address,
|
|
94
|
+
password,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
mock.onGet(API.DEVICE.DISPLAY(1)).reply(200, {
|
|
100
|
+
items: [
|
|
101
|
+
{
|
|
102
|
+
configuration: {
|
|
103
|
+
action1: '2b949045-8e03-4c07-a855-7794ade2e69c',
|
|
104
|
+
action1_data: {
|
|
105
|
+
color: '#00979D',
|
|
106
|
+
command_prefer_over_bluetooth: true,
|
|
107
|
+
command_prefer_over_googlehome: false,
|
|
108
|
+
command_prefer_over_internet: false,
|
|
109
|
+
googlehome_actions: [],
|
|
110
|
+
icon: 'caretup',
|
|
111
|
+
id: 9,
|
|
112
|
+
key: '2b949045-8e03-4c07-a855-7794ade2e69c',
|
|
113
|
+
arduino_action: {
|
|
114
|
+
value: 1,
|
|
115
|
+
pin: {
|
|
116
|
+
pin_number: 2,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
action2: '38347d5e-4418-4ab0-978c-c82f4c034897',
|
|
121
|
+
action2_data: {
|
|
122
|
+
color: '#00979D',
|
|
123
|
+
command_prefer_over_bluetooth: false,
|
|
124
|
+
command_prefer_over_googlehome: false,
|
|
125
|
+
command_prefer_over_internet: true,
|
|
126
|
+
googlehome_actions: [],
|
|
127
|
+
icon: 'stop',
|
|
128
|
+
id: 11,
|
|
129
|
+
key: '38347d5e-4418-4ab0-978c-c82f4c034897',
|
|
130
|
+
},
|
|
131
|
+
action3: 'a492e08c-8cb1-44ee-8ea0-46aaca4e5141',
|
|
132
|
+
action3_data: {
|
|
133
|
+
color: '#00979D',
|
|
134
|
+
command_prefer_over_bluetooth: false,
|
|
135
|
+
command_prefer_over_googlehome: false,
|
|
136
|
+
command_prefer_over_internet: true,
|
|
137
|
+
googlehome_actions: [],
|
|
138
|
+
icon: 'caretdown',
|
|
139
|
+
id: 10,
|
|
140
|
+
key: 'a492e08c-8cb1-44ee-8ea0-46aaca4e5141',
|
|
141
|
+
},
|
|
142
|
+
icon1: 'caretup',
|
|
143
|
+
icon2: 'stop',
|
|
144
|
+
icon3: 'caretdown',
|
|
145
|
+
text1: 'UP',
|
|
146
|
+
text2: 'STOP/UNLOCK',
|
|
147
|
+
text3: 'DOWN',
|
|
148
|
+
},
|
|
149
|
+
id: 19,
|
|
150
|
+
order: 2,
|
|
151
|
+
template: 'three_button_action_template',
|
|
152
|
+
type: 'action',
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
side_menu_items: [{ id: 1, order: 1, name: 'Setup generate passcode' }],
|
|
156
|
+
});
|
|
157
|
+
route = {
|
|
158
|
+
params: {
|
|
159
|
+
unitData: {
|
|
160
|
+
id: 1,
|
|
161
|
+
name: 'Unit name',
|
|
162
|
+
address: '298 Dien Bien Phu',
|
|
163
|
+
remote_control_options: {
|
|
164
|
+
googlehome: [
|
|
165
|
+
{
|
|
166
|
+
config_maps: [],
|
|
167
|
+
auth: {},
|
|
168
|
+
chip_id: 1,
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
station: {
|
|
174
|
+
id: 2,
|
|
175
|
+
name: 'Station name',
|
|
176
|
+
},
|
|
177
|
+
sensorData: {
|
|
178
|
+
id: 1,
|
|
179
|
+
is_managed_by_backend: true,
|
|
180
|
+
station: { id: 2, name: 'Station name' },
|
|
181
|
+
name: 'Sensor name',
|
|
182
|
+
chip_id: 1,
|
|
183
|
+
},
|
|
184
|
+
title: 'Button',
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
account = {
|
|
188
|
+
token: 'abc',
|
|
189
|
+
};
|
|
190
|
+
jest.useFakeTimers();
|
|
191
|
+
|
|
192
|
+
const setState = jest.fn();
|
|
193
|
+
const useLayoutEffectSpy = jest.spyOn(React, 'useLayoutEffect');
|
|
194
|
+
useLayoutEffectSpy.mockImplementation(() => setState);
|
|
195
|
+
useWatchConfigs.mockReset();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('scan bluetooth if available', async () => {
|
|
199
|
+
await render(wrapComponent(store, account, route));
|
|
200
|
+
jest.runAllTimers();
|
|
201
|
+
expect(bleManager.stopDeviceScan).toHaveBeenCalledTimes(2);
|
|
202
|
+
expect(bleManager.startDeviceScan).toHaveBeenCalledTimes(1);
|
|
203
|
+
expect(bleManager.startDeviceScan.mock.calls[0][0]).toEqual([address]);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('connect to first device', async () => {
|
|
207
|
+
await render(wrapComponent(store, account, route));
|
|
208
|
+
jest.runAllTimers();
|
|
209
|
+
expect(bleManager.stopDeviceScan).toHaveBeenCalledTimes(2);
|
|
210
|
+
expect(device.connect).toHaveBeenCalledTimes(1);
|
|
211
|
+
expect(device.discoverAllServicesAndCharacteristics).toHaveBeenCalledTimes(
|
|
212
|
+
1
|
|
213
|
+
);
|
|
214
|
+
expect(
|
|
215
|
+
device.writeCharacteristicWithoutResponseForService
|
|
216
|
+
).toHaveBeenCalledTimes(1);
|
|
217
|
+
expect(
|
|
218
|
+
device.writeCharacteristicWithResponseForService
|
|
219
|
+
).toHaveBeenCalledTimes(1);
|
|
220
|
+
expect(
|
|
221
|
+
base64.decode(
|
|
222
|
+
device.writeCharacteristicWithoutResponseForService.mock.calls[0][2]
|
|
223
|
+
)
|
|
224
|
+
).toEqual('start');
|
|
225
|
+
const confirmMessage =
|
|
226
|
+
device.writeCharacteristicWithResponseForService.mock.calls[0][2];
|
|
227
|
+
expect(base64.decode(confirmMessage).substring(0, 7)).toEqual('confirm');
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('disconnect when leave screen', async () => {
|
|
231
|
+
const { unmount } = await render(wrapComponent(store, account, route));
|
|
232
|
+
jest.runAllTimers();
|
|
233
|
+
await act(async () => {
|
|
234
|
+
unmount();
|
|
235
|
+
});
|
|
236
|
+
expect(device.cancelConnection).toHaveBeenCalledTimes(1);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('fail scan', async () => {
|
|
240
|
+
bleManager.startDeviceScan.mockImplementationOnce(
|
|
241
|
+
(uuids, options, handler) => handler('error', device)
|
|
242
|
+
);
|
|
243
|
+
await render(wrapComponent(store, account, route));
|
|
244
|
+
jest.runAllTimers();
|
|
245
|
+
expect(bleManager.stopDeviceScan).toHaveBeenCalledTimes(1);
|
|
246
|
+
expect(device.connect).toHaveBeenCalledTimes(0);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('control arduino pin device', async () => {
|
|
250
|
+
const { root } = await render(wrapComponent(store, account, route));
|
|
251
|
+
jest.runAllTimers();
|
|
252
|
+
const button = root.findByProps({
|
|
253
|
+
accessibilityLabel: AccessibilityLabel.BUTTON_TEMPLATE_1,
|
|
254
|
+
});
|
|
255
|
+
device.writeCharacteristicWithResponseForService.mockClear();
|
|
256
|
+
device.writeCharacteristicWithoutResponseForService.mockClear();
|
|
257
|
+
await act(async () => {
|
|
258
|
+
await button.props.onPress();
|
|
259
|
+
});
|
|
260
|
+
expect(
|
|
261
|
+
device.writeCharacteristicWithResponseForService
|
|
262
|
+
).toHaveBeenCalledTimes(1);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('control arduino pin fail', async () => {
|
|
266
|
+
device.readCharacteristicForService.mockReturnValue({ value: 'wrong' });
|
|
267
|
+
const { root } = await render(wrapComponent(store, account, route));
|
|
268
|
+
jest.runAllTimers();
|
|
269
|
+
const button = root.findByProps({
|
|
270
|
+
accessibilityLabel: AccessibilityLabel.BUTTON_TEMPLATE_1,
|
|
271
|
+
});
|
|
272
|
+
device.writeCharacteristicWithResponseForService.mockClear();
|
|
273
|
+
device.writeCharacteristicWithoutResponseForService.mockClear();
|
|
274
|
+
await act(async () => {
|
|
275
|
+
await button.props.onPress();
|
|
276
|
+
});
|
|
277
|
+
expect(
|
|
278
|
+
device.writeCharacteristicWithResponseForService
|
|
279
|
+
).toHaveBeenCalledTimes(0);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('control after fail scan', async () => {
|
|
283
|
+
bleManager.startDeviceScan.mockImplementationOnce(
|
|
284
|
+
(uuids, options, handler) => handler('error', device)
|
|
285
|
+
);
|
|
286
|
+
const { root } = await render(wrapComponent(store, account, route));
|
|
287
|
+
jest.runAllTimers();
|
|
288
|
+
const button = root.findByProps({
|
|
289
|
+
accessibilityLabel: AccessibilityLabel.BUTTON_TEMPLATE_1,
|
|
290
|
+
});
|
|
291
|
+
device.writeCharacteristicWithResponseForService.mockClear();
|
|
292
|
+
device.writeCharacteristicWithoutResponseForService.mockClear();
|
|
293
|
+
await act(async () => {
|
|
294
|
+
await button.props.onPress();
|
|
295
|
+
});
|
|
296
|
+
expect(
|
|
297
|
+
device.writeCharacteristicWithResponseForService
|
|
298
|
+
).toHaveBeenCalledTimes(0);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
+
import { NavigationContext, useNavigation } from '@react-navigation/native';
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
1
3
|
import React from 'react';
|
|
2
4
|
import { Alert, ScrollView } from 'react-native';
|
|
3
5
|
import { act, create } from 'react-test-renderer';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import DeviceDetail from '../detail';
|
|
8
|
-
import { API } from '../../../configs';
|
|
6
|
+
import { AlertAction, ButtonPopup, MenuActionMore } from '../../../commons';
|
|
7
|
+
import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
|
|
9
8
|
import { AlertSendConfirm } from '../../../commons/EmergencyButton/AlertSendConfirm';
|
|
10
9
|
import { AlertSent } from '../../../commons/EmergencyButton/AlertSent';
|
|
11
|
-
import { AlertAction, ButtonPopup, MenuActionMore } from '../../../commons';
|
|
12
|
-
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
13
10
|
import Text from '../../../commons/Text';
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import { getTranslate } from '../../../utils/I18n';
|
|
11
|
+
import { API } from '../../../configs';
|
|
12
|
+
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
17
13
|
import { SCProvider } from '../../../context';
|
|
18
14
|
import { mockSCStore } from '../../../context/mockStore';
|
|
19
|
-
import Routes from '../../../utils/Route';
|
|
20
|
-
import api from '../../../utils/Apis/axios';
|
|
21
15
|
import { useWatchConfigs } from '../../../hooks/IoT';
|
|
16
|
+
import api from '../../../utils/Apis/axios';
|
|
17
|
+
import { getTranslate } from '../../../utils/I18n';
|
|
18
|
+
import Routes from '../../../utils/Route';
|
|
19
|
+
import DeviceDetail from '../detail';
|
|
20
|
+
import { IconOutline } from '@ant-design/icons-react-native';
|
|
22
21
|
|
|
23
22
|
const mock = new MockAdapter(api.axiosInstance);
|
|
24
23
|
|
|
@@ -352,7 +351,8 @@ describe('test DeviceDetail', () => {
|
|
|
352
351
|
const buttonPopupIcon = instance.find(
|
|
353
352
|
(el) =>
|
|
354
353
|
el.props.accessibilityLabel ===
|
|
355
|
-
AccessibilityLabel.BUTTON_POPUP_RESOLVED_ICON &&
|
|
354
|
+
AccessibilityLabel.BUTTON_POPUP_RESOLVED_ICON &&
|
|
355
|
+
el.type === IconOutline
|
|
356
356
|
);
|
|
357
357
|
expect(buttonPopupTitle.props.children).toEqual([
|
|
358
358
|
'Unit name',
|
|
@@ -755,7 +755,7 @@ describe('test DeviceDetail', () => {
|
|
|
755
755
|
await act(async () => {
|
|
756
756
|
await create(wrapComponent(store, account, route));
|
|
757
757
|
});
|
|
758
|
-
expect(mockAlertShow).not.
|
|
758
|
+
expect(mockAlertShow).not.toHaveBeenCalled();
|
|
759
759
|
});
|
|
760
760
|
|
|
761
761
|
it('Test fetchUnitDetail', async () => {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
import { NavigationContext } from '@react-navigation/native';
|
|
2
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
3
|
+
import mqtt from 'precompiled-mqtt/dist/mqtt.browser';
|
|
1
4
|
import React from 'react';
|
|
2
5
|
import { Alert } from 'react-native';
|
|
3
6
|
import { act, create } from 'react-test-renderer';
|
|
4
|
-
import MockAdapter from 'axios-mock-adapter';
|
|
5
|
-
import mqtt from 'precompiled-mqtt/dist/mqtt.browser';
|
|
6
|
-
import { NavigationContext } from '@react-navigation/native';
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import QualityIndicatorItem from '../../../commons/Device/WaterQualitySensor/QualityIndicatorsItem';
|
|
9
9
|
import { API } from '../../../configs';
|
|
10
10
|
import { SCProvider } from '../../../context';
|
|
11
11
|
import { mockSCStore } from '../../../context/mockStore';
|
|
12
|
+
import { watchMultiConfigs } from '../../../iot/Monitor';
|
|
13
|
+
import { setConfigGlobalState } from '../../../iot/states';
|
|
12
14
|
import api from '../../../utils/Apis/axios';
|
|
13
15
|
import {
|
|
14
|
-
gatewayDataFactory,
|
|
15
16
|
configDataFactory,
|
|
17
|
+
gatewayDataFactory,
|
|
16
18
|
} from '../../../utils/FactoryGateway';
|
|
17
|
-
import
|
|
18
|
-
import { watchMultiConfigs } from '../../../iot/Monitor';
|
|
19
|
-
import { setConfigGlobalState } from '../../../iot/states';
|
|
19
|
+
import DeviceDetail from '../detail';
|
|
20
20
|
|
|
21
21
|
const mock = new MockAdapter(api.axiosInstance);
|
|
22
22
|
|
|
@@ -194,7 +194,7 @@ describe('test DeviceDetail', () => {
|
|
|
194
194
|
await act(async () => {
|
|
195
195
|
tree.unmount();
|
|
196
196
|
});
|
|
197
|
-
expect(client.end).
|
|
197
|
+
expect(client.end).toHaveBeenCalled();
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
const _receiveDataOnDeviceDetail = async (widgetConfigs, topic, message) => {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
// console log is required for debug, this feature has a lot of debugging
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import base64 from 'react-native-base64';
|
|
5
|
+
import { ScanMode } from 'react-native-ble-plx';
|
|
6
|
+
import md5 from 'md5';
|
|
7
|
+
import { bleManager } from '../../../utils/bluetooth';
|
|
8
|
+
|
|
9
|
+
const CHARACTERISTIC_CONFIRM_CODE_UUID = '6ee26cfb-b42f-43ae-9ecf-f70d84bbd64f';
|
|
10
|
+
const CHARACTERISTIC_CONTROL_UUID = 'f0e7aa38-e466-42af-b4c7-5e6ec5c9a614';
|
|
11
|
+
|
|
12
|
+
export const useBluetoothDevice = (device) => {
|
|
13
|
+
const serviceUuid = device?.remote_control_options?.bluetooth?.address;
|
|
14
|
+
const password = device?.remote_control_options?.bluetooth?.password;
|
|
15
|
+
const deviceRef = useRef(null);
|
|
16
|
+
const [isConnected, setIsConnected] = useState(false);
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
// on unmount, disconnect bluetooth, so it can be reused again
|
|
20
|
+
return () => {
|
|
21
|
+
if (isConnected) {
|
|
22
|
+
deviceRef.current.cancelConnection();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}, [isConnected]);
|
|
26
|
+
|
|
27
|
+
const control = useCallback(
|
|
28
|
+
(action, data) => {
|
|
29
|
+
if (!isConnected) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const value =
|
|
34
|
+
data?.value === undefined ? action.arduino_action.value : data?.value;
|
|
35
|
+
const message = `${action.arduino_action.pin.pin_number};${value}`;
|
|
36
|
+
|
|
37
|
+
console.log('control', message);
|
|
38
|
+
|
|
39
|
+
deviceRef.current.writeCharacteristicWithResponseForService(
|
|
40
|
+
serviceUuid,
|
|
41
|
+
CHARACTERISTIC_CONTROL_UUID,
|
|
42
|
+
base64.encode(message)
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
[isConnected, serviceUuid]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const sendConfirmCode = useCallback(
|
|
49
|
+
async (instanceCode) => {
|
|
50
|
+
console.log(`sendConfirmCode ${instanceCode}`);
|
|
51
|
+
const confirmCode = md5(`${password}${instanceCode}`);
|
|
52
|
+
|
|
53
|
+
await deviceRef.current.writeCharacteristicWithResponseForService(
|
|
54
|
+
serviceUuid,
|
|
55
|
+
CHARACTERISTIC_CONFIRM_CODE_UUID,
|
|
56
|
+
base64.encode('confirm' + confirmCode)
|
|
57
|
+
);
|
|
58
|
+
const result = await deviceRef.current.readCharacteristicForService(
|
|
59
|
+
serviceUuid,
|
|
60
|
+
CHARACTERISTIC_CONFIRM_CODE_UUID
|
|
61
|
+
);
|
|
62
|
+
const resultText = base64.decode(result.value);
|
|
63
|
+
console.log(resultText);
|
|
64
|
+
if (resultText.includes('confirmed')) {
|
|
65
|
+
setIsConnected(true);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
},
|
|
70
|
+
[password, serviceUuid]
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const askInstanceCode = useCallback(async () => {
|
|
74
|
+
console.log('askInstanceCode');
|
|
75
|
+
|
|
76
|
+
await deviceRef.current.writeCharacteristicWithoutResponseForService(
|
|
77
|
+
serviceUuid,
|
|
78
|
+
CHARACTERISTIC_CONFIRM_CODE_UUID,
|
|
79
|
+
base64.encode('start')
|
|
80
|
+
);
|
|
81
|
+
const response = await deviceRef.current.readCharacteristicForService(
|
|
82
|
+
serviceUuid,
|
|
83
|
+
CHARACTERISTIC_CONFIRM_CODE_UUID
|
|
84
|
+
);
|
|
85
|
+
return base64.decode(response.value);
|
|
86
|
+
}, [serviceUuid]);
|
|
87
|
+
|
|
88
|
+
const realConnect = useCallback(async () => {
|
|
89
|
+
// return await new Promise((resolve) => {
|
|
90
|
+
if (!serviceUuid || !password) {
|
|
91
|
+
console.log('Bluetooth is not enabled for this device');
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
console.log('start real connect');
|
|
95
|
+
try {
|
|
96
|
+
bleManager.stopDeviceScan();
|
|
97
|
+
} catch (e) {
|
|
98
|
+
/* istanbul ignore next */
|
|
99
|
+
console.log('Failed to stop scan');
|
|
100
|
+
}
|
|
101
|
+
bleManager.startDeviceScan(
|
|
102
|
+
[serviceUuid],
|
|
103
|
+
{ scanMode: ScanMode?.LowLatency },
|
|
104
|
+
// eslint-disable-next-line promise/prefer-await-to-callbacks
|
|
105
|
+
async (error, bleDevice) => {
|
|
106
|
+
if (error) {
|
|
107
|
+
console.log(error);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
console.log(bleDevice?.name, bleDevice?.localName);
|
|
111
|
+
|
|
112
|
+
console.log('bleManager.stopDeviceScan');
|
|
113
|
+
bleManager.stopDeviceScan();
|
|
114
|
+
console.log('device.connect');
|
|
115
|
+
const connectedDevice = await bleDevice.connect({ timeout: 5000 });
|
|
116
|
+
|
|
117
|
+
console.log('device.discoverAllServicesAndCharacteristics');
|
|
118
|
+
const fullInfoDevice =
|
|
119
|
+
await connectedDevice.discoverAllServicesAndCharacteristics();
|
|
120
|
+
console.log('device.publicCodeCharacteristic');
|
|
121
|
+
deviceRef.current = fullInfoDevice;
|
|
122
|
+
|
|
123
|
+
const instanceCode = await askInstanceCode();
|
|
124
|
+
return await sendConfirmCode(instanceCode);
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
// });
|
|
128
|
+
}, [askInstanceCode, password, sendConfirmCode, serviceUuid]);
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
realConnect();
|
|
132
|
+
}, [realConnect]);
|
|
133
|
+
|
|
134
|
+
return { control, isConnected };
|
|
135
|
+
};
|
|
@@ -13,19 +13,19 @@ import ListQualityIndicator from '../../../commons/Device/WaterQualitySensor/Lis
|
|
|
13
13
|
import Compass from '../../../commons/Device/WindDirection/Compass';
|
|
14
14
|
import Anemometer from '../../../commons/Device/WindSpeed/Anemometer';
|
|
15
15
|
import MediaPlayerDetail from '../../../commons/MediaPlayerDetail';
|
|
16
|
+
import IFrame from '../../../commons/Widgets/IFrame/IFrame';
|
|
17
|
+
import IFrameWithConfig from '../../../commons/Widgets/IFrameWithConfig/IFrameWithConfig';
|
|
18
|
+
import { Device } from '../../../configs';
|
|
16
19
|
import { AccessibilityLabel, WIDGET_TYPE } from '../../../configs/Constants';
|
|
17
20
|
import { useSCContextSelector } from '../../../context';
|
|
18
21
|
import { useRemoteControl } from '../../../hooks/IoT';
|
|
19
22
|
import { useConfigGlobalState } from '../../../iot/states';
|
|
20
23
|
import SmartIr from '../../../screens/SmartIr';
|
|
24
|
+
import { standardizeCameraScreenSize } from '../../../utils/Utils';
|
|
21
25
|
import { useEvaluateValue } from '../hooks/useEvaluateValue';
|
|
22
26
|
import styles from '../styles';
|
|
23
|
-
import VisualChart from './VisualChart';
|
|
24
|
-
import { standardizeCameraScreenSize } from '../../../utils/Utils';
|
|
25
|
-
import { Device } from '../../../configs';
|
|
26
27
|
import DonutCharts from './DonutChart';
|
|
27
|
-
import
|
|
28
|
-
import IFrameWithConfig from '../../../commons/Widgets/IFrameWithConfig/IFrameWithConfig';
|
|
28
|
+
import VisualChart from './VisualChart';
|
|
29
29
|
|
|
30
30
|
const { standardizeWidth, standardizeHeight } = standardizeCameraScreenSize(
|
|
31
31
|
Device.screenWidth - 32
|
|
@@ -33,6 +33,7 @@ const { standardizeWidth, standardizeHeight } = standardizeCameraScreenSize(
|
|
|
33
33
|
export const SensorDisplayItem = ({
|
|
34
34
|
item = {},
|
|
35
35
|
sensor,
|
|
36
|
+
bluetoothDevice,
|
|
36
37
|
emergency,
|
|
37
38
|
offsetTitle,
|
|
38
39
|
setOffsetTitle,
|
|
@@ -46,7 +47,7 @@ export const SensorDisplayItem = ({
|
|
|
46
47
|
const { type, template, uri, id, name, title, value_evaluation } =
|
|
47
48
|
configuration;
|
|
48
49
|
|
|
49
|
-
const sendRemoteCommand = useRemoteControl();
|
|
50
|
+
const sendRemoteCommand = useRemoteControl(bluetoothDevice);
|
|
50
51
|
const [processing, setProcessing] = useState(false);
|
|
51
52
|
// eslint-disable-next-line no-unused-vars
|
|
52
53
|
const [configValues, setConfigValues] = useConfigGlobalState('configValues');
|
|
@@ -114,12 +115,12 @@ export const SensorDisplayItem = ({
|
|
|
114
115
|
}, [configValues, evaluate, evaluateValue, configuration, value_evaluation]);
|
|
115
116
|
|
|
116
117
|
const doAction = useCallback(
|
|
117
|
-
async (action, data, interrupted = false) => {
|
|
118
|
+
async (action, data, interrupted = false, silent = false) => {
|
|
118
119
|
if (processing && !interrupted) {
|
|
119
120
|
return;
|
|
120
121
|
}
|
|
121
122
|
setProcessing(true);
|
|
122
|
-
await sendRemoteCommand(sensor, action, data, userId);
|
|
123
|
+
await sendRemoteCommand(sensor, action, data, userId, silent);
|
|
123
124
|
setProcessing(false);
|
|
124
125
|
},
|
|
125
126
|
[processing, sendRemoteCommand, sensor, userId]
|