@eohjsc/react-native-smart-city 0.3.76 → 0.3.77
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
CHANGED
|
@@ -6,89 +6,93 @@ import { useRemoteControl } from '../../hooks/IoT';
|
|
|
6
6
|
import { useConfigGlobalState } from '../../iot/states';
|
|
7
7
|
import IconComponent from '../IconComponent';
|
|
8
8
|
|
|
9
|
-
const ItemQuickAction = memo(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const ItemQuickAction = memo(
|
|
10
|
+
({ sensor, wrapperStyle, setStatus, iconSize = 40 }) => {
|
|
11
|
+
const [isSendingCommand, setIsSendingCommand] = useState(false);
|
|
12
|
+
const [action, setAction] = useState(sensor.action);
|
|
13
|
+
// eslint-disable-next-line no-unused-vars
|
|
14
|
+
const [configValues, _] = useConfigGlobalState('configValues');
|
|
15
|
+
const [isOn, setIsOn] = useState(false);
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const sendRemoteCommand = useRemoteControl();
|
|
18
|
+
const [processing, setProcessing] = useState(false);
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (!sensor.quick_action) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!(sensor.quick_action?.config_id in configValues)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const configValue = configValues[sensor.quick_action.config_id];
|
|
25
|
+
setIsOn(configValue?.value);
|
|
26
|
+
}, [sensor, configValues]);
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
setAction(sensor.quick_action.on_action);
|
|
37
|
-
setStatus && setStatus(sensor.quick_action.off_status);
|
|
38
|
-
}
|
|
39
|
-
}, [isOn, setStatus, sensor.quick_action]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!sensor.quick_action) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
setProcessing(true);
|
|
47
|
-
let data = null;
|
|
48
|
-
if (
|
|
49
|
-
action?.allow_config_store_value_id === sensor?.quick_action?.config_id
|
|
50
|
-
) {
|
|
51
|
-
if (action?.name?.toLowerCase().includes('off')) {
|
|
52
|
-
data = {
|
|
53
|
-
config_id: action?.allow_config_store_value_id,
|
|
54
|
-
config_value: 0,
|
|
55
|
-
};
|
|
33
|
+
if (isOn) {
|
|
34
|
+
setAction(sensor.quick_action.off_action);
|
|
35
|
+
setStatus && setStatus(sensor.quick_action.on_status);
|
|
56
36
|
} else {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
config_value: 1,
|
|
60
|
-
};
|
|
37
|
+
setAction(sensor.quick_action.on_action);
|
|
38
|
+
setStatus && setStatus(sensor.quick_action.off_status);
|
|
61
39
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
40
|
+
}, [isOn, setStatus, sensor.quick_action]);
|
|
41
|
+
|
|
42
|
+
const userId = useSCContextSelector((state) => state?.auth.account.user.id);
|
|
43
|
+
const onActionPress = useCallback(async () => {
|
|
44
|
+
if (processing) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
setProcessing(true);
|
|
48
|
+
let data = null;
|
|
49
|
+
if (
|
|
50
|
+
action?.allow_config_store_value_id === sensor?.quick_action?.config_id
|
|
51
|
+
) {
|
|
52
|
+
if (action?.name?.toLowerCase().includes('off')) {
|
|
53
|
+
data = {
|
|
54
|
+
config_id: action?.allow_config_store_value_id,
|
|
55
|
+
config_value: 0,
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
data = {
|
|
59
|
+
config_id: action?.allow_config_store_value_id,
|
|
60
|
+
config_value: 1,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
data = JSON.stringify(data);
|
|
64
|
+
}
|
|
65
|
+
await sendRemoteCommand(sensor, action, data, userId);
|
|
66
|
+
setIsSendingCommand(true);
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
if (!sensor.quick_action.will_auto_update_status) {
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
setIsOn(action.id === sensor.quick_action.on_action.id);
|
|
71
|
+
}, sensor.quick_action.interval);
|
|
72
|
+
}
|
|
73
|
+
setProcessing(false);
|
|
74
|
+
}, [processing, action, sensor, sendRemoteCommand, userId]);
|
|
75
|
+
|
|
76
|
+
if (!action) {
|
|
77
|
+
return <View />;
|
|
71
78
|
}
|
|
72
|
-
setProcessing(false);
|
|
73
|
-
}, [processing, action, sensor, sendRemoteCommand, userId]);
|
|
74
79
|
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
return (
|
|
81
|
+
<TouchableOpacity
|
|
82
|
+
accessibilityLabel={`${AccessibilityLabel.ITEM_QUICK_ACTION_PRESS}-${sensor?.id}`}
|
|
83
|
+
onPress={onActionPress}
|
|
84
|
+
>
|
|
85
|
+
<View style={wrapperStyle}>
|
|
86
|
+
<IconComponent
|
|
87
|
+
icon={action?.icon_kit || action?.icon || 'PoweroffOutlined'}
|
|
88
|
+
isSendingCommand={isSendingCommand}
|
|
89
|
+
iconSize={iconSize}
|
|
90
|
+
size={iconSize}
|
|
91
|
+
/>
|
|
92
|
+
</View>
|
|
93
|
+
</TouchableOpacity>
|
|
94
|
+
);
|
|
77
95
|
}
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
<TouchableOpacity
|
|
81
|
-
accessibilityLabel={`${AccessibilityLabel.ITEM_QUICK_ACTION_PRESS}-${sensor?.id}`}
|
|
82
|
-
onPress={onActionPress}
|
|
83
|
-
>
|
|
84
|
-
<View style={wrapperStyle}>
|
|
85
|
-
<IconComponent
|
|
86
|
-
icon={action?.icon_kit || action?.icon || 'PoweroffOutlined'}
|
|
87
|
-
isSendingCommand={isSendingCommand}
|
|
88
|
-
/>
|
|
89
|
-
</View>
|
|
90
|
-
</TouchableOpacity>
|
|
91
|
-
);
|
|
92
|
-
});
|
|
96
|
+
);
|
|
93
97
|
|
|
94
98
|
export default ItemQuickAction;
|
|
@@ -25,7 +25,13 @@ const AddSubUnit = ({ route }) => {
|
|
|
25
25
|
const t = useTranslations();
|
|
26
26
|
const { dismissKeyboard } = useKeyboardShow();
|
|
27
27
|
const { navigate, goBack, dispatch } = useNavigation();
|
|
28
|
-
const {
|
|
28
|
+
const {
|
|
29
|
+
unit,
|
|
30
|
+
addType,
|
|
31
|
+
isAddUnit,
|
|
32
|
+
location = '',
|
|
33
|
+
isInsideUnit,
|
|
34
|
+
} = route?.params;
|
|
29
35
|
const [roomName, setRoomName] = useState('');
|
|
30
36
|
const [wallpaper, setWallpaper] = useState('');
|
|
31
37
|
const [imageUrl, setImageUrl] = useState('');
|
|
@@ -94,18 +100,25 @@ const AddSubUnit = ({ route }) => {
|
|
|
94
100
|
});
|
|
95
101
|
return;
|
|
96
102
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
})
|
|
108
|
-
|
|
103
|
+
const commonPrams = {
|
|
104
|
+
unitId: unit.id,
|
|
105
|
+
unitData: unit,
|
|
106
|
+
stationId: data.id,
|
|
107
|
+
isAddSubUnit: true,
|
|
108
|
+
routeName: Routes.DashboardStack,
|
|
109
|
+
};
|
|
110
|
+
if (isInsideUnit) {
|
|
111
|
+
navigate(Routes.UnitDetail, {
|
|
112
|
+
params: commonPrams,
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
dispatch(
|
|
116
|
+
replace(Routes.UnitStack, {
|
|
117
|
+
screen: Routes.UnitDetail,
|
|
118
|
+
params: commonPrams,
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
}
|
|
109
122
|
cleanData();
|
|
110
123
|
} else {
|
|
111
124
|
awaitCreate.current = false;
|
|
@@ -118,12 +131,13 @@ const AddSubUnit = ({ route }) => {
|
|
|
118
131
|
roomName,
|
|
119
132
|
location,
|
|
120
133
|
wallpaper,
|
|
121
|
-
|
|
134
|
+
dispatch,
|
|
122
135
|
t,
|
|
123
136
|
unit,
|
|
124
137
|
addType,
|
|
125
|
-
|
|
138
|
+
isInsideUnit,
|
|
126
139
|
goBack,
|
|
140
|
+
navigate,
|
|
127
141
|
route.params,
|
|
128
142
|
]);
|
|
129
143
|
|
|
@@ -251,6 +251,48 @@ describe('Test AddSubUnit', () => {
|
|
|
251
251
|
});
|
|
252
252
|
});
|
|
253
253
|
|
|
254
|
+
it('test create sub-unit is in side Unit', async () => {
|
|
255
|
+
route.params = {
|
|
256
|
+
...route.params,
|
|
257
|
+
isInsideUnit: true,
|
|
258
|
+
};
|
|
259
|
+
mock.onPost(API.SUB_UNIT.CREATE_SUB_UNIT(1)).reply(200, {});
|
|
260
|
+
await act(async () => {
|
|
261
|
+
tree = await create(wrapComponent(route));
|
|
262
|
+
});
|
|
263
|
+
const instance = tree.root;
|
|
264
|
+
const viewButtonBottom = await makeValidateData(instance);
|
|
265
|
+
await act(async () => {
|
|
266
|
+
await viewButtonBottom.props.onRightClick();
|
|
267
|
+
});
|
|
268
|
+
expect(mockedNavigate).toHaveBeenCalledWith('UnitDetail', {
|
|
269
|
+
params: {
|
|
270
|
+
isAddSubUnit: true,
|
|
271
|
+
routeName: 'DashboardStack',
|
|
272
|
+
stationId: undefined,
|
|
273
|
+
unitData: { id: 1, name: 'Unit name' },
|
|
274
|
+
unitId: 1,
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('test create sub-unit is out side Unit', async () => {
|
|
280
|
+
route.params = {
|
|
281
|
+
...route.params,
|
|
282
|
+
isInsideUnit: false,
|
|
283
|
+
};
|
|
284
|
+
mock.onPost(API.SUB_UNIT.CREATE_SUB_UNIT(1)).reply(200, {});
|
|
285
|
+
await act(async () => {
|
|
286
|
+
tree = await create(wrapComponent(route));
|
|
287
|
+
});
|
|
288
|
+
const instance = tree.root;
|
|
289
|
+
const viewButtonBottom = await makeValidateData(instance);
|
|
290
|
+
await act(async () => {
|
|
291
|
+
await viewButtonBottom.props.onRightClick();
|
|
292
|
+
});
|
|
293
|
+
expect(mockNavigationDispatch).toBeCalledWith(mockReplace);
|
|
294
|
+
});
|
|
295
|
+
|
|
254
296
|
it('test create sub-unit type AddHassiDevice', async () => {
|
|
255
297
|
route.params = {
|
|
256
298
|
...route.params,
|
|
@@ -28,7 +28,10 @@ const AddMenu = memo(({ unit, afterItemClick, showAdd, setHideAdd }) => {
|
|
|
28
28
|
route: Routes.AddSubUnitStack,
|
|
29
29
|
text: t('sub_unit'),
|
|
30
30
|
image: <AddSubUnitIcon width={43} height={43} />,
|
|
31
|
-
data: {
|
|
31
|
+
data: {
|
|
32
|
+
screen: Routes.AddSubUnit,
|
|
33
|
+
params: { unit, isInsideUnit: true },
|
|
34
|
+
},
|
|
32
35
|
},
|
|
33
36
|
{
|
|
34
37
|
id: 'add_member',
|