Skip to content

Commit 74e98b7

Browse files
author
miot-robot
committed
Merge branch xb-scene-v2 into SDK_10071 refer 3dd6b0ccfa6982077f8d3ed427ab184a7f1482d2
1 parent 11d8af8 commit 74e98b7

File tree

2 files changed

+134
-3
lines changed

2 files changed

+134
-3
lines changed

bin/config/transformer.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

miot-sdk/service/sceneV2.js

+133-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @description 场景2.0相关服务
88
*/
99
import { report } from "../decorator/ReportDecorator";
10+
import { Device, Service } from 'miot';
1011
/**
1112
* @export
1213
*/
@@ -38,14 +39,38 @@ class IMiotSceneV2 {
3839
});
3940
});
4041
}
42+
@report
43+
loadSceneListByTags(tags = [], mode = 0, homeId, deviceId = Device.deviceID) {
44+
return new Promise((resolve, reject) => {
45+
(homeId ? Promise.resolve(homeId) : Device.getRoomInfoForCurrentHome().then((res) => {
46+
if (res?.data?.homeId) {
47+
return Promise.resolve(res.data.homeId);
48+
}
49+
return Promise.reject();
50+
})).then((homeId) => {
51+
native.MIOTRPC.standardCall('/appgateway/miot/appsceneservice/AppSceneService/GetSceneListByTags', {
52+
home_id: homeId,
53+
did: deviceId,
54+
tags,
55+
mode
56+
}, (ok, res) => {
57+
if (ok && res?.scene_info_list) {
58+
resolve(res.scene_info_list);
59+
return;
60+
}
61+
reject(res);
62+
});
63+
}).catch(reject);
64+
});
65+
}
4166
/**
4267
* since 10064
4368
* 获取场景2.0模板创建的场景列表,/app/appgateway/miot/appsceneservice/AppSceneService/GetTplSceneList
4469
* 场景2.0:模板创建的场景列表
4570
* @param {string} homeId 家庭id
4671
* @param {string} deviceId 设备id
4772
* @returns {Promise<array[object]>}
48-
* @example
73+
* @example
4974
* [{
5075
"template_id": "1343905190336802816",
5176
"scene_id": "1462743313128103936",
@@ -182,4 +207,110 @@ const MiotSceneInstanceV2 = new IMiotSceneV2();
182207
/**
183208
* @export
184209
*/
185-
export default MiotSceneInstanceV2;
210+
export default MiotSceneInstanceV2;
211+
export function createAction(payload, config) {
212+
return {
213+
group_id: 0,
214+
id: 0,
215+
type: 0,
216+
name: '',
217+
protocol_type: 2,
218+
from: 5,
219+
payload_json: {
220+
command: 'set_properties',
221+
delay_time: 0,
222+
device_name: Device.name,
223+
did: Device.deviceID,
224+
model: Device.model,
225+
value: '',
226+
...(payload || {})
227+
},
228+
...(config || {})
229+
};
230+
}
231+
export function createActions(actions = [], mode = 0) {
232+
return {
233+
mode,
234+
actions: actions.filter((action) => !!action).map((action, index) => {
235+
return {
236+
order: index + 1,
237+
...action
238+
};
239+
})
240+
};
241+
}
242+
export function createTrigger(trigger) {
243+
return {
244+
id: 0,
245+
src: 'user',
246+
key: 'user.click',
247+
extra: '',
248+
name: '',
249+
value_type: 5,
250+
extra_json: null,
251+
value_json: null,
252+
protocol_type: 2,
253+
...(trigger || {})
254+
};
255+
}
256+
export function createTriggers(triggers = [], express = 0) {
257+
return {
258+
express,
259+
triggers: triggers.filter((trigger) => !!trigger).map((trigger, index) => {
260+
return {
261+
order: index + 1,
262+
...trigger
263+
};
264+
})
265+
};
266+
}
267+
export function createCondition(condition) {
268+
return createTrigger(condition);
269+
}
270+
export function createConditions(conditions, express) {
271+
return createTriggers(conditions, express);
272+
}
273+
export function createTimewindow(config) {
274+
return {
275+
from: '0 0 0 * * * *',
276+
to: '0 0 0 * * * *',
277+
filter: '',
278+
extra: '',
279+
...(config || {})
280+
};
281+
}
282+
export function saveScene(config, timewindow, condition, trigger, action) {
283+
return Device.getRoomInfoForCurrentHome().then((res) => {
284+
const { homeId } = res?.data || {};
285+
if (!homeId) {
286+
return Promise.reject({
287+
msg: 'get homeId fail'
288+
});
289+
}
290+
const scene = {
291+
// scene_id 有,则为修改,否则为新建
292+
// scene_id: undefined,
293+
uid: Service.account.ID,
294+
home_id: homeId,
295+
scene_name: '',
296+
template_id: '0',
297+
edit_from: 1,
298+
common_use: false,
299+
enable: true,
300+
enable_push: false,
301+
// value_json: 1,
302+
value_format: 1,
303+
timewindow: timewindow || createTimewindow(),
304+
scene_condition: condition || createConditions(),
305+
scene_trigger: trigger || createTriggers([createTrigger()]),
306+
scene_action: action || createActions(),
307+
...(config || {})
308+
};
309+
return MiotSceneInstanceV2.editScene(scene).then((res) => {
310+
return {
311+
...scene,
312+
...(res || {})
313+
};
314+
});
315+
});
316+
}

0 commit comments

Comments
 (0)