@eohjsc/react-native-smart-city 0.3.8 → 0.3.11
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/README.md +36 -15
- package/package.json +10 -6
- package/react-native-smart-city.podspec +1 -0
- package/src/commons/Action/ItemQuickAction.js +16 -4
- package/src/commons/Action/__test__/ItemQuickAction.test.js +11 -6
- package/src/commons/ActionGroup/ColorPickerTemplate.js +37 -24
- package/src/commons/ActionGroup/CurtainButtonTemplate.js +10 -5
- package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +4 -0
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/ItemPasscode.js +1 -1
- package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/ItemPasscode.test.js +24 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/__test__/index.test.js +14 -0
- package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/index.js +1 -0
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +8 -2
- package/src/commons/ActionGroup/SliderRangeTemplate.js +6 -2
- package/src/commons/ActionGroup/SmartTiviActionTemplate/SmartTiviActionTemplate.js +7 -3
- package/src/commons/ActionGroup/StatesGridActionTemplate.js +22 -8
- package/src/commons/ActionGroup/TimerActionTemplate.js +11 -3
- package/src/commons/ActionGroup/TwoButtonTemplate/index.js +1 -5
- package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +53 -4
- package/src/commons/ActionGroup/__test__/OnOffButtonTemplate.test.js +14 -14
- package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +53 -78
- package/src/commons/ActionGroup/__test__/OneBigButtonTemplate.test.js +36 -20
- package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +77 -0
- package/src/commons/ActionGroup/__test__/TimerActionTemplate.test.js +58 -6
- package/src/commons/ActionGroup/__test__/TwoButtonTemplate.test.js +49 -1
- package/src/commons/ActionGroup/__test__/index.test.js +135 -0
- package/src/commons/Auth/AccountList.js +1 -1
- package/src/commons/Automate/ItemAutomate.js +1 -3
- package/src/commons/Calendar/__test__/Calendar.test.js +33 -0
- package/src/commons/Connecting/__test__/Connecting.test.js +19 -2
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItem.js +7 -3
- package/src/commons/ConnectingProcess/DeviceItem/DeviceItemStyles.js +8 -11
- package/src/commons/ConnectingProcess/__test__/Connecting.test.js +136 -3
- package/src/commons/ConnectingProcess/__test__/DeviceItem.test.js +3 -2
- package/src/commons/ConnectingProcess/index.js +76 -26
- package/src/commons/Dashboard/MyPinnedSharedUnit/__test__/MyPinnedSharedUnit.test.js +16 -13
- package/src/commons/Dashboard/MyPinnedSharedUnit/index.js +1 -1
- package/src/commons/Dashboard/MyUnit/__test__/MyUnit.test.js +0 -5
- package/src/commons/Device/ConnectedViewHeader.js +1 -1
- package/src/commons/Device/Hanet/ItemHanetDevice.test.js +58 -0
- package/src/commons/Device/HistoryChart.js +7 -3
- package/src/commons/Device/ItemDevice.js +34 -13
- package/src/commons/Device/LinearChart.js +15 -0
- package/src/commons/Device/PMSensor/PMSensorIndicatior.js +16 -12
- package/src/commons/Device/PMSensor/PMSensorIndicatorStyles.js +3 -0
- package/src/commons/Device/SonosSpeaker/index.js +1 -1
- package/src/commons/Device/WaterQualitySensor/ListQualityIndicator.js +1 -0
- package/src/commons/Device/WaterQualitySensor/QualityIndicatorsItem.js +7 -2
- package/src/commons/Explore/__test__/CityItem.test.js +33 -54
- package/src/commons/FieldTemplate/ChooseUserField/ChooseFieldStyles.js +25 -0
- package/src/commons/FieldTemplate/ChooseUserField/ChoosePopup.js +96 -0
- package/src/commons/FieldTemplate/ChooseUserField/ChoosePopupStyles.js +39 -0
- package/src/commons/FieldTemplate/ChooseUserField/__test__/index.test.js +118 -0
- package/src/commons/FieldTemplate/ChooseUserField/index.js +62 -0
- package/src/commons/FieldTemplate/PasscodeField/PasscodeFieldStyles.js +30 -0
- package/src/commons/FieldTemplate/PasscodeField/__test__/index.test.js +90 -0
- package/src/commons/FieldTemplate/PasscodeField/index.js +43 -0
- package/src/commons/FieldTemplate/ScheduleField/ScheduleFieldStyles.js +13 -0
- package/src/commons/FieldTemplate/ScheduleField/__test__/index.test.js +179 -0
- package/src/commons/FieldTemplate/ScheduleField/index.js +176 -0
- package/src/commons/Form/CurrencyInput.js +15 -1
- package/src/commons/Form/TextInputPassword.js +1 -1
- package/src/commons/FullLoading/index.js +2 -1
- package/src/commons/Header/HeaderCustom.js +2 -1
- package/src/commons/HeaderAni/index.js +6 -1
- package/src/commons/HorizontalPicker/index.js +2 -2
- package/src/commons/MediaPlayerDetail/Styles/MediaPlayerDetailStyles.js +0 -6
- package/src/commons/MediaPlayerDetail/index.js +29 -47
- package/src/commons/MenuActionAddnew/index.js +1 -0
- package/src/commons/MenuActionList/index.js +1 -0
- package/src/commons/MenuActionMore/index.js +1 -1
- package/src/commons/PreventAccess/__test__/PreventAccess.test.js +62 -0
- package/src/commons/PreventAccess/index.js +9 -1
- package/src/commons/Sharing/MemberList.js +10 -2
- package/src/commons/Sharing/WrapHeaderScrollable.js +2 -0
- package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +0 -1
- package/src/commons/SubUnit/Favorites/index.js +6 -3
- package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +8 -35
- package/src/commons/SubUnit/OneTap/index.js +1 -2
- package/src/commons/SubUnit/ShortDetail.js +25 -9
- package/src/commons/SubUnit/__test__/Item.test.js +0 -1
- package/src/commons/SubUnit/__test__/ShortDetail.test.js +9 -2
- package/src/commons/Unit/SharedUnit.js +1 -0
- package/src/commons/Unit/__test__/SharedUnit.test.js +38 -183
- package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +28 -1
- package/src/commons/UnitSummary/ConfigHistoryChart/index.js +2 -13
- package/src/commons/UnitSummary/ConfigHistoryChart.js +55 -13
- package/src/commons/WheelDateTimePicker/index.js +4 -3
- package/src/configs/API.js +91 -143
- package/src/configs/Constants.js +80 -1
- package/src/configs/SCConfig.js +4 -0
- package/src/context/actionType.ts +14 -2
- package/src/context/mockStore.ts +26 -0
- package/src/context/reducer.ts +84 -5
- package/src/hooks/Common/index.js +2 -0
- package/src/hooks/Common/useGGHomeDeviceConnected.js +16 -0
- package/src/hooks/Common/useGetIdUser.js +1 -5
- package/src/hooks/Common/useSensorsStatus.js +4 -4
- package/src/hooks/IoT/__test__/useGGHomeConnection.test.js +199 -0
- package/src/hooks/IoT/__test__/useRemoteControl.test.js +198 -0
- package/src/hooks/IoT/__test__/useValueEvaluation.test.js +58 -0
- package/src/hooks/IoT/index.js +5 -0
- package/src/hooks/IoT/useGGHomeConnection.js +93 -0
- package/src/hooks/IoT/useRemoteControl.js +79 -0
- package/src/hooks/IoT/useValueEvaluation.js +45 -0
- package/src/hooks/index.js +4 -0
- package/src/hooks/useReceiveNotifications.js +12 -7
- package/src/iot/Monitor.js +3 -2
- package/src/iot/RemoteControl/Bluetooth.js +1 -1
- package/src/iot/RemoteControl/GoogleHome.js +75 -49
- package/src/iot/RemoteControl/Internet.js +1 -1
- package/src/iot/RemoteControl/__test__/GoogleHome.test.js +95 -48
- package/src/iot/RemoteControl/__test__/Internet.test.js +18 -7
- package/src/iot/RemoteControl/__test__/LgThinq.test.js +36 -177
- package/src/iot/RemoteControl/index.js +52 -52
- package/src/navigations/UnitStack.js +19 -20
- package/src/navigations/UnitStackStyles.js +21 -0
- package/src/screens/AQIGuide/index.js +1 -1
- package/src/screens/ActivityLog/FilterPopup.js +2 -0
- package/src/screens/ActivityLog/__test__/index.test.js +38 -23
- package/src/screens/ActivityLog/hooks/__test__/index.test.js +51 -90
- package/src/screens/ActivityLog/hooks/index.js +1 -1
- package/src/screens/ActivityLog/index.js +2 -2
- package/src/screens/AddCommon/SelectSubUnit.js +1 -0
- package/src/screens/AddCommon/SelectUnit.js +1 -0
- package/src/screens/AddCommon/__test__/SelectSubUnit.test.js +13 -24
- package/src/screens/AddCommon/__test__/SelectUnit.test.js +9 -33
- package/src/screens/AddLocationMaps/__test__/index.test.js +265 -0
- package/src/screens/AddLocationMaps/index.js +48 -21
- package/src/screens/AddNewAction/SelectAction.js +33 -13
- package/src/screens/AddNewAction/SelectSensorDevices.js +8 -2
- package/src/screens/AddNewAction/SetupSensor.js +68 -32
- package/src/screens/AddNewAction/__test__/SelectAction.test.js +10 -91
- package/src/screens/AddNewAction/__test__/SelectSensorDevices.test.js +40 -26
- package/src/screens/AddNewAction/__test__/SetupSensor.test.js +2 -0
- package/src/screens/AddNewAutoSmart/__test__/AddNewAutoSmart.test.js +3 -1
- package/src/screens/AddNewAutoSmart/index.js +5 -2
- package/src/screens/AddNewDevice/ConnectingDevices.js +3 -3
- package/src/screens/AddNewDevice/__test__/AddNewDevice.test.js +42 -34
- package/src/screens/AddNewDevice/__test__/ConnectDevices.test.js +0 -4
- package/src/screens/AddNewDevice/__test__/ConnectingDevices.test.js +22 -22
- package/src/screens/AddNewDevice/hooks/ConnectDevices.js +1 -1
- package/src/screens/AddNewDevice/index.js +1 -0
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +23 -17
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +46 -40
- package/src/screens/AddNewGateway/PlugAndPlay/__test__/GatewayWifiList.test.js +64 -10
- package/src/screens/AddNewGateway/SelectGateway.js +1 -0
- package/src/screens/AddNewGateway/SetupGatewayWifi.js +2 -0
- package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +4 -6
- package/src/screens/AddNewGateway/__test__/ConnectedGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/ConnectingGateway.test.js +5 -29
- package/src/screens/AddNewGateway/__test__/SelectGateway.test.js +0 -4
- package/src/screens/AddNewGateway/__test__/SetupGateway.test.js +0 -4
- package/src/screens/AddNewGateway/index.js +1 -0
- package/src/screens/AddNewOneTap/__test__/AddNewOneTap.test.js +10 -24
- package/src/screens/AddNewOneTap/index.js +3 -2
- package/src/screens/AllCamera/index.js +4 -4
- package/src/screens/Automate/MultiUnits.js +8 -8
- package/src/screens/Automate/__test__/MultiUnits.test.js +6 -9
- package/src/screens/Automate/__test__/index.test.js +7 -12
- package/src/screens/Automate/index.js +5 -3
- package/src/screens/ConfirmUnitDeletion/__test__/ConfirmUnitDeletion.test.js +36 -8
- package/src/screens/ConfirmUnitDeletion/index.js +7 -1
- package/src/screens/Device/EditDevice/__test__/EditDevice.test.js +71 -22
- package/src/screens/Device/EditDevice/index.js +17 -15
- package/src/screens/Device/__test__/detail.test.js +33 -86
- package/src/screens/Device/components/DetailHistoryChart.js +1 -1
- package/src/screens/Device/components/SensorConnectStatusViewHeader.js +44 -24
- package/src/screens/Device/components/SensorDisplayItem.js +5 -2
- package/src/screens/Device/detail.js +101 -51
- package/src/screens/Device/hooks/useDisconnectedDevice.js +4 -4
- package/src/screens/Device/hooks/useEvaluateValue.js +97 -0
- package/src/screens/Device/hooks/useFavoriteDevice.js +7 -11
- package/src/screens/DeviceInfo/__test__/index.test.js +0 -2
- package/src/screens/EditActionsList/index.js +1 -1
- package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +6 -3
- package/src/screens/EmergencyContacts/__test__/EmergencyContactAddNew.test.js +7 -19
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +20 -2
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +40 -23
- package/src/screens/EmergencySetting/components/DropDownItem.js +2 -2
- package/src/screens/EmergencySetting/index.js +4 -1
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +41 -25
- package/src/screens/Explore/index.js +2 -0
- package/src/screens/GuestInfo/__test__/index.test.js +14 -41
- package/src/screens/GuestInfo/components/RecurringDetail.js +1 -0
- package/src/screens/GuestInfo/components/TemporaryDetail.js +2 -2
- package/src/screens/HanetCamera/Detail.js +1 -1
- package/src/screens/HanetCamera/__test__/CaptureFaceID.test.js +8 -12
- package/src/screens/HanetCamera/__test__/Detail.test.js +27 -42
- package/src/screens/HanetCamera/__test__/ManageAccess.test.js +8 -5
- package/src/screens/HanetCamera/__test__/MemberInfo.test.js +10 -32
- package/src/screens/HanetCamera/components/RequestFaceIDPopup.js +3 -2
- package/src/screens/HanetCamera/hooks/__test__/useHanetCheckinData.test.js +43 -35
- package/src/screens/HanetCamera/hooks/__test__/useHanetPlaceMembers.test.js +10 -21
- package/src/screens/HanetCamera/hooks/useHanetCheckinData.js +11 -11
- package/src/screens/HanetCamera/hooks/useHanetPlaceMembers.js +11 -11
- package/src/screens/ManageAccess/__test__/ManageAccess.test.js +33 -22
- package/src/screens/ManageAccess/hooks/__test__/useManageAccess.test.js +44 -45
- package/src/screens/ManageAccess/hooks/index.js +7 -4
- package/src/screens/ManageAccess/index.js +2 -1
- package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +35 -12
- package/src/screens/MoveToAnotherSubUnit/index.js +6 -6
- package/src/screens/Notification/__test__/Notification.test.js +31 -25
- package/src/screens/Notification/__test__/NotificationItem.test.js +8 -7
- package/src/screens/Notification/components/NotificationItem.js +17 -20
- package/src/screens/Notification/index.js +13 -2
- package/src/screens/PlayBackCamera/Timer.js +2 -2
- package/src/screens/PlayBackCamera/__test__/index.test.js +87 -2
- package/src/screens/PlayBackCamera/index.js +54 -35
- package/src/screens/ScanChipQR/__test__/ScanChipQR.test.js +7 -20
- package/src/screens/ScanChipQR/components/QRScan/index.js +1 -0
- package/src/screens/ScanChipQR/hooks/index.js +15 -16
- package/src/screens/ScanSensorQR/__test__/ScanSensorQR.test.js +8 -24
- package/src/screens/ScriptDetail/__test__/index.test.js +17 -86
- package/src/screens/ScriptDetail/index.js +30 -15
- package/src/screens/SelectUnit/__test__/index.test.js +12 -55
- package/src/screens/SelectUnit/index.js +9 -4
- package/src/screens/SetSchedule/index.js +15 -11
- package/src/screens/SharedUnit/__test__/TabHeader.test.js +0 -2
- package/src/screens/SharedUnit/index.js +2 -0
- package/src/screens/Sharing/Components/SensorItem.js +10 -12
- package/src/screens/Sharing/InfoMemberUnit.js +1 -1
- package/src/screens/Sharing/MemberList.js +12 -11
- package/src/screens/Sharing/SelectPermission.js +136 -83
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +47 -29
- package/src/screens/Sharing/__test__/MemberList.test.js +13 -127
- package/src/screens/Sharing/__test__/MemberList2.test.js +80 -0
- package/src/screens/Sharing/__test__/SelectPermission.test.js +28 -38
- package/src/screens/Sharing/__test__/SelectUser.test.js +17 -38
- package/src/screens/Sharing/hooks/index.js +3 -0
- package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +28 -0
- package/src/screens/SideMenuDetail/__test__/index.test.js +154 -0
- package/src/screens/SideMenuDetail/index.js +148 -0
- package/src/screens/SmartIr/components/GroupButtonByType/GroupButtonByType.js +3 -2
- package/src/screens/SmartIr/components/SelectBrand.js +1 -1
- package/src/screens/SubUnit/AddSubUnit.js +23 -17
- package/src/screens/SubUnit/Detail.js +1 -2
- package/src/screens/SubUnit/EditSubUnit.js +15 -13
- package/src/screens/SubUnit/ManageSubUnit.js +13 -7
- package/src/screens/SubUnit/__test__/AddSubUnit.test.js +29 -89
- package/src/screens/SubUnit/__test__/Detail.test.js +31 -8
- package/src/screens/SubUnit/__test__/EditSubUnit.test.js +21 -89
- package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +27 -1
- package/src/screens/SubUnit/hooks/__test__/useManageSubUnit.test.js +48 -45
- package/src/screens/SubUnit/hooks/useManageSubUnit.js +7 -7
- package/src/screens/SyncLGDevice/AddLGDevice.js +1 -0
- package/src/screens/SyncLGDevice/__test__/AddLGDevice.test.js +22 -91
- package/src/screens/TDSGuide/index.js +4 -1
- package/src/screens/UVIndexGuide/index.js +1 -1
- package/src/screens/Unit/ChooseLocation.js +7 -14
- package/src/screens/Unit/Detail.js +37 -75
- package/src/screens/Unit/ManageUnit.js +1 -0
- package/src/screens/Unit/SelectAddress.js +46 -26
- package/src/screens/Unit/SelectDevices.js +158 -0
- package/src/screens/Unit/SelectDevicesStyles.js +40 -0
- package/src/screens/Unit/SmartAccount.js +4 -4
- package/src/screens/Unit/Station/index.js +4 -0
- package/src/screens/Unit/Summaries.js +18 -2
- package/src/screens/Unit/__test__/CheckSendEmail.test.js +24 -29
- package/src/screens/Unit/__test__/ChooseLocation.test.js +27 -14
- package/src/screens/Unit/__test__/Detail.test.js +98 -199
- package/src/screens/Unit/__test__/ManageUnit.test.js +18 -42
- package/src/screens/Unit/__test__/SelectAddress.test.js +249 -50
- package/src/screens/Unit/__test__/SelectDevices.test.js +110 -0
- package/src/screens/Unit/__test__/SmartAccount.test.js +17 -9
- package/src/screens/Unit/__test__/SmartAccountItem.test.js +0 -1
- package/src/screens/Unit/__test__/Summaries.test.js +100 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/MyAllUnit.test.js +36 -0
- package/src/screens/Unit/components/MyAllUnit/__test__/index.test.js +54 -0
- package/src/screens/Unit/components/MyUnitDevice/index.js +4 -4
- package/src/screens/Unit/components/SharedUnit/index.js +1 -0
- package/src/screens/Unit/components/__test__/MyUnitDevice.test.js +2 -2
- package/src/screens/Unit/components/__test__/SharedUnit.test.js +31 -34
- package/src/screens/Unit/hook/useUnitConnectRemoteDevices.js +50 -0
- package/src/screens/Unit/styles.js +8 -0
- package/src/screens/UnitSummary/__test__/index.test.js +91 -30
- package/src/screens/UnitSummary/components/3PPowerConsumption/__test__/3PPowerConsumption.test.js +31 -2
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/__test__/index.test.js +7 -4
- package/src/screens/UnitSummary/components/PowerConsumeHistoryChart/index.js +2 -13
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/ItemPower.test.js +0 -1
- package/src/screens/UnitSummary/components/PowerConsumption/__test__/PowerConsumption.test.js +14 -16
- package/src/screens/UnitSummary/components/RunningDevices/__test__/index.test.js +11 -2
- package/src/screens/UnitSummary/components/RunningDevices/index.js +7 -10
- package/src/screens/UnitSummary/components/Temperature/index.js +4 -4
- package/src/screens/UnitSummary/components/WaterQuality/Item/index.js +10 -2
- package/src/screens/UnitSummary/index.js +15 -1
- package/src/screens/WaterQualityGuide/index.js +1 -1
- package/src/utils/Apis/axios.js +61 -32
- package/src/utils/Converter/time.js +0 -18
- package/src/utils/I18n/translations/en.json +13 -1
- package/src/utils/I18n/translations/vi.json +14 -1
- package/src/utils/Permission/common.js +67 -0
- package/src/utils/Route/index.js +2 -0
- package/src/utils/Setting/Location.js +30 -0
- package/src/utils/Utils.js +12 -7
- package/src/utils/Validation.js +3 -0
- package/src/utils/__test__/Utils.test.js +12 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { useContext, useCallback } from 'react';
|
|
2
|
+
import { SCContext, useSCContextSelector } from '../../context';
|
|
3
|
+
import { Action } from '../../context/actionType';
|
|
4
|
+
import {
|
|
5
|
+
googleHomeConnect,
|
|
6
|
+
googleHomeDisconnect,
|
|
7
|
+
} from '../../iot/RemoteControl/GoogleHome';
|
|
8
|
+
import { axiosPost } from '../../utils/Apis/axios';
|
|
9
|
+
import { API } from '../../configs';
|
|
10
|
+
|
|
11
|
+
const useGGHomeConnection = () => {
|
|
12
|
+
const { setAction } = useContext(SCContext);
|
|
13
|
+
const { connections } = useSCContextSelector((state) => state.iot.googlehome);
|
|
14
|
+
const { listDevice } = useSCContextSelector((state) => state);
|
|
15
|
+
|
|
16
|
+
const onEstablished = useCallback(
|
|
17
|
+
async (newConnections, options) => {
|
|
18
|
+
setAction(Action.SET_GOOGLE_HOME_CONNECTIONS, newConnections);
|
|
19
|
+
|
|
20
|
+
const isConnected = options.some(
|
|
21
|
+
(option) => !!newConnections[option.chip_id]
|
|
22
|
+
);
|
|
23
|
+
let chipId = options[0].chip_id;
|
|
24
|
+
if (!isConnected) {
|
|
25
|
+
setAction(Action.LIST_DEVICE_TYPES, {
|
|
26
|
+
chipId: chipId,
|
|
27
|
+
sentEmail: true,
|
|
28
|
+
});
|
|
29
|
+
await axiosPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL(), {
|
|
30
|
+
chip_id: chipId,
|
|
31
|
+
is_connected: false,
|
|
32
|
+
});
|
|
33
|
+
} else if (isConnected && listDevice[chipId]?.sentEmail) {
|
|
34
|
+
setAction(Action.LIST_DEVICE_TYPES, {
|
|
35
|
+
chipId: chipId,
|
|
36
|
+
sentEmail: false,
|
|
37
|
+
});
|
|
38
|
+
await axiosPost(API.GOOGLE_HOME.CHECK_SEND_EMAIL(), {
|
|
39
|
+
chip_id: chipId,
|
|
40
|
+
is_connected: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[setAction, listDevice]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const onDisconnected = useCallback(
|
|
48
|
+
async (option) => {
|
|
49
|
+
setAction(Action.CHANGE_GOOGLE_HOME_CONN_STATE, { option, data: 0 });
|
|
50
|
+
},
|
|
51
|
+
[setAction]
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const onReconnected = useCallback(
|
|
55
|
+
async (option, connection) => {
|
|
56
|
+
setAction(Action.CHANGE_GOOGLE_HOME_CONN_STATE, {
|
|
57
|
+
option,
|
|
58
|
+
data: connection,
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
[setAction]
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const connectGoogleHome = useCallback(
|
|
65
|
+
async (options) => {
|
|
66
|
+
setAction(Action.CONNECTING_GOOGLE_HOME);
|
|
67
|
+
await googleHomeConnect(
|
|
68
|
+
connections,
|
|
69
|
+
options,
|
|
70
|
+
onEstablished,
|
|
71
|
+
onDisconnected,
|
|
72
|
+
onReconnected
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
[connections, onEstablished, onDisconnected, onReconnected]
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const disconnectGoogleHome = useCallback(
|
|
80
|
+
async (options) => {
|
|
81
|
+
await googleHomeDisconnect(connections, options);
|
|
82
|
+
setAction(Action.SET_GOOGLE_HOME_CONNECTIONS, {});
|
|
83
|
+
},
|
|
84
|
+
[setAction, connections]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
connectGoogleHome,
|
|
89
|
+
disconnectGoogleHome,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export default useGGHomeConnection;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useSCContextSelector } from '../../context';
|
|
3
|
+
import { sendCommandOverGoogleHome } from '../../iot/RemoteControl/GoogleHome';
|
|
4
|
+
import { sendCommandOverInternet } from '../../iot/RemoteControl/Internet';
|
|
5
|
+
import { sendCommandOverLGThinq } from '../../iot/RemoteControl/LG';
|
|
6
|
+
import {
|
|
7
|
+
sendCommandOverBluetooth,
|
|
8
|
+
SEND_COMMAND_OVER_BLUETOOTH_FAIL,
|
|
9
|
+
} from '../../iot/RemoteControl/Bluetooth';
|
|
10
|
+
import { ToastBottomHelper } from '../../utils/Utils';
|
|
11
|
+
import { t } from 'i18n-js';
|
|
12
|
+
|
|
13
|
+
const useRemoteControl = () => {
|
|
14
|
+
const ggHomeConnections = useSCContextSelector(
|
|
15
|
+
(state) => state.iot.googlehome.connections
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const sendRemoteCommand = useCallback(
|
|
19
|
+
async (sensor, action, data, userId, actionName) => {
|
|
20
|
+
// No action, raise not authorized
|
|
21
|
+
let result = false;
|
|
22
|
+
if (!action) {
|
|
23
|
+
ToastBottomHelper.error(
|
|
24
|
+
t('your_account_has_not_been_authorized_to_control')
|
|
25
|
+
);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (action.command_prefer_over_bluetooth) {
|
|
30
|
+
try {
|
|
31
|
+
result = await sendCommandOverBluetooth(sensor, action, data, userId);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if (err === SEND_COMMAND_OVER_BLUETOOTH_FAIL) {
|
|
34
|
+
result = await sendCommandOverInternet(
|
|
35
|
+
sensor,
|
|
36
|
+
action,
|
|
37
|
+
data,
|
|
38
|
+
'bluetooth',
|
|
39
|
+
actionName
|
|
40
|
+
);
|
|
41
|
+
} else {
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
action.command_prefer_over_internet ||
|
|
49
|
+
action.command_prefer_over_bluetooth
|
|
50
|
+
) {
|
|
51
|
+
result = await sendCommandOverInternet(
|
|
52
|
+
sensor,
|
|
53
|
+
action,
|
|
54
|
+
data,
|
|
55
|
+
'internet'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (action.command_prefer_over_googlehome) {
|
|
60
|
+
result = await sendCommandOverGoogleHome(
|
|
61
|
+
ggHomeConnections,
|
|
62
|
+
sensor,
|
|
63
|
+
action,
|
|
64
|
+
data
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (action.command_prefer_over_lg) {
|
|
69
|
+
result = await sendCommandOverLGThinq(sensor, action, data);
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
},
|
|
73
|
+
[ggHomeConnections]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return sendRemoteCommand;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default useRemoteControl;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect } from 'react';
|
|
2
|
+
import { API } from '../../configs';
|
|
3
|
+
import { SCContext, useSCContextSelector } from '../../context';
|
|
4
|
+
import { Action } from '../../context/actionType';
|
|
5
|
+
import { axiosGet } from '../../utils/Apis/axios';
|
|
6
|
+
|
|
7
|
+
const useValueEvaluations = (unitId) => {
|
|
8
|
+
const { setAction } = useContext(SCContext);
|
|
9
|
+
|
|
10
|
+
const fetchConfigValueEvaluations = useCallback(
|
|
11
|
+
async (page = 1) => {
|
|
12
|
+
if (!unitId) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const params = new URLSearchParams();
|
|
16
|
+
params.append('config__end_device__station__unit', unitId);
|
|
17
|
+
params.append('page', page);
|
|
18
|
+
const { success, data } = await axiosGet(API.VALUE_EVALUATIONS(), {
|
|
19
|
+
params,
|
|
20
|
+
});
|
|
21
|
+
if (success) {
|
|
22
|
+
setAction(Action.UPDATE_VALUE_EVALUATIONS, {
|
|
23
|
+
unitId,
|
|
24
|
+
data: data.results,
|
|
25
|
+
});
|
|
26
|
+
if (data.next) {
|
|
27
|
+
await fetchConfigValueEvaluations(page + 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
[unitId, setAction]
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const fetchedValueEvaluationUnits = useSCContextSelector((state) => {
|
|
35
|
+
return state.fetchedValueEvaluationUnits || [];
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!(fetchedValueEvaluationUnits.indexOf(unitId) !== -1)) {
|
|
40
|
+
fetchConfigValueEvaluations();
|
|
41
|
+
}
|
|
42
|
+
}, [unitId, fetchConfigValueEvaluations, fetchedValueEvaluationUnits]);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default useValueEvaluations;
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { useEffect, useState, useCallback } from 'react';
|
|
2
2
|
import OneSignal from 'react-native-onesignal';
|
|
3
3
|
|
|
4
|
-
const useReceiveNotifications = () => {
|
|
4
|
+
const useReceiveNotifications = (callBack) => {
|
|
5
5
|
const [dataNofitication, setDataNofitication] = useState(null);
|
|
6
|
-
const [showEmergencyPopup, setShowEmergencyPopup] = useState(false);
|
|
7
6
|
|
|
8
7
|
const onReceived = useCallback((data) => {
|
|
9
|
-
const { additionalData } = data
|
|
8
|
+
const { additionalData } = data;
|
|
10
9
|
setDataNofitication(additionalData);
|
|
11
|
-
setShowEmergencyPopup(!!additionalData);
|
|
12
10
|
}, []);
|
|
13
11
|
|
|
14
12
|
useEffect(() => {
|
|
15
|
-
OneSignal.
|
|
16
|
-
|
|
13
|
+
OneSignal.setNotificationWillShowInForegroundHandler(
|
|
14
|
+
(notifReceivedEvent) => {
|
|
15
|
+
let notif = notifReceivedEvent.getNotification();
|
|
16
|
+
setTimeout(() => notifReceivedEvent.complete(notif), 0);
|
|
17
|
+
onReceived(notif);
|
|
18
|
+
callBack && callBack();
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
}, [callBack, onReceived]);
|
|
17
22
|
|
|
18
|
-
return { dataNofitication
|
|
23
|
+
return { dataNofitication };
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
export default useReceiveNotifications;
|
package/src/iot/Monitor.js
CHANGED
|
@@ -99,8 +99,9 @@ export const realWatchMultiConfigs = async (configIds) => {
|
|
|
99
99
|
const configValues = getConfigGlobalState('configValues');
|
|
100
100
|
const newConfigValues = { ...configValues, ...data };
|
|
101
101
|
setConfigGlobalState('configValues', newConfigValues);
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
for (const configId in data) {
|
|
103
|
+
watchConfig(configId);
|
|
104
|
+
}
|
|
104
105
|
}
|
|
105
106
|
};
|
|
106
107
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable promise/prefer-await-to-then */
|
|
2
1
|
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
3
2
|
import { BLE } from '../../configs';
|
|
4
3
|
import t from '../../hooks/Common/useTranslations';
|
|
@@ -82,6 +81,7 @@ const realScanBluetoothDevices = () => {
|
|
|
82
81
|
setTimeout(() => {
|
|
83
82
|
try {
|
|
84
83
|
bleManager.stopDeviceScan();
|
|
84
|
+
// eslint-disable-next-line no-empty
|
|
85
85
|
} catch {}
|
|
86
86
|
}, 15000);
|
|
87
87
|
};
|
|
@@ -5,8 +5,6 @@ import { ToastBottomHelper } from '../../utils/Utils';
|
|
|
5
5
|
import { API } from '../../configs';
|
|
6
6
|
import { axiosPost } from '../../utils/Apis/axios';
|
|
7
7
|
|
|
8
|
-
let connections = {};
|
|
9
|
-
|
|
10
8
|
let configMaps = {};
|
|
11
9
|
|
|
12
10
|
let attributeMaps = {};
|
|
@@ -89,14 +87,14 @@ async function fetchConnectionEntities(connection) {
|
|
|
89
87
|
const entity = states[i];
|
|
90
88
|
const entityId = entity.entity_id;
|
|
91
89
|
|
|
92
|
-
if (
|
|
90
|
+
if (Object.prototype.hasOwnProperty.call(configMaps, entityId)) {
|
|
93
91
|
const [configId, type] = configMaps[entityId];
|
|
94
92
|
const typeConverter = valueTypes[type] || keepValue;
|
|
95
93
|
|
|
96
94
|
configValues[configId] = typeConverter(entity.state, entityId);
|
|
97
95
|
}
|
|
98
96
|
|
|
99
|
-
if (
|
|
97
|
+
if (Object.prototype.hasOwnProperty.call(attributeMaps, entityId)) {
|
|
100
98
|
const entityAttributeMaps = attributeMaps[entityId];
|
|
101
99
|
for (const [attributeName, attributeMap] of Object.entries(
|
|
102
100
|
entityAttributeMaps
|
|
@@ -118,14 +116,21 @@ async function fetchConnectionEntities(connection) {
|
|
|
118
116
|
setConfigGlobalState('configValues', { ...configValues });
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
export const googleHomeConnect = async (
|
|
122
|
-
|
|
119
|
+
export const googleHomeConnect = async (
|
|
120
|
+
oldConnections,
|
|
121
|
+
options,
|
|
122
|
+
onEstablished,
|
|
123
|
+
onDisconnected,
|
|
124
|
+
onReconnected
|
|
125
|
+
) => {
|
|
126
|
+
let connections = {};
|
|
127
|
+
|
|
123
128
|
for (let i = 0; i < options.length; i++) {
|
|
124
129
|
const option = options[i];
|
|
125
130
|
|
|
126
|
-
if (option.chip_id in
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
if (option.chip_id in oldConnections && !!oldConnections[option.chip_id]) {
|
|
132
|
+
connections[option.chip_id] = oldConnections[option.chip_id];
|
|
133
|
+
continue;
|
|
129
134
|
}
|
|
130
135
|
connections[option.chip_id] = 0; // connecting
|
|
131
136
|
|
|
@@ -152,43 +157,45 @@ export const googleHomeConnect = async (options) => {
|
|
|
152
157
|
}
|
|
153
158
|
});
|
|
154
159
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
160
|
+
try {
|
|
161
|
+
let auth = new Auth(option.auth);
|
|
162
|
+
const connection = await createConnection({ auth });
|
|
163
|
+
await connection.subscribeEvents(stateChangeCallback, 'state_changed');
|
|
164
|
+
|
|
165
|
+
connection.addEventListener('disconnected', async () => {
|
|
166
|
+
await onDisconnected(option);
|
|
167
|
+
ToastBottomHelper.error(t('command_googlehome_lost'));
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
connection.addEventListener('ready', async (conn, eventData) => {
|
|
171
|
+
await fetchConnectionEntities(conn);
|
|
172
|
+
await onReconnected(option, conn);
|
|
173
|
+
ToastBottomHelper.success(t('command_googlehome_ready'));
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
connections[option.chip_id] = connection;
|
|
177
|
+
await fetchConnectionEntities(connection);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
connections[option.chip_id] = 0;
|
|
180
|
+
}
|
|
173
181
|
}
|
|
174
|
-
|
|
182
|
+
await onEstablished(connections, options);
|
|
183
|
+
return connections;
|
|
175
184
|
};
|
|
176
185
|
|
|
177
|
-
export const googleHomeDisconnect = async (options) => {
|
|
186
|
+
export const googleHomeDisconnect = async (connections, options) => {
|
|
178
187
|
for (let i = 0; i < options.length; i++) {
|
|
179
188
|
const option = options[i];
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
if (option.chip_id in connections) {
|
|
190
|
+
if (connections[option.chip_id]) {
|
|
191
|
+
await connections[option.chip_id].close();
|
|
192
|
+
}
|
|
183
193
|
}
|
|
184
|
-
|
|
185
|
-
await connections[option.chip_id].close();
|
|
186
|
-
delete connections[option.chip_id];
|
|
187
194
|
}
|
|
188
195
|
};
|
|
189
196
|
|
|
190
|
-
function
|
|
191
|
-
return connections[
|
|
197
|
+
function getDeviceConnection(connections, device) {
|
|
198
|
+
return connections[device.chip_id];
|
|
192
199
|
}
|
|
193
200
|
|
|
194
201
|
function getServiceName(message) {
|
|
@@ -209,10 +216,20 @@ async function sendCommandSingleAction(connection, ghAction, data) {
|
|
|
209
216
|
message.service_data[name] = data;
|
|
210
217
|
}
|
|
211
218
|
|
|
212
|
-
|
|
219
|
+
try {
|
|
220
|
+
await connection.sendMessagePromise(message);
|
|
221
|
+
return true;
|
|
222
|
+
} catch (err) {
|
|
223
|
+
ToastBottomHelper.error(t('command_send_fail_googlehome'));
|
|
224
|
+
}
|
|
213
225
|
}
|
|
214
226
|
|
|
215
|
-
export async function sendCommandOverGoogleHome(
|
|
227
|
+
export async function sendCommandOverGoogleHome(
|
|
228
|
+
connections,
|
|
229
|
+
device,
|
|
230
|
+
action,
|
|
231
|
+
data
|
|
232
|
+
) {
|
|
216
233
|
if (
|
|
217
234
|
!(action.googlehome_actions && action.googlehome_actions.length) &&
|
|
218
235
|
!action.googlehome_action
|
|
@@ -220,30 +237,39 @@ export async function sendCommandOverGoogleHome(sensor, action, data) {
|
|
|
220
237
|
return;
|
|
221
238
|
}
|
|
222
239
|
|
|
223
|
-
const connection =
|
|
240
|
+
const connection = getDeviceConnection(connections, device);
|
|
224
241
|
if (!connection) {
|
|
225
242
|
ToastBottomHelper.error(t('command_send_fail_googlehome'));
|
|
226
243
|
return;
|
|
227
244
|
}
|
|
228
245
|
|
|
246
|
+
let triggerSuccess;
|
|
247
|
+
|
|
229
248
|
if (action.googlehome_actions) {
|
|
230
249
|
for (let i = 0; i < action.googlehome_actions.length; i++) {
|
|
231
|
-
await sendCommandSingleAction(
|
|
250
|
+
triggerSuccess = await sendCommandSingleAction(
|
|
232
251
|
connection,
|
|
233
252
|
action.googlehome_actions[i],
|
|
234
253
|
data
|
|
235
254
|
);
|
|
236
255
|
}
|
|
237
256
|
} else if (action.googlehome_action) {
|
|
238
|
-
await sendCommandSingleAction(
|
|
257
|
+
triggerSuccess = await sendCommandSingleAction(
|
|
258
|
+
connection,
|
|
259
|
+
action.googlehome_action,
|
|
260
|
+
data
|
|
261
|
+
);
|
|
239
262
|
}
|
|
240
263
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
264
|
+
if (triggerSuccess) {
|
|
265
|
+
const { success } = await axiosPost(API.DEVICE.ACTIVITY_LOG(), {
|
|
266
|
+
action_id: action.id,
|
|
267
|
+
message: 'Trigger by user action with google home',
|
|
268
|
+
});
|
|
269
|
+
if (success) {
|
|
270
|
+
ToastBottomHelper.success(t('command_send_success_googlehome'));
|
|
271
|
+
}
|
|
272
|
+
return success;
|
|
247
273
|
}
|
|
248
|
-
return
|
|
274
|
+
return false;
|
|
249
275
|
}
|
|
@@ -17,7 +17,7 @@ export const sendCommandOverInternet = async (
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
ToastBottomHelper.success(t('Sending command via internet'));
|
|
20
|
-
const { success } = await axiosPost(API.
|
|
20
|
+
const { success } = await axiosPost(API.DEVICE.TRIGGER_ACTION(sensor.id), {
|
|
21
21
|
key: action.key,
|
|
22
22
|
data,
|
|
23
23
|
source,
|