@tuya-miniapp/ark-extension-virtual-device 1.5.0 → 1.6.0-beta-1
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/dist/worker/index.js +610 -313
- package/package.json +1 -1
package/dist/worker/index.js
CHANGED
|
@@ -213424,7 +213424,7 @@ var require_package = __commonJS({
|
|
|
213424
213424
|
"package.json"(exports, module2) {
|
|
213425
213425
|
module2.exports = {
|
|
213426
213426
|
name: "@tuya-miniapp/ark-extension-virtual-device",
|
|
213427
|
-
version: "1.5.0
|
|
213427
|
+
version: "1.5.0",
|
|
213428
213428
|
license: "MIT",
|
|
213429
213429
|
files: [
|
|
213430
213430
|
"manifest.json",
|
|
@@ -254815,6 +254815,12 @@ var cachedDevices = {};
|
|
|
254815
254815
|
function getCachedDevice() {
|
|
254816
254816
|
return cachedDevices;
|
|
254817
254817
|
}
|
|
254818
|
+
function shouldDispatchSubDeviceEvent(devId, should = void 0) {
|
|
254819
|
+
if (typeof should !== "undefined") {
|
|
254820
|
+
cachedDevices[`sub_${devId}_should`] = should;
|
|
254821
|
+
}
|
|
254822
|
+
return !!cachedDevices[`sub_${devId}_should`];
|
|
254823
|
+
}
|
|
254818
254824
|
var isBase64 = (str) => {
|
|
254819
254825
|
try {
|
|
254820
254826
|
return btoa(atob(str)) == str;
|
|
@@ -254829,146 +254835,152 @@ function isInteger(num) {
|
|
|
254829
254835
|
return /^-?\d+$/.test(num);
|
|
254830
254836
|
}
|
|
254831
254837
|
var getDeviceInfo = async (body) => {
|
|
254832
|
-
|
|
254833
|
-
|
|
254834
|
-
|
|
254835
|
-
|
|
254836
|
-
|
|
254837
|
-
|
|
254838
|
-
|
|
254839
|
-
|
|
254840
|
-
|
|
254841
|
-
|
|
254842
|
-
|
|
254843
|
-
|
|
254844
|
-
|
|
254845
|
-
|
|
254846
|
-
|
|
254847
|
-
|
|
254848
|
-
|
|
254849
|
-
|
|
254850
|
-
});
|
|
254851
|
-
return res;
|
|
254852
|
-
};
|
|
254853
|
-
return new Promise((resolve) => {
|
|
254854
|
-
resolve({
|
|
254855
|
-
result: {
|
|
254856
|
-
schema: JSON.stringify(parseJson()),
|
|
254857
|
-
isOnline: true,
|
|
254858
|
-
isActive: true,
|
|
254859
|
-
uuid: "123",
|
|
254860
|
-
iconUrl: "https://images.tuyacn.com/smart/icon/non-session-user/159049664009d883358de.png",
|
|
254861
|
-
dps: formatDps(parseJson()),
|
|
254862
|
-
name: "\u9762\u677F\u6A21\u677F"
|
|
254863
|
-
},
|
|
254864
|
-
t: 1676878538884,
|
|
254865
|
-
success: true,
|
|
254866
|
-
status: "ok"
|
|
254867
|
-
});
|
|
254868
|
-
});
|
|
254869
|
-
} else if (mode === "group" && isNumeric(body.deviceId)) {
|
|
254870
|
-
if (groupInfoList[body?.deviceId]) {
|
|
254871
|
-
return groupInfoList[body?.deviceId];
|
|
254872
|
-
}
|
|
254873
|
-
const response = await apiRequestByAtop({
|
|
254874
|
-
api: "tuya.m.device.group.get",
|
|
254875
|
-
version: "2.0",
|
|
254876
|
-
params: {
|
|
254877
|
-
id: body?.deviceId
|
|
254878
|
-
}
|
|
254879
|
-
});
|
|
254880
|
-
const { productId } = response?.result || {};
|
|
254881
|
-
if (productId) {
|
|
254882
|
-
const productResponse = await getProductInfo({ productIds: [productId] });
|
|
254883
|
-
if (productResponse.result instanceof Array && productResponse.result.length > 0) {
|
|
254884
|
-
const product = productResponse.result[0];
|
|
254885
|
-
console.log("product>>", product);
|
|
254886
|
-
groupInfoList[body?.deviceId] = {
|
|
254887
|
-
result: {
|
|
254888
|
-
...response?.result,
|
|
254889
|
-
panelConfig: product.panelConfig,
|
|
254890
|
-
categoryCode: product.categoryCode,
|
|
254891
|
-
meshCategory: product.meshCategory,
|
|
254892
|
-
supportGroup: product.supportGroup,
|
|
254893
|
-
schema: product.schemaInfo?.schema,
|
|
254894
|
-
capability: product.capability,
|
|
254895
|
-
supportSGroup: product.supportSGroup,
|
|
254896
|
-
attribute: product.attribute,
|
|
254897
|
-
category: product.category
|
|
254838
|
+
try {
|
|
254839
|
+
const mode = await getDebugMode();
|
|
254840
|
+
if (isInstanceMode2) {
|
|
254841
|
+
let fileContent = await readFile("src/devices/schema.ts");
|
|
254842
|
+
let schemaFile = fileContent.replace(" as const", "").split("export const defaultSchema = ")[1];
|
|
254843
|
+
let parseJson = new Function(`return ${schemaFile}`);
|
|
254844
|
+
const formatDps = (dpSchema) => {
|
|
254845
|
+
let res = {};
|
|
254846
|
+
dpSchema.forEach((item) => {
|
|
254847
|
+
let type = item?.property?.type;
|
|
254848
|
+
if (type === "bool") {
|
|
254849
|
+
res[item.id] = true;
|
|
254850
|
+
} else if (type === "string") {
|
|
254851
|
+
res[item.id] = "";
|
|
254852
|
+
} else if (type === "value") {
|
|
254853
|
+
res[item.id] = item.property.min;
|
|
254854
|
+
} else if (type === "enum") {
|
|
254855
|
+
res[item.id] = item.property?.range[0] || "";
|
|
254898
254856
|
}
|
|
254899
|
-
};
|
|
254857
|
+
});
|
|
254858
|
+
return res;
|
|
254859
|
+
};
|
|
254860
|
+
return new Promise((resolve) => {
|
|
254861
|
+
resolve({
|
|
254862
|
+
result: {
|
|
254863
|
+
schema: JSON.stringify(parseJson()),
|
|
254864
|
+
isOnline: true,
|
|
254865
|
+
isActive: true,
|
|
254866
|
+
uuid: "123",
|
|
254867
|
+
iconUrl: "https://images.tuyacn.com/smart/icon/non-session-user/159049664009d883358de.png",
|
|
254868
|
+
dps: formatDps(parseJson()),
|
|
254869
|
+
name: "\u9762\u677F\u6A21\u677F"
|
|
254870
|
+
},
|
|
254871
|
+
t: 1676878538884,
|
|
254872
|
+
success: true,
|
|
254873
|
+
status: "ok"
|
|
254874
|
+
});
|
|
254875
|
+
});
|
|
254876
|
+
} else if (mode === "group" && isNumeric(body.deviceId)) {
|
|
254877
|
+
if (groupInfoList[body?.deviceId]) {
|
|
254900
254878
|
return groupInfoList[body?.deviceId];
|
|
254901
254879
|
}
|
|
254902
|
-
|
|
254903
|
-
|
|
254904
|
-
|
|
254905
|
-
|
|
254906
|
-
|
|
254907
|
-
|
|
254908
|
-
|
|
254909
|
-
|
|
254910
|
-
|
|
254911
|
-
|
|
254912
|
-
|
|
254913
|
-
|
|
254914
|
-
|
|
254915
|
-
|
|
254916
|
-
|
|
254917
|
-
|
|
254880
|
+
const response = await apiRequestByAtop({
|
|
254881
|
+
api: "tuya.m.device.group.get",
|
|
254882
|
+
version: "2.0",
|
|
254883
|
+
params: {
|
|
254884
|
+
id: body?.deviceId
|
|
254885
|
+
}
|
|
254886
|
+
});
|
|
254887
|
+
const { productId } = response?.result || {};
|
|
254888
|
+
if (productId) {
|
|
254889
|
+
const productResponse = await getProductInfo({
|
|
254890
|
+
productIds: [productId]
|
|
254891
|
+
});
|
|
254892
|
+
if (productResponse.result instanceof Array && productResponse.result.length > 0) {
|
|
254893
|
+
const product = productResponse.result[0];
|
|
254894
|
+
console.log("product>>", product);
|
|
254895
|
+
groupInfoList[body?.deviceId] = {
|
|
254896
|
+
result: {
|
|
254897
|
+
...response?.result,
|
|
254898
|
+
panelConfig: product.panelConfig,
|
|
254899
|
+
categoryCode: product.categoryCode,
|
|
254900
|
+
meshCategory: product.meshCategory,
|
|
254901
|
+
supportGroup: product.supportGroup,
|
|
254902
|
+
schema: product.schemaInfo?.schema,
|
|
254903
|
+
capability: product.capability,
|
|
254904
|
+
supportSGroup: product.supportSGroup,
|
|
254905
|
+
attribute: product.attribute,
|
|
254906
|
+
category: product.category
|
|
254907
|
+
}
|
|
254908
|
+
};
|
|
254909
|
+
return groupInfoList[body?.deviceId];
|
|
254910
|
+
}
|
|
254911
|
+
return null;
|
|
254918
254912
|
}
|
|
254919
|
-
});
|
|
254920
|
-
if (!devInfo.success && !devInfo.result) {
|
|
254921
254913
|
return null;
|
|
254922
|
-
}
|
|
254923
|
-
|
|
254924
|
-
|
|
254925
|
-
devInfo.result.dataPointInfo = devInfo32.result?.dataPointInfo;
|
|
254926
|
-
devInfo.result.meta = devInfo32.result?.meta;
|
|
254927
|
-
if (Object.hasOwn(devInfo32.result, "cloudOnline")) {
|
|
254928
|
-
devInfo.result.cloudOnline = devInfo32.result?.cloudOnline;
|
|
254929
|
-
}
|
|
254930
|
-
try {
|
|
254931
|
-
const pInfo = await apiRequestByAtop({
|
|
254932
|
-
api: "tuya.m.product.ext.prop.batch.get",
|
|
254914
|
+
} else {
|
|
254915
|
+
const devInfo = await apiRequestByAtop({
|
|
254916
|
+
api: "tuya.m.device.get",
|
|
254933
254917
|
version: "1.0",
|
|
254934
254918
|
params: {
|
|
254935
|
-
|
|
254919
|
+
devId: body?.deviceId
|
|
254936
254920
|
}
|
|
254937
254921
|
});
|
|
254938
|
-
const
|
|
254939
|
-
|
|
254940
|
-
|
|
254941
|
-
|
|
254942
|
-
|
|
254943
|
-
try {
|
|
254944
|
-
const bleInfo = await apiRequestByAtop({
|
|
254945
|
-
api: "smartlife.m.device.ext.prop.batch.get",
|
|
254946
|
-
version: "1.1",
|
|
254947
|
-
params: { devIds: [body?.deviceId] }
|
|
254948
|
-
});
|
|
254949
|
-
const ble = bleInfo?.result[0];
|
|
254950
|
-
devInfo.result.zigbeeInstallCode = ble?.zigbeeInstallCode;
|
|
254951
|
-
devInfo.result.bluetoothCapability = ble?.bluetoothCapability;
|
|
254952
|
-
} catch (error) {
|
|
254953
|
-
console.log("-----error smartlife.m.device.ext.prop.batch.get", error);
|
|
254954
|
-
}
|
|
254955
|
-
try {
|
|
254956
|
-
const { schema, dps } = devInfo.result;
|
|
254957
|
-
const oDps = { ...dps };
|
|
254958
|
-
JSON.parse(schema).map((item) => {
|
|
254959
|
-
const { id, type } = item;
|
|
254960
|
-
if (Object.keys(oDps).includes(`${id}`) && type === "raw") {
|
|
254961
|
-
if (!isHexString(oDps[id])) {
|
|
254962
|
-
const b2 = Buffer.from(oDps[id], "base64");
|
|
254963
|
-
oDps[id] = b2.toString("hex");
|
|
254964
|
-
}
|
|
254922
|
+
const devInfo32 = await apiRequestByAtop({
|
|
254923
|
+
api: "tuya.m.device.get",
|
|
254924
|
+
version: "4.1",
|
|
254925
|
+
params: {
|
|
254926
|
+
devId: body?.deviceId
|
|
254965
254927
|
}
|
|
254966
254928
|
});
|
|
254967
|
-
devInfo.result
|
|
254968
|
-
|
|
254969
|
-
|
|
254929
|
+
if (!devInfo.success && !devInfo.result) {
|
|
254930
|
+
return null;
|
|
254931
|
+
}
|
|
254932
|
+
devInfo.result.moduleMap = devInfo32.result?.moduleMap;
|
|
254933
|
+
devInfo.result.baseAttribute = devInfo32.result?.baseAttribute;
|
|
254934
|
+
devInfo.result.dataPointInfo = devInfo32.result?.dataPointInfo;
|
|
254935
|
+
devInfo.result.meta = devInfo32.result?.meta;
|
|
254936
|
+
if (Object.hasOwn(devInfo32.result, "cloudOnline")) {
|
|
254937
|
+
devInfo.result.cloudOnline = devInfo32.result?.cloudOnline;
|
|
254938
|
+
}
|
|
254939
|
+
try {
|
|
254940
|
+
const pInfo = await apiRequestByAtop({
|
|
254941
|
+
api: "tuya.m.product.ext.prop.batch.get",
|
|
254942
|
+
version: "1.0",
|
|
254943
|
+
params: {
|
|
254944
|
+
pids: [devInfo.result?.productId]
|
|
254945
|
+
}
|
|
254946
|
+
});
|
|
254947
|
+
const pro = pInfo?.result[0];
|
|
254948
|
+
devInfo.result.bizAttribute = pro?.bizAttribute;
|
|
254949
|
+
} catch (error) {
|
|
254950
|
+
console.log("-----error tuya.m.product.ext.prop.batch.get", error);
|
|
254951
|
+
}
|
|
254952
|
+
try {
|
|
254953
|
+
const bleInfo = await apiRequestByAtop({
|
|
254954
|
+
api: "smartlife.m.device.ext.prop.batch.get",
|
|
254955
|
+
version: "1.1",
|
|
254956
|
+
params: { devIds: [body?.deviceId] }
|
|
254957
|
+
});
|
|
254958
|
+
const ble = bleInfo?.result[0];
|
|
254959
|
+
devInfo.result.zigbeeInstallCode = ble?.zigbeeInstallCode;
|
|
254960
|
+
devInfo.result.bluetoothCapability = ble?.bluetoothCapability;
|
|
254961
|
+
} catch (error) {
|
|
254962
|
+
console.log("-----error smartlife.m.device.ext.prop.batch.get", error);
|
|
254963
|
+
}
|
|
254964
|
+
try {
|
|
254965
|
+
const { schema, dps } = devInfo.result;
|
|
254966
|
+
const oDps = { ...dps };
|
|
254967
|
+
JSON.parse(schema).map((item) => {
|
|
254968
|
+
const { id, type } = item;
|
|
254969
|
+
if (Object.keys(oDps).includes(`${id}`) && type === "raw") {
|
|
254970
|
+
if (!isHexString(oDps[id])) {
|
|
254971
|
+
const b2 = Buffer.from(oDps[id], "base64");
|
|
254972
|
+
oDps[id] = b2.toString("hex");
|
|
254973
|
+
}
|
|
254974
|
+
}
|
|
254975
|
+
});
|
|
254976
|
+
devInfo.result.dps = oDps;
|
|
254977
|
+
} catch (error) {
|
|
254978
|
+
console.log(error);
|
|
254979
|
+
}
|
|
254980
|
+
return devInfo;
|
|
254970
254981
|
}
|
|
254971
|
-
|
|
254982
|
+
} catch (error) {
|
|
254983
|
+
console.log("-------------88888", error);
|
|
254972
254984
|
}
|
|
254973
254985
|
};
|
|
254974
254986
|
var getHomeDeviceList = async () => {
|
|
@@ -255329,6 +255341,7 @@ var MqttListener = (topic, message) => {
|
|
|
255329
255341
|
}, 50);
|
|
255330
255342
|
};
|
|
255331
255343
|
async function dispatchMessageToTTT(result, devOrGroupId, dps) {
|
|
255344
|
+
console.log("dispatchMessageToTTT>>", result);
|
|
255332
255345
|
switch (result?.protocol) {
|
|
255333
255346
|
case 1:
|
|
255334
255347
|
if (typeof result.data?.online === "boolean") {
|
|
@@ -255366,20 +255379,35 @@ async function dispatchMessageToTTT(result, devOrGroupId, dps) {
|
|
|
255366
255379
|
break;
|
|
255367
255380
|
case 4:
|
|
255368
255381
|
case 5:
|
|
255369
|
-
|
|
255370
|
-
|
|
255371
|
-
|
|
255372
|
-
|
|
255373
|
-
|
|
255374
|
-
|
|
255375
|
-
|
|
255376
|
-
|
|
255377
|
-
|
|
255378
|
-
|
|
255379
|
-
|
|
255380
|
-
|
|
255382
|
+
{
|
|
255383
|
+
ark.miniapp.emitPluginEvent({
|
|
255384
|
+
name: "TYUniDeviceControlManager.onDpDataChange",
|
|
255385
|
+
data: {
|
|
255386
|
+
deviceId: devOrGroupId,
|
|
255387
|
+
dps
|
|
255388
|
+
}
|
|
255389
|
+
});
|
|
255390
|
+
ark.miniapp.emitPluginEvent({
|
|
255391
|
+
name: "TUNIDeviceControlManager.onDpDataChange",
|
|
255392
|
+
data: {
|
|
255393
|
+
deviceId: devOrGroupId,
|
|
255394
|
+
dps
|
|
255395
|
+
}
|
|
255396
|
+
});
|
|
255397
|
+
if (result.data?.cid) {
|
|
255398
|
+
const { data: devList2 } = await getSubDeviceInfoList({
|
|
255399
|
+
meshId: devOrGroupId
|
|
255400
|
+
});
|
|
255401
|
+
const dev = devList2.find((item) => item.deviceTopo?.nodeId === result.data?.cid);
|
|
255402
|
+
ark.miniapp.emitPluginEvent({
|
|
255403
|
+
name: "TUNIDeviceControlManager.onSubDeviceDpUpdate",
|
|
255404
|
+
data: {
|
|
255405
|
+
deviceId: dev?.devId,
|
|
255406
|
+
dps
|
|
255407
|
+
}
|
|
255408
|
+
});
|
|
255381
255409
|
}
|
|
255382
|
-
}
|
|
255410
|
+
}
|
|
255383
255411
|
break;
|
|
255384
255412
|
case 32:
|
|
255385
255413
|
ark.miniapp.emitPluginEvent({
|
|
@@ -255400,24 +255428,44 @@ async function dispatchMessageToTTT(result, devOrGroupId, dps) {
|
|
|
255400
255428
|
});
|
|
255401
255429
|
delete cachedDeviceList[devOrGroupId];
|
|
255402
255430
|
break;
|
|
255431
|
+
case 33:
|
|
255432
|
+
{
|
|
255433
|
+
console.log("---------\u5B50\u8BBE\u5907\u53D8\u52A8", result);
|
|
255434
|
+
const {
|
|
255435
|
+
type: type2,
|
|
255436
|
+
s: s2,
|
|
255437
|
+
t: t2,
|
|
255438
|
+
data: { devId: opDevId }
|
|
255439
|
+
} = result;
|
|
255440
|
+
const pluginName = {
|
|
255441
|
+
delete: "onSubDeviceRemoved",
|
|
255442
|
+
add: "onSubDeviceAdded"
|
|
255443
|
+
};
|
|
255444
|
+
if (shouldDispatchSubDeviceEvent(devOrGroupId)) {
|
|
255445
|
+
ark.miniapp.emitPluginEvent({
|
|
255446
|
+
name: `TUNIDeviceControlManager.${pluginName[type2]}`,
|
|
255447
|
+
data: {
|
|
255448
|
+
deviceId: opDevId
|
|
255449
|
+
}
|
|
255450
|
+
});
|
|
255451
|
+
}
|
|
255452
|
+
}
|
|
255453
|
+
break;
|
|
255403
255454
|
case 34:
|
|
255455
|
+
const { data: { devId }, type } = result;
|
|
255404
255456
|
ark.miniapp.emitPluginEvent({
|
|
255405
|
-
name: "TYUniDeviceControlManager.
|
|
255457
|
+
name: "TYUniDeviceControlManager.onSubDeviceInfoUpdate",
|
|
255406
255458
|
data: {
|
|
255407
|
-
|
|
255408
|
-
deviceId: devOrGroupId,
|
|
255409
|
-
dps: {}
|
|
255459
|
+
deviceId: devId
|
|
255410
255460
|
}
|
|
255411
255461
|
});
|
|
255412
255462
|
ark.miniapp.emitPluginEvent({
|
|
255413
|
-
name: "TUNIDeviceControlManager.
|
|
255463
|
+
name: "TUNIDeviceControlManager.onSubDeviceInfoUpdate",
|
|
255414
255464
|
data: {
|
|
255415
|
-
|
|
255416
|
-
deviceId: devOrGroupId,
|
|
255417
|
-
dps: {}
|
|
255465
|
+
deviceId: devId
|
|
255418
255466
|
}
|
|
255419
255467
|
});
|
|
255420
|
-
removeCachedDevice(
|
|
255468
|
+
removeCachedDevice(devId);
|
|
255421
255469
|
break;
|
|
255422
255470
|
case 47:
|
|
255423
255471
|
ark.miniapp.emitPluginEvent({
|
|
@@ -255467,6 +255515,20 @@ async function dispatchMessageToTTT(result, devOrGroupId, dps) {
|
|
|
255467
255515
|
console.log("-error", error);
|
|
255468
255516
|
}
|
|
255469
255517
|
break;
|
|
255518
|
+
case 113:
|
|
255519
|
+
{
|
|
255520
|
+
const {
|
|
255521
|
+
data: { devId: devId2 }
|
|
255522
|
+
} = result;
|
|
255523
|
+
ark.miniapp.emitPluginEvent({
|
|
255524
|
+
name: "TUNIOTAManager.onOtaCompleted",
|
|
255525
|
+
data: {
|
|
255526
|
+
deviceId: devId2,
|
|
255527
|
+
result: 0
|
|
255528
|
+
}
|
|
255529
|
+
});
|
|
255530
|
+
}
|
|
255531
|
+
break;
|
|
255470
255532
|
}
|
|
255471
255533
|
}
|
|
255472
255534
|
function parseRawMessage(result, devInfo) {
|
|
@@ -255693,42 +255755,52 @@ var MqttClientManager = class _MqttClientManager {
|
|
|
255693
255755
|
_MqttClientManager._client = null;
|
|
255694
255756
|
}
|
|
255695
255757
|
static async addDeviceListener(deviceInfo2) {
|
|
255696
|
-
if (!deviceInfo2)
|
|
255697
|
-
return;
|
|
255698
|
-
if (!this._client) {
|
|
255699
|
-
await initMqttClient();
|
|
255700
|
-
}
|
|
255701
255758
|
try {
|
|
255702
|
-
|
|
255703
|
-
if (MqttDevManager.deviceList.find((item) => item.devId === deviceInfo2.devId)) {
|
|
255704
|
-
console.log("-------\u5DF2\u7ECF\u6CE8\u518C\u8FC7\u76D1\u542C\u4E86", topic);
|
|
255759
|
+
if (!deviceInfo2)
|
|
255705
255760
|
return;
|
|
255706
|
-
|
|
255707
|
-
|
|
255761
|
+
if (!this._client) {
|
|
255762
|
+
await initMqttClient();
|
|
255708
255763
|
}
|
|
255709
|
-
|
|
255710
|
-
|
|
255711
|
-
|
|
255712
|
-
|
|
255713
|
-
|
|
255764
|
+
try {
|
|
255765
|
+
const topic = `smart/mb/in/${deviceInfo2.devId}`;
|
|
255766
|
+
if (MqttDevManager.deviceList.find(
|
|
255767
|
+
(item) => item.devId === deviceInfo2.devId
|
|
255768
|
+
)) {
|
|
255769
|
+
console.log("-------\u5DF2\u7ECF\u6CE8\u518C\u8FC7\u76D1\u542C\u4E86", topic);
|
|
255770
|
+
return;
|
|
255714
255771
|
} else {
|
|
255715
|
-
|
|
255772
|
+
MqttDevManager.deviceList.push(deviceInfo2);
|
|
255716
255773
|
}
|
|
255717
|
-
|
|
255774
|
+
console.log("------device to subscribe", topic);
|
|
255775
|
+
this._client.subscribe(topic, { qos: 2 }, (err, grant) => {
|
|
255776
|
+
console.log("MQTT -->>>> error: ", err, "granted : ", grant);
|
|
255777
|
+
if (!err) {
|
|
255778
|
+
viewLog(`[MQTT] @i18n(subscribeSuccess) ${deviceInfo2.devId}`);
|
|
255779
|
+
} else {
|
|
255780
|
+
viewLog(`[MQTT] @i18n(subscribeFailed) ${deviceInfo2.devId} ${err}`);
|
|
255781
|
+
}
|
|
255782
|
+
});
|
|
255783
|
+
} catch (error) {
|
|
255784
|
+
console.log("=======\u6709\u5730\u65B9\u51FA\u4E86\u95EE\u9898", error);
|
|
255785
|
+
}
|
|
255718
255786
|
} catch (error) {
|
|
255719
255787
|
console.log("=======\u6709\u5730\u65B9\u51FA\u4E86\u95EE\u9898", error);
|
|
255720
255788
|
}
|
|
255721
255789
|
}
|
|
255722
255790
|
static removeDeviceListener(devId) {
|
|
255723
|
-
|
|
255724
|
-
|
|
255725
|
-
|
|
255726
|
-
|
|
255727
|
-
|
|
255728
|
-
|
|
255729
|
-
|
|
255791
|
+
try {
|
|
255792
|
+
const topic = `smart/mb/in/${devId}`;
|
|
255793
|
+
const index = MqttDevManager.deviceList.findIndex(
|
|
255794
|
+
(item) => item.devId === devId
|
|
255795
|
+
);
|
|
255796
|
+
console.log("-------------toRemove", devId);
|
|
255797
|
+
if (index > -1) {
|
|
255798
|
+
MqttDevManager.deviceList.splice(index, 1);
|
|
255799
|
+
}
|
|
255800
|
+
return this._client.unsubscribeAsync(topic);
|
|
255801
|
+
} catch (error) {
|
|
255802
|
+
console.log("-----------error", error);
|
|
255730
255803
|
}
|
|
255731
|
-
return this._client.unsubscribeAsync(topic);
|
|
255732
255804
|
}
|
|
255733
255805
|
static async addGroupListener(groupInfo2) {
|
|
255734
255806
|
if (!groupInfo2)
|
|
@@ -255881,57 +255953,67 @@ function unRegisterGroupChange(params) {
|
|
|
255881
255953
|
}
|
|
255882
255954
|
async function getGroupInfo(params) {
|
|
255883
255955
|
const { groupId } = params;
|
|
255884
|
-
|
|
255885
|
-
|
|
255886
|
-
|
|
255887
|
-
|
|
255888
|
-
|
|
255889
|
-
|
|
255890
|
-
|
|
255891
|
-
|
|
255892
|
-
|
|
255893
|
-
|
|
255894
|
-
|
|
255895
|
-
|
|
255896
|
-
|
|
255897
|
-
|
|
255898
|
-
|
|
255899
|
-
|
|
255900
|
-
|
|
255901
|
-
|
|
255902
|
-
|
|
255903
|
-
|
|
255904
|
-
|
|
255905
|
-
|
|
255906
|
-
|
|
255907
|
-
|
|
255908
|
-
|
|
255909
|
-
|
|
255910
|
-
|
|
255911
|
-
|
|
255912
|
-
|
|
255913
|
-
|
|
255914
|
-
|
|
255915
|
-
|
|
255916
|
-
|
|
255917
|
-
|
|
255918
|
-
|
|
255919
|
-
|
|
255920
|
-
|
|
255956
|
+
try {
|
|
255957
|
+
const response = await apiRequestByAtop({
|
|
255958
|
+
api: "tuya.m.device.group.get",
|
|
255959
|
+
version: "2.0",
|
|
255960
|
+
params: {
|
|
255961
|
+
id: groupId
|
|
255962
|
+
}
|
|
255963
|
+
});
|
|
255964
|
+
groupInfo = response?.result;
|
|
255965
|
+
const result = { ...groupInfo };
|
|
255966
|
+
if (!!groupInfo) {
|
|
255967
|
+
const { productId } = groupInfo;
|
|
255968
|
+
result.groupId = String(result.id);
|
|
255969
|
+
result.pv = Number(result.pv);
|
|
255970
|
+
try {
|
|
255971
|
+
const productInfo = await getProductInfo({
|
|
255972
|
+
productIds: [productId],
|
|
255973
|
+
version: "1.0"
|
|
255974
|
+
});
|
|
255975
|
+
const { schemaInfo } = productInfo?.result[0];
|
|
255976
|
+
const schemaString = schemaInfo?.schema;
|
|
255977
|
+
result.schema = JSON.parse(schemaString);
|
|
255978
|
+
result.productInfo = productInfo?.result[0] || {};
|
|
255979
|
+
result.productInfo.productVer = result["productVer"];
|
|
255980
|
+
delete result.productInfo["panelConfig"];
|
|
255981
|
+
delete result.productInfo["i18nTime"];
|
|
255982
|
+
groupInfo = {
|
|
255983
|
+
...groupInfo,
|
|
255984
|
+
...result
|
|
255985
|
+
};
|
|
255986
|
+
} catch (error) {
|
|
255987
|
+
console.log(error);
|
|
255988
|
+
}
|
|
255989
|
+
const { data } = await getGroupDeviceList({ groupId });
|
|
255990
|
+
if (data) {
|
|
255991
|
+
const { deviceList = [] } = data;
|
|
255992
|
+
result.deviceList = deviceList;
|
|
255993
|
+
}
|
|
255994
|
+
}
|
|
255995
|
+
delete result["devId"];
|
|
255996
|
+
delete result["category"];
|
|
255997
|
+
delete result["homeDisplayOrder"];
|
|
255998
|
+
delete result["id"];
|
|
255999
|
+
delete result["productVer"];
|
|
256000
|
+
delete result["standard"];
|
|
256001
|
+
delete result["uid"];
|
|
256002
|
+
cachedGroups[groupId] = { ...result };
|
|
256003
|
+
console.log("--------\u83B7\u53D6 Group \u5931\u8D25", result);
|
|
256004
|
+
return {
|
|
256005
|
+
errorCode: 0,
|
|
256006
|
+
errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des,
|
|
256007
|
+
data: Object.keys(result).length > 0 ? result : null
|
|
256008
|
+
};
|
|
256009
|
+
} catch (error) {
|
|
256010
|
+
console.log("--------\u83B7\u53D6\u4FE1\u606F\u5931\u8D25", error);
|
|
256011
|
+
return {
|
|
256012
|
+
errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_MODEL_NULL.code,
|
|
256013
|
+
errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_MODEL_NULL.des,
|
|
256014
|
+
data: void 0
|
|
256015
|
+
};
|
|
255921
256016
|
}
|
|
255922
|
-
delete result["devId"];
|
|
255923
|
-
delete result["category"];
|
|
255924
|
-
delete result["homeDisplayOrder"];
|
|
255925
|
-
delete result["id"];
|
|
255926
|
-
delete result["productVer"];
|
|
255927
|
-
delete result["standard"];
|
|
255928
|
-
delete result["uid"];
|
|
255929
|
-
cachedGroups[groupId] = { ...result };
|
|
255930
|
-
return {
|
|
255931
|
-
errorCode: 0,
|
|
255932
|
-
errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des,
|
|
255933
|
-
data: result
|
|
255934
|
-
};
|
|
255935
256017
|
}
|
|
255936
256018
|
async function publishGroupDps2(params) {
|
|
255937
256019
|
const { groupId, dps, dpCodes } = params;
|
|
@@ -256301,6 +256383,7 @@ __export(services_exports, {
|
|
|
256301
256383
|
setDeviceId: () => setDeviceId,
|
|
256302
256384
|
setGroupId: () => setGroupId,
|
|
256303
256385
|
setProductId: () => setProductId,
|
|
256386
|
+
shouldDispatchSubDeviceEvent: () => shouldDispatchSubDeviceEvent,
|
|
256304
256387
|
switchHome: () => switchHome,
|
|
256305
256388
|
switchPluginVersion: () => switchPluginVersion,
|
|
256306
256389
|
uninstallExtension: () => uninstallExtension,
|
|
@@ -271369,6 +271452,7 @@ async function publishDps2(params) {
|
|
|
271369
271452
|
data: null
|
|
271370
271453
|
};
|
|
271371
271454
|
} catch (e2) {
|
|
271455
|
+
console.log("--------ad", e2);
|
|
271372
271456
|
return {
|
|
271373
271457
|
errorCode: import_TYUniCode2.TYUniPluginError.DEVICEKIT_PUBLISH_DPS_ERROR.code,
|
|
271374
271458
|
errorMsg: import_TYUniCode2.TYUniPluginError.DEVICEKIT_PUBLISH_DPS_ERROR.des,
|
|
@@ -271422,6 +271506,7 @@ async function getProductInfo2(params) {
|
|
|
271422
271506
|
errorMsg: !!productInfo ? import_TYUniCode2.TYUniPluginError.SUCCESS.des : import_TYUniCode2.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.des
|
|
271423
271507
|
};
|
|
271424
271508
|
} catch (e2) {
|
|
271509
|
+
console.log("--------getProductInfo", e2);
|
|
271425
271510
|
return {
|
|
271426
271511
|
data: null,
|
|
271427
271512
|
devices: [],
|
|
@@ -271499,6 +271584,24 @@ function registerMQTTProtocolListener(params) {
|
|
|
271499
271584
|
errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
|
|
271500
271585
|
};
|
|
271501
271586
|
}
|
|
271587
|
+
function registerGateWaySubDeviceListener(params) {
|
|
271588
|
+
const { deviceId } = params;
|
|
271589
|
+
shouldDispatchSubDeviceEvent(deviceId, true);
|
|
271590
|
+
return {
|
|
271591
|
+
data: null,
|
|
271592
|
+
errorCode: 0,
|
|
271593
|
+
errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
|
|
271594
|
+
};
|
|
271595
|
+
}
|
|
271596
|
+
function unregisterGateWaySubDeviceListener(params) {
|
|
271597
|
+
const { deviceId } = params;
|
|
271598
|
+
shouldDispatchSubDeviceEvent(deviceId, false);
|
|
271599
|
+
return {
|
|
271600
|
+
data: null,
|
|
271601
|
+
errorCode: 0,
|
|
271602
|
+
errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
|
|
271603
|
+
};
|
|
271604
|
+
}
|
|
271502
271605
|
function unregisterDeviceListListener(params) {
|
|
271503
271606
|
devList.map((devId) => {
|
|
271504
271607
|
initMqttClient_default.removeDeviceListener(devId);
|
|
@@ -271701,11 +271804,61 @@ function offDpDataChange() {
|
|
|
271701
271804
|
errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
|
|
271702
271805
|
};
|
|
271703
271806
|
}
|
|
271807
|
+
async function getSubDeviceInfoList(params) {
|
|
271808
|
+
const { meshId: deviceId } = params;
|
|
271809
|
+
try {
|
|
271810
|
+
const { result: list } = await apiRequestByAtop({
|
|
271811
|
+
api: "tuya.m.device.sub.list",
|
|
271812
|
+
version: "2.1",
|
|
271813
|
+
params: {
|
|
271814
|
+
meshId: deviceId
|
|
271815
|
+
}
|
|
271816
|
+
});
|
|
271817
|
+
const promise = list.map((item) => {
|
|
271818
|
+
return getDeviceInfo2({ deviceId: item.devId });
|
|
271819
|
+
});
|
|
271820
|
+
const all3 = await Promise.all(promise);
|
|
271821
|
+
return {
|
|
271822
|
+
data: all3.map((item) => {
|
|
271823
|
+
const detail = list.find((i2) => i2.devId === item.data.devId);
|
|
271824
|
+
return { ...detail, nodeId: detail.mac, ...item.data };
|
|
271825
|
+
}),
|
|
271826
|
+
errorCode: 0,
|
|
271827
|
+
errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
|
|
271828
|
+
};
|
|
271829
|
+
} catch (error) {
|
|
271830
|
+
return {
|
|
271831
|
+
data: [],
|
|
271832
|
+
errorCode: import_TYUniCode2.TYUniPluginError.DEVICEKIT_GW_ID_INVALID.code,
|
|
271833
|
+
errorMsg: import_TYUniCode2.TYUniPluginError.DEVICEKIT_GW_ID_INVALID.des
|
|
271834
|
+
};
|
|
271835
|
+
}
|
|
271836
|
+
}
|
|
271704
271837
|
ark.miniapp.addPluginMethod(
|
|
271705
271838
|
"TUNIDeviceControlManager",
|
|
271706
271839
|
"getDeviceInfo",
|
|
271707
271840
|
getDeviceInfo2
|
|
271708
271841
|
);
|
|
271842
|
+
ark.miniapp.addPluginMethod(
|
|
271843
|
+
"TUNIDeviceControlManager",
|
|
271844
|
+
"getSubDeviceInfoList",
|
|
271845
|
+
getSubDeviceInfoList
|
|
271846
|
+
);
|
|
271847
|
+
ark.miniapp.addPluginMethod(
|
|
271848
|
+
"TUNIDeviceControlManager",
|
|
271849
|
+
"registerGateWaySubDeviceListener",
|
|
271850
|
+
registerGateWaySubDeviceListener
|
|
271851
|
+
);
|
|
271852
|
+
ark.miniapp.addPluginMethod(
|
|
271853
|
+
"TUNIDeviceControlManager",
|
|
271854
|
+
"registerZigbeeGateWaySubDeviceListener",
|
|
271855
|
+
registerGateWaySubDeviceListener
|
|
271856
|
+
);
|
|
271857
|
+
ark.miniapp.addPluginMethod(
|
|
271858
|
+
"TUNIDeviceControlManager",
|
|
271859
|
+
"unregisterGateWaySubDeviceListener",
|
|
271860
|
+
unregisterGateWaySubDeviceListener
|
|
271861
|
+
);
|
|
271709
271862
|
ark.miniapp.addPluginMethod(
|
|
271710
271863
|
"TUNIDeviceDetailManager",
|
|
271711
271864
|
"getShareDeviceInfo",
|
|
@@ -272041,8 +272194,38 @@ ark.miniapp.addPluginMethod("TYUniBluetoothManager", "bluetoothIsPowerOn", bluet
|
|
|
272041
272194
|
// worker/api/TYUniOTAManager.ts
|
|
272042
272195
|
var import_TYUniCode5 = __toESM(require_dist());
|
|
272043
272196
|
async function checkOTAUpgradeStatus(params) {
|
|
272197
|
+
const { deviceId } = params;
|
|
272198
|
+
if (!deviceId) {
|
|
272199
|
+
return {
|
|
272200
|
+
errorCode: import_TYUniCode5.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.code,
|
|
272201
|
+
errorMsg: import_TYUniCode5.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.des,
|
|
272202
|
+
data: null
|
|
272203
|
+
};
|
|
272204
|
+
}
|
|
272205
|
+
try {
|
|
272206
|
+
const data = await apiRequestByAtop({
|
|
272207
|
+
api: "m.thing.firmware.upgrade.info.get",
|
|
272208
|
+
version: "1.0",
|
|
272209
|
+
params: {
|
|
272210
|
+
devId: deviceId
|
|
272211
|
+
}
|
|
272212
|
+
});
|
|
272213
|
+
const update = data.result?.find((item) => {
|
|
272214
|
+
const { upgradeStatus } = item;
|
|
272215
|
+
return upgradeStatus !== 0;
|
|
272216
|
+
});
|
|
272217
|
+
return {
|
|
272218
|
+
data: { status: update?.upgradeStatus || 0 },
|
|
272219
|
+
errorCode: 0,
|
|
272220
|
+
errorMsg: import_TYUniCode5.TYUniPluginError.SUCCESS.des
|
|
272221
|
+
};
|
|
272222
|
+
} catch (error) {
|
|
272223
|
+
console.log("---------error", error);
|
|
272224
|
+
}
|
|
272225
|
+
}
|
|
272226
|
+
async function registerOTACompleted() {
|
|
272044
272227
|
return {
|
|
272045
|
-
data:
|
|
272228
|
+
data: void 0,
|
|
272046
272229
|
errorCode: 0,
|
|
272047
272230
|
errorMsg: import_TYUniCode5.TYUniPluginError.SUCCESS.des
|
|
272048
272231
|
};
|
|
@@ -272057,6 +272240,16 @@ ark.miniapp.addPluginMethod(
|
|
|
272057
272240
|
"checkOTAUpgradeStatus",
|
|
272058
272241
|
checkOTAUpgradeStatus
|
|
272059
272242
|
);
|
|
272243
|
+
ark.miniapp.addPluginMethod(
|
|
272244
|
+
"TUNIOTAManager",
|
|
272245
|
+
"otaStatus",
|
|
272246
|
+
checkOTAUpgradeStatus
|
|
272247
|
+
);
|
|
272248
|
+
ark.miniapp.addPluginMethod(
|
|
272249
|
+
"TUNIOTAManager",
|
|
272250
|
+
"registerOTACompleted",
|
|
272251
|
+
registerOTACompleted
|
|
272252
|
+
);
|
|
272060
272253
|
|
|
272061
272254
|
// worker/api/TYUniBluetoothManager.ts
|
|
272062
272255
|
var import_TYUniCode6 = __toESM(require_dist());
|
|
@@ -272638,11 +272831,97 @@ async function syncTimerTask(params) {
|
|
|
272638
272831
|
errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
|
|
272639
272832
|
};
|
|
272640
272833
|
}
|
|
272834
|
+
async function checkOTAUpdateInfo(params) {
|
|
272835
|
+
const { deviceId } = params;
|
|
272836
|
+
if (!deviceId) {
|
|
272837
|
+
return {
|
|
272838
|
+
errorCode: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.code,
|
|
272839
|
+
errorMsg: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.des,
|
|
272840
|
+
data: null
|
|
272841
|
+
};
|
|
272842
|
+
}
|
|
272843
|
+
try {
|
|
272844
|
+
const data = await apiRequestByAtop({
|
|
272845
|
+
api: "m.thing.firmware.upgrade.info.get",
|
|
272846
|
+
version: "1.0",
|
|
272847
|
+
params: {
|
|
272848
|
+
devId: deviceId
|
|
272849
|
+
}
|
|
272850
|
+
});
|
|
272851
|
+
return {
|
|
272852
|
+
data: data.result,
|
|
272853
|
+
errorCode: 0,
|
|
272854
|
+
errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
|
|
272855
|
+
};
|
|
272856
|
+
} catch (error) {
|
|
272857
|
+
return {
|
|
272858
|
+
data: null,
|
|
272859
|
+
errorCode: error.innerError.errorCode,
|
|
272860
|
+
errorMsg: error.innerError.errorMsg
|
|
272861
|
+
};
|
|
272862
|
+
}
|
|
272863
|
+
}
|
|
272864
|
+
async function getDeviceOfflineReminderState(params) {
|
|
272865
|
+
const { deviceId } = params;
|
|
272866
|
+
if (!deviceId) {
|
|
272867
|
+
return {
|
|
272868
|
+
errorCode: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.code,
|
|
272869
|
+
errorMsg: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.des,
|
|
272870
|
+
data: null
|
|
272871
|
+
};
|
|
272872
|
+
}
|
|
272873
|
+
try {
|
|
272874
|
+
const data = await apiRequestByAtop({
|
|
272875
|
+
api: "tuya.m.linkage.dynamic.configuration",
|
|
272876
|
+
version: "1.0",
|
|
272877
|
+
params: {
|
|
272878
|
+
entityType: 1,
|
|
272879
|
+
entityId: deviceId
|
|
272880
|
+
}
|
|
272881
|
+
});
|
|
272882
|
+
return {
|
|
272883
|
+
data: { state: data.result?.offlineReminder || 0 },
|
|
272884
|
+
errorCode: 0,
|
|
272885
|
+
errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
|
|
272886
|
+
};
|
|
272887
|
+
} catch (error) {
|
|
272888
|
+
return {
|
|
272889
|
+
data: null,
|
|
272890
|
+
errorCode: error.innerError.errorCode,
|
|
272891
|
+
errorMsg: error.innerError.errorMsg
|
|
272892
|
+
};
|
|
272893
|
+
}
|
|
272894
|
+
}
|
|
272895
|
+
async function getDeviceOfflineReminderWarningText() {
|
|
272896
|
+
try {
|
|
272897
|
+
const data = await apiRequestByAtop({
|
|
272898
|
+
api: "tuya.m.client.conf.get",
|
|
272899
|
+
version: "1.0",
|
|
272900
|
+
params: {}
|
|
272901
|
+
});
|
|
272902
|
+
return {
|
|
272903
|
+
data: { warningText: data.result?.offlineSwitchRemind },
|
|
272904
|
+
errorCode: 0,
|
|
272905
|
+
errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
|
|
272906
|
+
};
|
|
272907
|
+
} catch (error) {
|
|
272908
|
+
return {
|
|
272909
|
+
data: null,
|
|
272910
|
+
errorCode: error.innerError.errorCode,
|
|
272911
|
+
errorMsg: error.innerError.errorMsg
|
|
272912
|
+
};
|
|
272913
|
+
}
|
|
272914
|
+
}
|
|
272641
272915
|
ark.miniapp.addPluginMethod(
|
|
272642
272916
|
"TUNIDeviceDetailManager",
|
|
272643
272917
|
"syncTimerTask",
|
|
272644
272918
|
syncTimerTask
|
|
272645
272919
|
);
|
|
272920
|
+
ark.miniapp.addPluginMethod(
|
|
272921
|
+
"TUNIDeviceDetailManager",
|
|
272922
|
+
"checkOTAUpdateInfo",
|
|
272923
|
+
checkOTAUpdateInfo
|
|
272924
|
+
);
|
|
272646
272925
|
ark.miniapp.addPluginMethod("TUNIDeviceDetailManager", "addTimer", addTimer);
|
|
272647
272926
|
ark.miniapp.addPluginMethod(
|
|
272648
272927
|
"TUNIDeviceDetailManager",
|
|
@@ -272659,6 +272938,16 @@ ark.miniapp.addPluginMethod(
|
|
|
272659
272938
|
"removeTimer",
|
|
272660
272939
|
removeTimer
|
|
272661
272940
|
);
|
|
272941
|
+
ark.miniapp.addPluginMethod(
|
|
272942
|
+
"TUNIDeviceDetailManager",
|
|
272943
|
+
"getDeviceOfflineReminderState",
|
|
272944
|
+
getDeviceOfflineReminderState
|
|
272945
|
+
);
|
|
272946
|
+
ark.miniapp.addPluginMethod(
|
|
272947
|
+
"TUNIDeviceDetailManager",
|
|
272948
|
+
"getDeviceOfflineReminderWarningText",
|
|
272949
|
+
getDeviceOfflineReminderWarningText
|
|
272950
|
+
);
|
|
272662
272951
|
|
|
272663
272952
|
// worker/api/Bridge.ts
|
|
272664
272953
|
var import_TYUniCode11 = __toESM(require_dist());
|
|
@@ -272884,100 +273173,108 @@ function saveDebugExtension({ service, params: { path: path6 }, eventId }) {
|
|
|
272884
273173
|
var isInstanceMode7 = process.env.PROJECT_MODE === "instant";
|
|
272885
273174
|
initPlugin();
|
|
272886
273175
|
ark.runtime.onMessage(async (event) => {
|
|
272887
|
-
|
|
272888
|
-
|
|
272889
|
-
|
|
272890
|
-
|
|
272891
|
-
|
|
272892
|
-
|
|
272893
|
-
|
|
272894
|
-
|
|
272895
|
-
|
|
272896
|
-
|
|
272897
|
-
|
|
272898
|
-
|
|
272899
|
-
|
|
272900
|
-
|
|
272901
|
-
|
|
272902
|
-
|
|
272903
|
-
|
|
272904
|
-
|
|
272905
|
-
|
|
272906
|
-
|
|
272907
|
-
|
|
272908
|
-
|
|
272909
|
-
|
|
272910
|
-
|
|
272911
|
-
|
|
272912
|
-
|
|
272913
|
-
|
|
272914
|
-
|
|
272915
|
-
|
|
272916
|
-
|
|
272917
|
-
} else {
|
|
272918
|
-
if (service === "initLaunchParams") {
|
|
272919
|
-
const { deviceId, productId, groupId, __debugMode } = params;
|
|
272920
|
-
if (!!productId) {
|
|
272921
|
-
await setProductId(productId);
|
|
272922
|
-
} else {
|
|
272923
|
-
await setProductId("");
|
|
272924
|
-
}
|
|
272925
|
-
if (!!deviceId) {
|
|
272926
|
-
await setDeviceId(deviceId);
|
|
272927
|
-
} else {
|
|
272928
|
-
await setDeviceId("");
|
|
273176
|
+
try {
|
|
273177
|
+
const message = event.message;
|
|
273178
|
+
console.log("\u540E\u7AEF\u6536\u5230\u6D88\u606F", message);
|
|
273179
|
+
if (isJSON(message)) {
|
|
273180
|
+
const data = JSON.parse(message);
|
|
273181
|
+
if (data["__bridge__"]) {
|
|
273182
|
+
const { event: event2, payload } = data["__bridge__"];
|
|
273183
|
+
bridgeWall.send(event2, payload);
|
|
273184
|
+
console.log("[bridgeWall.send]", data["__bridge__"]);
|
|
273185
|
+
}
|
|
273186
|
+
const service = data.service;
|
|
273187
|
+
const params = data.params;
|
|
273188
|
+
console.log(`\u540E\u7AEF\u65B9\u6CD5[${service}]\u662F\u5426\u5B9E\u73B0:`, service in services_default);
|
|
273189
|
+
if (service in services_default) {
|
|
273190
|
+
try {
|
|
273191
|
+
const res = await services_default[service](params);
|
|
273192
|
+
ark.runtime.sendMessage(
|
|
273193
|
+
JSON.stringify({
|
|
273194
|
+
...data,
|
|
273195
|
+
result: res
|
|
273196
|
+
})
|
|
273197
|
+
);
|
|
273198
|
+
} catch (error) {
|
|
273199
|
+
console.log(`\u540E\u7AEF\u65B9\u6CD5[${service}]\u6267\u884C\u5931\u8D25`, error);
|
|
273200
|
+
ark.runtime.sendMessage(
|
|
273201
|
+
JSON.stringify({
|
|
273202
|
+
...data,
|
|
273203
|
+
result: null
|
|
273204
|
+
})
|
|
273205
|
+
);
|
|
272929
273206
|
}
|
|
272930
|
-
|
|
272931
|
-
|
|
272932
|
-
|
|
272933
|
-
|
|
273207
|
+
} else {
|
|
273208
|
+
if (service === "initLaunchParams") {
|
|
273209
|
+
const { deviceId, productId, groupId, __debugMode } = params;
|
|
273210
|
+
if (!!productId) {
|
|
273211
|
+
await setProductId(productId);
|
|
273212
|
+
} else {
|
|
273213
|
+
await setProductId("");
|
|
273214
|
+
}
|
|
273215
|
+
if (!!deviceId) {
|
|
273216
|
+
await setDeviceId(deviceId);
|
|
273217
|
+
} else {
|
|
273218
|
+
await setDeviceId("");
|
|
273219
|
+
}
|
|
273220
|
+
if (!!groupId) {
|
|
273221
|
+
await setGroupId(groupId);
|
|
273222
|
+
} else {
|
|
273223
|
+
await setGroupId("");
|
|
273224
|
+
}
|
|
273225
|
+
initMqttClient_default.removeAllSubscribe();
|
|
273226
|
+
await setDebugMode({ mode: __debugMode });
|
|
273227
|
+
initLaunchParams();
|
|
273228
|
+
ark.runtime.sendMessage(JSON.stringify({ ...data }));
|
|
273229
|
+
} else if (service === "startMQTT") {
|
|
273230
|
+
initMqttClient_default.reconnectAll();
|
|
273231
|
+
} else if (service === "set_debug_extension_path") {
|
|
273232
|
+
saveDebugExtension(data);
|
|
272934
273233
|
}
|
|
272935
|
-
initMqttClient_default.removeAllSubscribe();
|
|
272936
|
-
await setDebugMode({ mode: __debugMode });
|
|
272937
|
-
initLaunchParams();
|
|
272938
|
-
ark.runtime.sendMessage(JSON.stringify({ ...data }));
|
|
272939
|
-
} else if (service === "startMQTT") {
|
|
272940
|
-
initMqttClient_default.reconnectAll();
|
|
272941
|
-
} else if (service === "set_debug_extension_path") {
|
|
272942
|
-
saveDebugExtension(data);
|
|
272943
273234
|
}
|
|
272944
273235
|
}
|
|
273236
|
+
} catch (error) {
|
|
273237
|
+
console.log("---------------error", error);
|
|
272945
273238
|
}
|
|
272946
273239
|
});
|
|
272947
273240
|
async function initLaunchParams() {
|
|
272948
|
-
|
|
272949
|
-
|
|
272950
|
-
|
|
272951
|
-
|
|
272952
|
-
|
|
272953
|
-
|
|
272954
|
-
|
|
272955
|
-
|
|
272956
|
-
|
|
272957
|
-
|
|
272958
|
-
|
|
272959
|
-
|
|
272960
|
-
|
|
272961
|
-
|
|
272962
|
-
|
|
272963
|
-
|
|
272964
|
-
|
|
272965
|
-
|
|
272966
|
-
|
|
272967
|
-
|
|
272968
|
-
|
|
272969
|
-
|
|
272970
|
-
|
|
272971
|
-
|
|
272972
|
-
|
|
272973
|
-
|
|
272974
|
-
|
|
272975
|
-
|
|
272976
|
-
|
|
272977
|
-
|
|
273241
|
+
try {
|
|
273242
|
+
onUpdateListener && onUpdateListener();
|
|
273243
|
+
const status = await ark.auth.checkStatus();
|
|
273244
|
+
console.log("authorized:", status);
|
|
273245
|
+
if (status !== "authorized")
|
|
273246
|
+
return;
|
|
273247
|
+
console.log("to get device or group id");
|
|
273248
|
+
let deviceId = await services_default.getDeviceId();
|
|
273249
|
+
console.log(" got device id", deviceId);
|
|
273250
|
+
const groupId = await services_default.getGroupId();
|
|
273251
|
+
console.log(" got group id", groupId);
|
|
273252
|
+
const mode = await services_default.getDebugMode();
|
|
273253
|
+
console.log(" got dev mode", mode);
|
|
273254
|
+
let deviceInfo2 = null, groupInfo2 = null;
|
|
273255
|
+
if (groupId && mode === "group") {
|
|
273256
|
+
const gd = await getGroupInfo({ groupId });
|
|
273257
|
+
groupInfo2 = gd?.data;
|
|
273258
|
+
deviceId = groupId;
|
|
273259
|
+
}
|
|
273260
|
+
if (deviceId && deviceId !== groupId) {
|
|
273261
|
+
await getLangContent({});
|
|
273262
|
+
await getDeviceInfo2({ deviceId });
|
|
273263
|
+
deviceInfo2 = getCachedDevice()[deviceId];
|
|
273264
|
+
}
|
|
273265
|
+
console.log("to startMQTT", deviceId, groupId);
|
|
273266
|
+
await initMqttClient();
|
|
273267
|
+
if (mode === "group") {
|
|
273268
|
+
initMqttClient_default.addGroupListener(groupInfo2);
|
|
273269
|
+
} else {
|
|
273270
|
+
console.log("------------------- \u53BB\u76D1\u542C");
|
|
273271
|
+
initMqttClient_default.addDeviceListener(deviceInfo2);
|
|
273272
|
+
}
|
|
273273
|
+
ark.utils.reload();
|
|
273274
|
+
initUpdateMessage();
|
|
273275
|
+
} catch (error) {
|
|
273276
|
+
console.log("---------update", error);
|
|
272978
273277
|
}
|
|
272979
|
-
ark.utils.reload();
|
|
272980
|
-
initUpdateMessage();
|
|
272981
273278
|
}
|
|
272982
273279
|
isInstanceMode7 && ark.project.setCompilationParams({ params: `deviceId=123` });
|
|
272983
273280
|
ark.auth.onAuthed(async (env) => {
|