@tuya-miniapp/ark-extension-virtual-device 1.5.0-beta-2 → 1.5.0-beta-3

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.
Files changed (2) hide show
  1. package/dist/worker/index.js +793 -93
  2. package/package.json +1 -1
@@ -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-beta-1",
213427
+ version: "1.5.0-beta-2",
213428
213428
  license: "MIT",
213429
213429
  files: [
213430
213430
  "manifest.json",
@@ -253337,19 +253337,23 @@ var viewLog = (message) => {
253337
253337
 
253338
253338
  // worker/utils/home.ts
253339
253339
  var getHomeId = async () => {
253340
- let savedHomeId = await ark.storage.get("current_home_id");
253341
- const u2 = await ark.auth.getCustomerUserInfo();
253342
- if (!u2) {
253343
- console.log("\u7528\u6237\u4FE1\u606F\u83B7\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6388\u6743", u2);
253344
- viewLog(`[MQTT] @i18n(connectNoAccess)`);
253340
+ try {
253341
+ let savedHomeId = await ark.storage.get("current_home_id");
253342
+ const u2 = await ark.auth.getCustomerUserInfo();
253343
+ if (!u2) {
253344
+ console.log("\u7528\u6237\u4FE1\u606F\u83B7\u53D6\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6388\u6743", u2);
253345
+ viewLog(`[MQTT] @i18n(connectNoAccess)`);
253346
+ return null;
253347
+ }
253348
+ const userInfo = typeof u2 === "string" ? JSON.parse(u2) : u2;
253349
+ const {
253350
+ extras: { homeId }
253351
+ } = userInfo;
253352
+ return savedHomeId || homeId;
253353
+ } catch (error) {
253354
+ console.log("-------aaaaaa", error);
253345
253355
  return null;
253346
253356
  }
253347
- const userInfo = typeof u2 === "string" ? JSON.parse(u2) : u2;
253348
- const {
253349
- extras: { homeId }
253350
- } = userInfo;
253351
- console.log("-------getHomeId", homeId, savedHomeId);
253352
- return savedHomeId || homeId;
253353
253357
  };
253354
253358
  var setHomeId = async (homeId) => {
253355
253359
  console.log("-------setHomeId", homeId);
@@ -253363,6 +253367,10 @@ var allDeviceIds = [];
253363
253367
  var allGroupIds = [];
253364
253368
  var getAllDeviceIds = () => allDeviceIds;
253365
253369
  var getAllGroupIds = () => allGroupIds;
253370
+ var cachedDevices = {};
253371
+ function getCachedDevice() {
253372
+ return cachedDevices;
253373
+ }
253366
253374
  var isBase64 = (str) => {
253367
253375
  try {
253368
253376
  return btoa(atob(str)) == str;
@@ -254357,6 +254365,9 @@ var initMqttClient_default = MqttClientManager;
254357
254365
  // worker/api/TYUniGroupControlManager.ts
254358
254366
  var groupInfo = null;
254359
254367
  var cachedGroups = {};
254368
+ function getCachedGroup(groupId) {
254369
+ return cachedGroups[groupId];
254370
+ }
254360
254371
  var groupIds = [];
254361
254372
  var count = 0;
254362
254373
  function registerGroupChange(params) {
@@ -254417,7 +254428,6 @@ function unRegisterGroupChange(params) {
254417
254428
  }
254418
254429
  async function getGroupInfo(params) {
254419
254430
  const { groupId } = params;
254420
- const homeId = await getHomeId();
254421
254431
  const response = await apiRequestByAtop({
254422
254432
  api: "tuya.m.device.group.get",
254423
254433
  version: "2.0",
@@ -254450,36 +254460,10 @@ async function getGroupInfo(params) {
254450
254460
  } catch (error) {
254451
254461
  console.log(error);
254452
254462
  }
254453
- const devList2 = await apiRequestByAtop({
254454
- api: "s.m.dev.group.add.dev.list",
254455
- version: "1.0",
254456
- params: {
254457
- groupId,
254458
- productId: result.productId
254459
- },
254460
- meta: {
254461
- gid: homeId
254462
- }
254463
- });
254464
- const list = devList2?.result?.filter((item) => item.checked);
254465
- if (list && list.length > 0) {
254466
- try {
254467
- const homeAllDeviceResponse = await apiRequestByAtop({
254468
- api: "tuya.m.my.group.device.list",
254469
- version: "2.1",
254470
- params: {},
254471
- meta: {
254472
- gid: homeId
254473
- }
254474
- });
254475
- const devIds = list.map((item) => item.devId);
254476
- const l2 = homeAllDeviceResponse?.result?.filter(
254477
- (item) => devIds.indexOf(item.devId) > -1
254478
- );
254479
- result.deviceList = l2;
254480
- } catch (error) {
254481
- console.log(error);
254482
- }
254463
+ const { data } = await getGroupDeviceList({ groupId });
254464
+ if (data) {
254465
+ const { deviceList = [] } = data;
254466
+ result.deviceList = deviceList;
254483
254467
  }
254484
254468
  }
254485
254469
  delete result["devId"];
@@ -254496,28 +254480,59 @@ async function getGroupInfo(params) {
254496
254480
  data: result
254497
254481
  };
254498
254482
  }
254499
- async function PublishGroupDps(params) {
254500
- const { groupId, dps } = params;
254483
+ async function publishGroupDps2(params) {
254484
+ const { groupId, dps, dpCodes } = params;
254501
254485
  try {
254502
- if (cachedGroups[groupId]) {
254503
- const { schema } = cachedGroups[groupId];
254504
- const idCodes = {};
254505
- schema.map((item) => {
254506
- idCodes[item.id] = item.code;
254486
+ if (!cachedGroups[groupId]) {
254487
+ await getGroupInfo({ groupId });
254488
+ }
254489
+ if (!cachedGroups[groupId]) {
254490
+ return {
254491
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_MODEL_NULL.code,
254492
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_MODEL_NULL.des,
254493
+ data: null
254494
+ };
254495
+ }
254496
+ const { schema, ownerId } = cachedGroups[groupId];
254497
+ let pubDps = dps || {};
254498
+ const idCodes = {};
254499
+ const codeIds = {};
254500
+ schema.map((item) => {
254501
+ idCodes[item.id] = item.code;
254502
+ codeIds[item.code] = item.id;
254503
+ });
254504
+ const publish = dpCodes ? dpCodes : {};
254505
+ if (dpCodes) {
254506
+ Object.keys(dpCodes).map((key) => {
254507
+ const dpId = codeIds[key];
254508
+ pubDps[dpId] = dpCodes[key];
254507
254509
  });
254508
- const publish = {};
254510
+ } else {
254509
254511
  Object.keys(dps).map((key) => {
254510
254512
  const code2 = idCodes[key];
254511
254513
  publish[code2] = dps[key];
254512
254514
  });
254513
- ark.runtime.sendMessage(
254514
- JSON.stringify({ type: "publishDps", value: publish, protocol: 5 })
254515
+ }
254516
+ ark.runtime.sendMessage(
254517
+ JSON.stringify({ type: "publishDps", value: publish, protocol: 5 })
254518
+ );
254519
+ let reason, result;
254520
+ try {
254521
+ result = await publishGroupDps(
254522
+ { groupId, dps: pubDps, schema, ownerId },
254523
+ (err) => {
254524
+ reason = err;
254525
+ }
254515
254526
  );
254527
+ } catch (error) {
254528
+ console.log("-------try", error);
254516
254529
  }
254517
- let reason;
254518
- const result = await publishGroupDps({ groupId, dps }, (err) => {
254519
- reason = err;
254520
- });
254530
+ console.log(
254531
+ "---------publish result ",
254532
+ { groupId, dps: pubDps },
254533
+ result,
254534
+ reason
254535
+ );
254521
254536
  let code = 0, msg = import_TYUniCode.TYUniPluginError.SUCCESS.des;
254522
254537
  if (reason || !result) {
254523
254538
  switch (reason) {
@@ -254547,6 +254562,170 @@ async function PublishGroupDps(params) {
254547
254562
  };
254548
254563
  }
254549
254564
  }
254565
+ async function publishGroupDpCodes(params) {
254566
+ const { groupId } = params;
254567
+ console.log(
254568
+ "---------------TUNIGroupControlManager.publishGroupDpCodes",
254569
+ params
254570
+ );
254571
+ if (!groupId) {
254572
+ return {
254573
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_PUBLISH_DPS_ERROR.code,
254574
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_PUBLISH_DPS_ERROR.des,
254575
+ data: null
254576
+ };
254577
+ }
254578
+ if (!cachedGroups[groupId]) {
254579
+ await getGroupInfo({ groupId });
254580
+ }
254581
+ return publishGroupDps2(params);
254582
+ }
254583
+ async function getGroupProperty(params) {
254584
+ const { groupId, dps } = params;
254585
+ const result = await apiRequestByAtop({
254586
+ api: "s.m.dev.property.get",
254587
+ version: "2.0",
254588
+ params: {
254589
+ devId: groupId,
254590
+ bizType: "1"
254591
+ }
254592
+ });
254593
+ return {
254594
+ data: {
254595
+ result: result.result
254596
+ },
254597
+ errorCode: 0,
254598
+ errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des
254599
+ };
254600
+ }
254601
+ async function setGroupProperty(params) {
254602
+ const { groupId, code, value } = params;
254603
+ const result = await apiRequestByAtop({
254604
+ api: "s.m.dev.property.save",
254605
+ version: "2.0",
254606
+ params: {
254607
+ devId: groupId,
254608
+ bizType: "1",
254609
+ code,
254610
+ value
254611
+ }
254612
+ });
254613
+ return {
254614
+ data: result.result,
254615
+ errorCode: 0,
254616
+ errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des
254617
+ };
254618
+ }
254619
+ async function getGroupDeviceList(params) {
254620
+ const { groupId } = params;
254621
+ if (!groupId) {
254622
+ return {
254623
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_ID_INVALID.code,
254624
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_ID_INVALID.des,
254625
+ data: null
254626
+ };
254627
+ }
254628
+ const homeId = await getHomeId();
254629
+ let deviceList = [];
254630
+ const devList2 = await apiRequestByAtop({
254631
+ api: "s.m.dev.group.add.dev.list",
254632
+ version: "4.0",
254633
+ params: {
254634
+ groupId
254635
+ },
254636
+ meta: {
254637
+ gid: homeId
254638
+ }
254639
+ });
254640
+ const list = devList2?.result?.filter((item) => item.checked);
254641
+ if (list && list.length > 0) {
254642
+ try {
254643
+ const homeAllDeviceResponse = await apiRequestByAtop({
254644
+ api: "tuya.m.my.group.device.list",
254645
+ version: "2.1",
254646
+ params: {},
254647
+ meta: {
254648
+ gid: homeId
254649
+ }
254650
+ });
254651
+ const devIds = list.map((item) => item.devId);
254652
+ const l2 = homeAllDeviceResponse?.result?.filter(
254653
+ (item) => devIds.indexOf(item.devId) > -1
254654
+ );
254655
+ deviceList = l2;
254656
+ return {
254657
+ data: {
254658
+ deviceList,
254659
+ groupId
254660
+ },
254661
+ errorCode: 0,
254662
+ errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des
254663
+ };
254664
+ } catch (error) {
254665
+ console.log(error);
254666
+ return {
254667
+ data: null,
254668
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_ID_INVALID.code,
254669
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_ID_INVALID.des
254670
+ };
254671
+ }
254672
+ }
254673
+ }
254674
+ async function getGroupDeviceNum(params) {
254675
+ const { groupId } = params;
254676
+ if (!groupId) {
254677
+ return {
254678
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_ID_INVALID.code,
254679
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_ID_INVALID.des,
254680
+ data: null
254681
+ };
254682
+ }
254683
+ await getGroupInfo({ groupId });
254684
+ const group = cachedGroups[groupId];
254685
+ return {
254686
+ data: { devieNum: group.deviceNum },
254687
+ errorCode: 0,
254688
+ errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des
254689
+ };
254690
+ }
254691
+ async function getDeviceNumWithDpCode(params) {
254692
+ const { groupId, dpCode } = params;
254693
+ console.log("--------getDeviceNumWithDpCode", groupId, dpCode);
254694
+ if (!groupId) {
254695
+ return {
254696
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_ID_INVALID.code,
254697
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_GROUP_ID_INVALID.des,
254698
+ data: null
254699
+ };
254700
+ }
254701
+ const homeId = await getHomeId();
254702
+ const devList2 = await apiRequestByAtop({
254703
+ api: "s.m.dev.group.add.dev.list",
254704
+ version: "4.0",
254705
+ params: {
254706
+ groupId
254707
+ },
254708
+ meta: {
254709
+ gid: homeId
254710
+ }
254711
+ });
254712
+ const deviceList = devList2?.result?.filter((item) => item.checked);
254713
+ const promises = deviceList.map((item) => {
254714
+ return getDeviceInfo2({ deviceId: item.devId });
254715
+ });
254716
+ const l2 = await Promise.all(promises);
254717
+ console.log("--------getDeviceNumWithDpCode", l2);
254718
+ const result = deviceList.filter((item) => {
254719
+ const { schema } = item;
254720
+ return schema.find((s2) => s2.code === dpCode);
254721
+ });
254722
+ console.log("--------999999", result);
254723
+ return {
254724
+ data: { devieNum: result.length },
254725
+ errorCode: 0,
254726
+ errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des
254727
+ };
254728
+ }
254550
254729
  ark.miniapp.addPluginMethod(
254551
254730
  "TUNIGroupControlManager",
254552
254731
  "registerGroupChange",
@@ -254555,7 +254734,12 @@ ark.miniapp.addPluginMethod(
254555
254734
  ark.miniapp.addPluginMethod(
254556
254735
  "TUNIGroupControlManager",
254557
254736
  "publishGroupDps",
254558
- PublishGroupDps
254737
+ publishGroupDps2
254738
+ );
254739
+ ark.miniapp.addPluginMethod(
254740
+ "TUNIGroupControlManager",
254741
+ "publishGroupDpCodes",
254742
+ publishGroupDpCodes
254559
254743
  );
254560
254744
  ark.miniapp.addPluginMethod(
254561
254745
  "TUNIGroupControlManager",
@@ -254582,6 +254766,31 @@ ark.miniapp.addPluginMethod(
254582
254766
  "getGroupInfo",
254583
254767
  getGroupInfo
254584
254768
  );
254769
+ ark.miniapp.addPluginMethod(
254770
+ "TUNIGroupControlManager",
254771
+ "getGroupProperty",
254772
+ getGroupProperty
254773
+ );
254774
+ ark.miniapp.addPluginMethod(
254775
+ "TUNIGroupControlManager",
254776
+ "setGroupProperty",
254777
+ setGroupProperty
254778
+ );
254779
+ ark.miniapp.addPluginMethod(
254780
+ "TUNIGroupControlManager",
254781
+ "getGroupDeviceList",
254782
+ getGroupDeviceList
254783
+ );
254784
+ ark.miniapp.addPluginMethod(
254785
+ "TUNIGroupControlManager",
254786
+ "getGroupDeviceNum",
254787
+ getGroupDeviceNum
254788
+ );
254789
+ ark.miniapp.addPluginMethod(
254790
+ "TUNIGroupControlManager",
254791
+ "getDeviceNumWithDpCode",
254792
+ getDeviceNumWithDpCode
254793
+ );
254585
254794
 
254586
254795
  // worker/api/services/index.ts
254587
254796
  var services_exports = {};
@@ -254602,6 +254811,7 @@ __export(services_exports, {
254602
254811
  getAllDeviceIds: () => getAllDeviceIds,
254603
254812
  getAllGroupIds: () => getAllGroupIds,
254604
254813
  getAppId: () => getAppId,
254814
+ getCachedDevice: () => getCachedDevice,
254605
254815
  getDebugMode: () => getDebugMode,
254606
254816
  getDeviceId: () => getDeviceId,
254607
254817
  getDeviceInfo: () => getDeviceInfo,
@@ -256093,6 +256303,12 @@ var isEqual2 = (a2, b2) => {
256093
256303
  return false;
256094
256304
  return keys.every((k2) => isEqual2(a2[k2], b2[k2]));
256095
256305
  };
256306
+ function isNumeric(str) {
256307
+ if (typeof str != "string")
256308
+ return false;
256309
+ return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
256310
+ !isNaN(parseFloat(str));
256311
+ }
256096
256312
 
256097
256313
  // worker/api/services/parseI18nCheckResult.ts
256098
256314
  var import_lodash4 = __toESM(require_lodash());
@@ -269411,10 +269627,15 @@ var publishDps = async ({ deviceId, dps }, cb) => {
269411
269627
  }
269412
269628
  let error = false;
269413
269629
  if (devId) {
269414
- const devInfo = await getDeviceInfo({ deviceId: devId });
269415
- const { schema } = devInfo?.result || {};
269630
+ let devInfo = getCachedDevice()[devId];
269631
+ if (!devInfo) {
269632
+ devInfo = await getDeviceInfo({ deviceId: devId });
269633
+ devInfo = devInfo?.result;
269634
+ }
269635
+ const { schema } = devInfo || {};
269416
269636
  if (schema) {
269417
- JSON.parse(schema).map((item) => {
269637
+ const s2 = typeof schema === "string" ? JSON.parse(schema) : schema;
269638
+ s2.map((item) => {
269418
269639
  const { id, code, property, type: oType } = item;
269419
269640
  const { type } = property || {};
269420
269641
  if (Object.keys(dps).includes(`${id}`) && (type === "raw" || oType === "raw") && isHexString(dps[id])) {
@@ -269430,6 +269651,7 @@ var publishDps = async ({ deviceId, dps }, cb) => {
269430
269651
  }
269431
269652
  });
269432
269653
  }
269654
+ console.log("00000000000000", dps);
269433
269655
  if (Object.keys(dps).length === 0 || error) {
269434
269656
  cb && cb(error ? "number_publish_error" : "dps_is_empty");
269435
269657
  return false;
@@ -269477,15 +269699,19 @@ var publishGroupDps = async (params, cb) => {
269477
269699
  });
269478
269700
  return;
269479
269701
  }
269480
- let groupId = await getGroupId();
269481
- if (!groupId)
269482
- groupId = gid;
269702
+ let groupId = gid;
269703
+ if (!groupId) {
269704
+ groupId = await getGroupId();
269705
+ }
269483
269706
  let error = false;
269484
269707
  if (groupId) {
269485
- const devInfo = await getGroupInfo({ groupId });
269486
- const { schema } = devInfo?.result || {};
269708
+ if (!getCachedGroup(groupId)) {
269709
+ await getGroupInfo({ groupId });
269710
+ }
269711
+ const groupInfo2 = getCachedGroup(groupId);
269712
+ const { schema } = groupInfo2 || {};
269487
269713
  if (schema) {
269488
- JSON.parse(schema).map((item) => {
269714
+ schema.map((item) => {
269489
269715
  const { id, code, property, type: oType } = item;
269490
269716
  const { type } = property || {};
269491
269717
  if (Object.keys(dps).includes(`${id}`) && (type === "raw" || oType === "raw") && isHexString(dps[id])) {
@@ -269515,10 +269741,10 @@ var publishGroupDps = async (params, cb) => {
269515
269741
  },
269516
269742
  meta: {
269517
269743
  bizType: "ide",
269518
- gid: devInfo.data?.ownerId
269744
+ gid: groupInfo2.ownerId
269519
269745
  }
269520
269746
  });
269521
- console.log("publish", groupId, devInfo.data?.ownerId, dps, result);
269747
+ console.log("publish", groupId, groupInfo2.ownerId, dps, result);
269522
269748
  if (result.result) {
269523
269749
  cb && cb(null);
269524
269750
  return true;
@@ -269536,13 +269762,10 @@ var publishGroupDps = async (params, cb) => {
269536
269762
  var import_lodash5 = __toESM(require_lodash());
269537
269763
  var deviceInfo = null;
269538
269764
  var cachedDeviceList = null;
269539
- var cachedDevices = {};
269540
- function getCachedDevice() {
269541
- return cachedDevices;
269542
- }
269765
+ var cachedDevices2 = getCachedDevice();
269543
269766
  function updateCachedDevice(devId, dps) {
269544
- if (cachedDevices[devId]) {
269545
- const { schema } = cachedDevices[devId];
269767
+ if (cachedDevices2[devId]) {
269768
+ const { schema } = cachedDevices2[devId];
269546
269769
  const dpCodes = {};
269547
269770
  Object.keys(dps).map((dpId) => {
269548
269771
  const sch = schema.find((item) => item.id == dpId);
@@ -269550,18 +269773,18 @@ function updateCachedDevice(devId, dps) {
269550
269773
  dpCodes[sch.code] = dps[dpId];
269551
269774
  }
269552
269775
  });
269553
- cachedDevices[devId].dps = {
269554
- ...cachedDevices[devId].dps,
269776
+ cachedDevices2[devId].dps = {
269777
+ ...cachedDevices2[devId].dps,
269555
269778
  ...dps
269556
269779
  };
269557
- cachedDevices[devId].dpCodes = {
269558
- ...cachedDevices[devId].dpCodes,
269780
+ cachedDevices2[devId].dpCodes = {
269781
+ ...cachedDevices2[devId].dpCodes,
269559
269782
  ...dpCodes
269560
269783
  };
269561
269784
  }
269562
269785
  }
269563
269786
  function removeCachedDevice(devId) {
269564
- delete cachedDevices[devId];
269787
+ delete cachedDevices2[devId];
269565
269788
  }
269566
269789
  async function getDeviceInfo2(params) {
269567
269790
  const { deviceId } = params;
@@ -269573,12 +269796,12 @@ async function getDeviceInfo2(params) {
269573
269796
  errorMsg: import_TYUniCode2.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.des
269574
269797
  };
269575
269798
  }
269576
- if (cachedDevices[deviceId]) {
269577
- if (projectDeviceId === cachedDevices[deviceId].devId) {
269578
- deviceInfo = cachedDevices[deviceId];
269799
+ if (cachedDevices2[deviceId]) {
269800
+ if (projectDeviceId === cachedDevices2[deviceId].devId) {
269801
+ deviceInfo = cachedDevices2[deviceId];
269579
269802
  }
269580
269803
  return {
269581
- data: cachedDevices[deviceId],
269804
+ data: cachedDevices2[deviceId],
269582
269805
  errorCode: 0,
269583
269806
  errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
269584
269807
  };
@@ -269667,7 +269890,7 @@ async function getDeviceInfo2(params) {
269667
269890
  delete result["gwType"];
269668
269891
  delete result["dpMaxTime"];
269669
269892
  delete result["i18nTime"];
269670
- cachedDevices[deviceId] = result;
269893
+ cachedDevices2[deviceId] = result;
269671
269894
  const returnData = { ...result };
269672
269895
  delete returnData["localKey"];
269673
269896
  return {
@@ -269679,25 +269902,45 @@ async function getDeviceInfo2(params) {
269679
269902
  async function publishDps2(params) {
269680
269903
  const { deviceId, dps } = params;
269681
269904
  try {
269682
- if (cachedDevices[deviceId]) {
269683
- const { schema } = cachedDevices[deviceId];
269905
+ let dev = cachedDevices2[deviceId];
269906
+ if (!dev) {
269907
+ await getDeviceInfo2({ deviceId });
269908
+ dev = cachedDevices2[deviceId];
269909
+ }
269910
+ let _dps = { ...dps };
269911
+ if (dev) {
269912
+ const { schema } = dev;
269684
269913
  const idCodes = {};
269914
+ const codeIds = {};
269685
269915
  schema.map((item) => {
269686
269916
  idCodes[item.id] = item.code;
269917
+ codeIds[item.code] = item.id;
269687
269918
  });
269688
269919
  const publish = {};
269920
+ const pudp = {};
269689
269921
  Object.keys(dps).map((key) => {
269690
- const code2 = idCodes[key];
269691
- publish[code2] = dps[key];
269922
+ if (isNumeric(key)) {
269923
+ const code2 = idCodes[key];
269924
+ publish[code2] = dps[key];
269925
+ } else {
269926
+ publish[key] = dps[key];
269927
+ pudp[codeIds[key]] = dps[key];
269928
+ }
269692
269929
  });
269693
269930
  ark.runtime.sendMessage(
269694
269931
  JSON.stringify({ type: "publishDps", value: publish, protocol: 5 })
269695
269932
  );
269933
+ if (Object.keys(pudp).length > 0) {
269934
+ _dps = pudp;
269935
+ }
269696
269936
  }
269937
+ console.log("--------result publishDpsWithMqtt", deviceId, _dps);
269697
269938
  let reason;
269698
- const result = await publishDps({ deviceId, dps }, (err) => {
269939
+ const result = await publishDps({ deviceId, dps: _dps }, (err) => {
269699
269940
  reason = err;
269941
+ console.log("--------error", err);
269700
269942
  });
269943
+ console.log("--------result", result, reason);
269701
269944
  let code = 0, msg = import_TYUniCode2.TYUniPluginError.SUCCESS.des;
269702
269945
  if (reason || !result) {
269703
269946
  switch (reason) {
@@ -269830,7 +270073,7 @@ function registerDeviceListListener(params) {
269830
270073
  console.log("------get success");
269831
270074
  list.map(({ data }) => {
269832
270075
  const { devId } = data;
269833
- initMqttClient_default.addDeviceListener(cachedDevices[devId]);
270076
+ initMqttClient_default.addDeviceListener(cachedDevices2[devId]);
269834
270077
  });
269835
270078
  }).catch((err) => {
269836
270079
  console.log("---------registerDeviceListListener failed", err);
@@ -269927,21 +270170,166 @@ async function getDeviceListByDevIds(params) {
269927
270170
  errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
269928
270171
  };
269929
270172
  }
270173
+ async function getDeviceWifiActivatorStatus(params) {
270174
+ const { deviceId } = params;
270175
+ let devInfo = cachedDevices2[deviceId];
270176
+ if (!devInfo) {
270177
+ await getDeviceInfo2({ deviceId });
270178
+ devInfo = cachedDevices2[deviceId];
270179
+ }
270180
+ return {
270181
+ data: { wifiActivator: !(devInfo?.meta?.wifiEnable === false) },
270182
+ errorCode: 0,
270183
+ errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
270184
+ };
270185
+ }
270186
+ async function getDeviceOnlineType(params) {
270187
+ const { deviceId } = params;
270188
+ let devInfo = cachedDevices2[deviceId];
270189
+ if (!devInfo) {
270190
+ await getDeviceInfo2({ deviceId });
270191
+ devInfo = cachedDevices2[deviceId];
270192
+ }
270193
+ const { isLocalOnline, isCloudOnline, isOnline, capability } = devInfo;
270194
+ const isBle = !!getBitValue(capability, 10);
270195
+ const isBleMesh = !!getBitValue(capability, 11);
270196
+ const isSigMesh = !!getBitValue(capability, 15);
270197
+ const isBleBeacon = !!getBitValue(capability, 21);
270198
+ let onlineType = 0;
270199
+ if (isOnline || isLocalOnline) {
270200
+ onlineType = onlineType | 1 << 0;
270201
+ }
270202
+ console.log(
270203
+ "================ type",
270204
+ onlineType,
270205
+ capability,
270206
+ isBle,
270207
+ isBleMesh,
270208
+ isSigMesh,
270209
+ isBleBeacon
270210
+ );
270211
+ if (isBle && isLocalOnline) {
270212
+ console.log("================ ble", onlineType, 1 < 2);
270213
+ onlineType = onlineType | 1 << 2;
270214
+ }
270215
+ if ((isBleMesh || isSigMesh) && isLocalOnline) {
270216
+ console.log("================ mesh", onlineType, 1 < 3);
270217
+ onlineType = onlineType | 1 << 3;
270218
+ }
270219
+ if (isBleBeacon && isLocalOnline) {
270220
+ console.log("================ beacon", onlineType, 1 < 4);
270221
+ onlineType = onlineType | 1 << 4;
270222
+ }
270223
+ return {
270224
+ data: { onlineType },
270225
+ errorCode: 0,
270226
+ errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
270227
+ };
270228
+ }
270229
+ async function getShareDeviceInfo(params) {
270230
+ const { deviceId } = params;
270231
+ const result = await apiRequestByAtop({
270232
+ api: "tuya.m.sharing.sharer.resowner.find",
270233
+ version: "1.0",
270234
+ params: {
270235
+ resId: deviceId,
270236
+ resType: "device"
270237
+ }
270238
+ });
270239
+ console.log("----------6c089f69ce17af46bazi3v", deviceId, result);
270240
+ const data = { ...result.result };
270241
+ const r2 = {
270242
+ name: void 0,
270243
+ email: void 0,
270244
+ mobile: void 0
270245
+ };
270246
+ if (Object.keys(data)) {
270247
+ r2.name = data.name;
270248
+ r2.email = data.email;
270249
+ r2.mobile = data.phone;
270250
+ }
270251
+ return {
270252
+ data: { ...r2 },
270253
+ errorCode: 0,
270254
+ errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
270255
+ };
270256
+ }
270257
+ async function requestAdvancedCapability(params) {
270258
+ const { bizId, bizType, vasCodes } = params;
270259
+ const homeId = await getHomeId();
270260
+ const result = await apiRequestByAtop({
270261
+ api: "s.m.dev.property.get",
270262
+ version: "1.0",
270263
+ params: {
270264
+ bizId,
270265
+ bizType,
270266
+ vasCodes,
270267
+ gid: homeId
270268
+ },
270269
+ meta: {
270270
+ gid: homeId
270271
+ }
270272
+ });
270273
+ return {
270274
+ data: result.result,
270275
+ errorCode: 0,
270276
+ errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
270277
+ };
270278
+ }
270279
+ var dbDataChangeCb = null;
270280
+ function onDpDataChange(cb) {
270281
+ dbDataChangeCb = cb;
270282
+ console.log("-------------onDpDataChange", cb);
270283
+ return {
270284
+ data: null,
270285
+ errorCode: 0,
270286
+ errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
270287
+ };
270288
+ }
270289
+ function offDpDataChange() {
270290
+ dbDataChangeCb = null;
270291
+ return {
270292
+ data: null,
270293
+ errorCode: 0,
270294
+ errorMsg: import_TYUniCode2.TYUniPluginError.SUCCESS.des
270295
+ };
270296
+ }
269930
270297
  ark.miniapp.addPluginMethod(
269931
270298
  "TUNIDeviceControlManager",
269932
270299
  "getDeviceInfo",
269933
270300
  getDeviceInfo2
269934
270301
  );
270302
+ ark.miniapp.addPluginMethod(
270303
+ "TUNIDeviceDetailManager",
270304
+ "getShareDeviceInfo",
270305
+ getShareDeviceInfo
270306
+ );
269935
270307
  ark.miniapp.addPluginMethod(
269936
270308
  "TUNIDeviceControlManager",
269937
270309
  "getProductInfo",
269938
270310
  getProductInfo2
269939
270311
  );
270312
+ ark.miniapp.addPluginMethod(
270313
+ "TUNIDeviceControlManager",
270314
+ "onDpDataChange",
270315
+ onDpDataChange
270316
+ );
270317
+ ark.miniapp.onPluginEvent("onDpDataChange", onDpDataChange);
270318
+ ark.miniapp.addPluginMethod(
270319
+ "TUNIDeviceControlManager",
270320
+ "offDpDataChange",
270321
+ offDpDataChange
270322
+ );
269940
270323
  ark.miniapp.addPluginMethod(
269941
270324
  "TUNIDeviceControlManager",
269942
270325
  "publishDps",
269943
270326
  publishDps2
269944
270327
  );
270328
+ ark.miniapp.addPluginMethod(
270329
+ "TUNIDeviceControlManager",
270330
+ "publishDpsWithPipeType",
270331
+ publishDps2
270332
+ );
269945
270333
  ark.miniapp.addPluginMethod(
269946
270334
  "TUNIThingControlManager",
269947
270335
  "getDeviceThingModelInfo",
@@ -269978,6 +270366,36 @@ ark.miniapp.addPluginMethod(
269978
270366
  "publishDps",
269979
270367
  publishDps2
269980
270368
  );
270369
+ ark.miniapp.addPluginMethod(
270370
+ "TYUniDeviceControlManager",
270371
+ "publishCommands",
270372
+ publishDps2
270373
+ );
270374
+ ark.miniapp.addPluginMethod(
270375
+ "TUNIDeviceControlManager",
270376
+ "publishCommands",
270377
+ publishDps2
270378
+ );
270379
+ ark.miniapp.addPluginMethod(
270380
+ "TUNIDeviceActivationManager",
270381
+ "getDeviceWifiActivatorStatus",
270382
+ getDeviceWifiActivatorStatus
270383
+ );
270384
+ ark.miniapp.addPluginMethod(
270385
+ "TUNIDeviceActivationManager",
270386
+ "getDeviceWifiActivatorStatus",
270387
+ getDeviceWifiActivatorStatus
270388
+ );
270389
+ ark.miniapp.addPluginMethod(
270390
+ "TYUniDeviceControlManager",
270391
+ "getDeviceOnlineType",
270392
+ getDeviceOnlineType
270393
+ );
270394
+ ark.miniapp.addPluginMethod(
270395
+ "TUNIDeviceControlManager",
270396
+ "getDeviceOnlineType",
270397
+ getDeviceOnlineType
270398
+ );
269981
270399
  ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "queryDps", queryDps2);
269982
270400
  ark.miniapp.addPluginMethod(
269983
270401
  "TYUniDeviceControlManager",
@@ -270019,6 +270437,11 @@ ark.miniapp.addPluginMethod(
270019
270437
  "unregisterMQTTProtocolListener",
270020
270438
  registerMQTTProtocolListener
270021
270439
  );
270440
+ ark.miniapp.addPluginMethod(
270441
+ "TUNIDeviceControlManager",
270442
+ "requestAdvancedCapability",
270443
+ requestAdvancedCapability
270444
+ );
270022
270445
  ark.miniapp.addPluginMethod(
270023
270446
  "TUNIOTAManager",
270024
270447
  "registerOTACompleted",
@@ -270558,8 +270981,280 @@ ark.miniapp.addPluginMethod(
270558
270981
  getDeviceIdList
270559
270982
  );
270560
270983
 
270561
- // worker/api/Bridge.ts
270984
+ // worker/api/TUNIDeviceDetailManager.ts
270562
270985
  var import_TYUniCode10 = __toESM(require_dist());
270986
+ async function addTimer(params) {
270987
+ const {
270988
+ deviceId,
270989
+ groupId,
270990
+ category,
270991
+ timer: { loops, time, dps, isAppPush, aliasName }
270992
+ } = params;
270993
+ if (!deviceId && !groupId) {
270994
+ if (!groupId) {
270995
+ return {
270996
+ errorCode: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.code,
270997
+ errorMsg: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.des,
270998
+ data: null
270999
+ };
271000
+ }
271001
+ }
271002
+ try {
271003
+ const data = await apiRequestByAtop({
271004
+ api: "tuya.m.clock.dps.add",
271005
+ version: "1.0",
271006
+ params: {
271007
+ bizId: deviceId || groupId,
271008
+ bizType: deviceId ? 0 : 1,
271009
+ loops,
271010
+ category,
271011
+ status: 1,
271012
+ actions: {
271013
+ dps,
271014
+ time
271015
+ },
271016
+ isAppPush,
271017
+ aliasName
271018
+ }
271019
+ });
271020
+ return {
271021
+ data: {
271022
+ timerId: data.result
271023
+ },
271024
+ errorCode: 0,
271025
+ errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
271026
+ };
271027
+ } catch (error) {
271028
+ return {
271029
+ data: null,
271030
+ errorCode: error.innerError.errorCode,
271031
+ errorMsg: error.innerError.errorMsg
271032
+ };
271033
+ }
271034
+ }
271035
+ async function updateTimer(params) {
271036
+ const {
271037
+ deviceId,
271038
+ groupId,
271039
+ category,
271040
+ timer: { loops, time, dps, isAppPush, aliasName, timerId }
271041
+ } = params;
271042
+ if (!deviceId && !groupId) {
271043
+ if (!groupId) {
271044
+ return {
271045
+ errorCode: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.code,
271046
+ errorMsg: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.des,
271047
+ data: null
271048
+ };
271049
+ }
271050
+ }
271051
+ try {
271052
+ const data = await apiRequestByAtop({
271053
+ api: "tuya.m.clock.dps.update",
271054
+ version: "1.0",
271055
+ params: {
271056
+ bizId: deviceId || groupId,
271057
+ bizType: deviceId ? 0 : 1,
271058
+ id: timerId,
271059
+ loops,
271060
+ category,
271061
+ status: 1,
271062
+ actions: {
271063
+ dps,
271064
+ time
271065
+ },
271066
+ isAppPush,
271067
+ aliasName
271068
+ }
271069
+ });
271070
+ return {
271071
+ data: void 0,
271072
+ errorCode: 0,
271073
+ errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
271074
+ };
271075
+ } catch (error) {
271076
+ return {
271077
+ data: null,
271078
+ errorCode: error.innerError.errorCode,
271079
+ errorMsg: error.innerError.errorMsg
271080
+ };
271081
+ }
271082
+ }
271083
+ async function updateTimerStatus(params) {
271084
+ const { deviceId, groupId, timerId, status } = params;
271085
+ if (!deviceId && !groupId) {
271086
+ if (!groupId) {
271087
+ return {
271088
+ errorCode: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.code,
271089
+ errorMsg: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.des,
271090
+ data: null
271091
+ };
271092
+ }
271093
+ }
271094
+ try {
271095
+ await apiRequestByAtop({
271096
+ api: "tuya.m.clock.batch.status.update",
271097
+ version: "1.0",
271098
+ params: {
271099
+ bizId: deviceId || groupId,
271100
+ bizType: deviceId ? 0 : 1,
271101
+ ids: timerId,
271102
+ status: status === true ? 1 : 0
271103
+ }
271104
+ });
271105
+ ark.miniapp.emitPluginEvent({
271106
+ name: "RCTNativeAppEventEmitter.linkageTimeUpdate",
271107
+ data: null
271108
+ });
271109
+ ark.miniapp.emitPluginEvent({
271110
+ name: "TUNIDeviceDetailManager.onTimerUpdate",
271111
+ data: null
271112
+ });
271113
+ return {
271114
+ data: void 0,
271115
+ errorCode: 0,
271116
+ errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
271117
+ };
271118
+ } catch (error) {
271119
+ return {
271120
+ data: void 0,
271121
+ errorCode: error.innerError.errorCode,
271122
+ errorMsg: error.innerError.errorMsg
271123
+ };
271124
+ }
271125
+ }
271126
+ async function removeTimer(params) {
271127
+ const { deviceId, groupId, timerId } = params;
271128
+ if (!deviceId && !groupId) {
271129
+ if (!groupId) {
271130
+ return {
271131
+ errorCode: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.code,
271132
+ errorMsg: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.des,
271133
+ data: null
271134
+ };
271135
+ }
271136
+ }
271137
+ try {
271138
+ await apiRequestByAtop({
271139
+ api: "tuya.m.clock.batch.status.update",
271140
+ version: "1.0",
271141
+ params: {
271142
+ bizId: deviceId || groupId,
271143
+ bizType: deviceId ? 0 : 1,
271144
+ ids: timerId,
271145
+ status: 2
271146
+ }
271147
+ });
271148
+ ark.miniapp.emitPluginEvent({
271149
+ name: "RCTNativeAppEventEmitter.linkageTimeUpdate",
271150
+ data: null
271151
+ });
271152
+ ark.miniapp.emitPluginEvent({
271153
+ name: "TUNIDeviceDetailManager.onTimerUpdate",
271154
+ data: null
271155
+ });
271156
+ return {
271157
+ data: void 0,
271158
+ errorCode: 0,
271159
+ errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
271160
+ };
271161
+ } catch (error) {
271162
+ return {
271163
+ data: void 0,
271164
+ errorCode: error.innerError.errorCode,
271165
+ errorMsg: error.innerError.errorMsg
271166
+ };
271167
+ }
271168
+ }
271169
+ async function syncTimerTask(params) {
271170
+ const { deviceId, groupId, category } = params;
271171
+ if (!deviceId && !groupId) {
271172
+ if (!groupId) {
271173
+ return {
271174
+ errorCode: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.code,
271175
+ errorMsg: import_TYUniCode10.TYUniPluginError.DEVICEKIT_DEVICE_ID_AND_GROUP_ID_INVALID.des,
271176
+ data: null
271177
+ };
271178
+ }
271179
+ }
271180
+ const data = await apiRequestByAtop({
271181
+ api: "tuya.m.clock.dps.list",
271182
+ version: "2.0",
271183
+ params: {
271184
+ bizId: deviceId || groupId,
271185
+ bizType: deviceId ? 0 : 1
271186
+ }
271187
+ });
271188
+ const list = [];
271189
+ const parseTimer = (item) => {
271190
+ const {
271191
+ aliasName,
271192
+ date,
271193
+ dps,
271194
+ id,
271195
+ isAppPush,
271196
+ loops,
271197
+ status,
271198
+ time,
271199
+ timezoneId,
271200
+ groupOrder
271201
+ } = item;
271202
+ return {
271203
+ aliasName,
271204
+ date,
271205
+ dps: JSON.parse(dps),
271206
+ id: `${id}`,
271207
+ isAppPush,
271208
+ loops,
271209
+ status: !!status,
271210
+ time,
271211
+ timeId: `${id}`,
271212
+ timezoneId
271213
+ };
271214
+ };
271215
+ if (!!category) {
271216
+ data.result?.filter((l2) => l2.category === category).map((cate) => {
271217
+ const { timers } = cate;
271218
+ const t2 = timers.map(parseTimer);
271219
+ list.push(...t2);
271220
+ });
271221
+ } else {
271222
+ data.result?.map((cate) => {
271223
+ const { timers } = cate;
271224
+ const t2 = timers.map(parseTimer);
271225
+ list.push(...t2);
271226
+ });
271227
+ }
271228
+ return {
271229
+ data: { timers: list },
271230
+ errorCode: 0,
271231
+ errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
271232
+ };
271233
+ }
271234
+ ark.miniapp.addPluginMethod(
271235
+ "TUNIDeviceDetailManager",
271236
+ "syncTimerTask",
271237
+ syncTimerTask
271238
+ );
271239
+ ark.miniapp.addPluginMethod("TUNIDeviceDetailManager", "addTimer", addTimer);
271240
+ ark.miniapp.addPluginMethod(
271241
+ "TUNIDeviceDetailManager",
271242
+ "updateTimer",
271243
+ updateTimer
271244
+ );
271245
+ ark.miniapp.addPluginMethod(
271246
+ "TUNIDeviceDetailManager",
271247
+ "updateTimerStatus",
271248
+ updateTimerStatus
271249
+ );
271250
+ ark.miniapp.addPluginMethod(
271251
+ "TUNIDeviceDetailManager",
271252
+ "removeTimer",
271253
+ removeTimer
271254
+ );
271255
+
271256
+ // worker/api/Bridge.ts
271257
+ var import_TYUniCode11 = __toESM(require_dist());
270563
271258
  var bridgeWall = {
270564
271259
  // 向小程序发送消息
270565
271260
  send(event, payload) {
@@ -270582,7 +271277,7 @@ async function handle(params) {
270582
271277
  return {
270583
271278
  data: { status: 0 },
270584
271279
  errorCode: 0,
270585
- errorMsg: import_TYUniCode10.TYUniPluginError.SUCCESS.des
271280
+ errorMsg: import_TYUniCode11.TYUniPluginError.SUCCESS.des
270586
271281
  };
270587
271282
  } else {
270588
271283
  return checkOTAUpgradeStatus(params);
@@ -270707,11 +271402,16 @@ ark.runtime.onMessage(async (event) => {
270707
271402
  async function initLaunchParams() {
270708
271403
  onUpdateListener && onUpdateListener();
270709
271404
  const status = await ark.auth.checkStatus();
271405
+ console.log("authorized:", status);
270710
271406
  if (status !== "authorized")
270711
271407
  return;
271408
+ console.log("to get device or group id");
270712
271409
  let deviceId = await services_default.getDeviceId();
271410
+ console.log(" got device id", deviceId);
270713
271411
  const groupId = await services_default.getGroupId();
271412
+ console.log(" got group id", groupId);
270714
271413
  const mode = await services_default.getDebugMode();
271414
+ console.log(" got dev mode", mode);
270715
271415
  let deviceInfo2 = null, groupInfo2 = null;
270716
271416
  if (groupId && mode === "group") {
270717
271417
  const gd = await getGroupInfo({ groupId });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/ark-extension-virtual-device",
3
- "version": "1.5.0-beta-2",
3
+ "version": "1.5.0-beta-3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "manifest.json",