@tuya-miniapp/ark-extension-virtual-device 0.0.2 → 0.0.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.
@@ -21338,7 +21338,12 @@ var services_exports = {};
21338
21338
  __export(services_exports, {
21339
21339
  apiRequestByAtop: () => apiRequestByAtop,
21340
21340
  apiRequestByBusinessAtop: () => apiRequestByBusinessAtop,
21341
+ bluetoothIsOn: () => bluetoothIsOn,
21341
21342
  clearProjectInfo: () => clearProjectInfo,
21343
+ emitBleConnectStatus: () => emitBleConnectStatus,
21344
+ emitBluetoothState: () => emitBluetoothState,
21345
+ emitDarkState: () => emitDarkState,
21346
+ emitDeviceOnlineState: () => emitDeviceOnlineState,
21342
21347
  emitNetworkState: () => emitNetworkState,
21343
21348
  getDeviceInfo: () => getDeviceInfo,
21344
21349
  getDeviceMqttInfo: () => getDeviceMqttInfo,
@@ -21497,6 +21502,150 @@ var viewLog = (message) => {
21497
21502
  }));
21498
21503
  };
21499
21504
 
21505
+ // worker/api/TYUniDeviceControlManager.ts
21506
+ var import_TYUniCode = __toESM(require_dist());
21507
+
21508
+ // worker/api/services/queryDps.ts
21509
+ var queryDps = async ({ deviceId, dpIds }) => {
21510
+ const deviceInfo2 = await getDeviceInfo({ "deviceId": deviceId });
21511
+ const dps = deviceInfo2?.result?.dps || {};
21512
+ const schema = JSON.parse(deviceInfo2?.result?.schema || "[]");
21513
+ JSON.parse(schema).map((item) => {
21514
+ const { id, code, property } = item;
21515
+ const { type } = property || {};
21516
+ if (type === "raw") {
21517
+ const b = Buffer.from(dps[id], "base64");
21518
+ dps[id] = b.toString("hex");
21519
+ }
21520
+ });
21521
+ const result = {};
21522
+ for (const dpId of dpIds) {
21523
+ result[dpId] = dps[dpId];
21524
+ }
21525
+ return result;
21526
+ };
21527
+
21528
+ // worker/api/TYUniDeviceControlManager.ts
21529
+ var deviceInfo = null;
21530
+ async function getDeviceInfo2(params) {
21531
+ const { deviceId } = params;
21532
+ if (!deviceId) {
21533
+ return {
21534
+ data: null,
21535
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.code,
21536
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.des
21537
+ };
21538
+ }
21539
+ const response = await getDeviceInfo({ deviceId });
21540
+ const { result: devInfo } = response || {};
21541
+ let product = {};
21542
+ try {
21543
+ const presponse = await getProductInfo({ productIds: [devInfo.productId] });
21544
+ const { result: productInfo } = presponse || {};
21545
+ product = productInfo[0] || {};
21546
+ } catch (e) {
21547
+ console.log("\u672A\u83B7\u53D6\u5230\u4EA7\u54C1\u4FE1\u606F");
21548
+ }
21549
+ if (!devInfo) {
21550
+ return {
21551
+ data: null,
21552
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.code,
21553
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.des
21554
+ };
21555
+ }
21556
+ const { dps, schema } = devInfo;
21557
+ const objSchema = {};
21558
+ JSON.parse(schema).map((item) => {
21559
+ const { id, code, property } = item;
21560
+ const { type } = property || {};
21561
+ if (Object.keys(dps).includes(`${id}`) && type === "raw") {
21562
+ const b = Buffer.from(dps[id], "base64");
21563
+ dps[id] = b.toString("hex");
21564
+ }
21565
+ objSchema[code] = dps[id];
21566
+ });
21567
+ deviceInfo = {
21568
+ ...devInfo,
21569
+ dps,
21570
+ dpCodes: objSchema,
21571
+ deviceOnline: devInfo.isOnline,
21572
+ icon: devInfo.iconUrl,
21573
+ schema: JSON.parse(devInfo.schema),
21574
+ capability: product.capability
21575
+ };
21576
+ return {
21577
+ data: deviceInfo,
21578
+ errorCode: 0,
21579
+ errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des
21580
+ };
21581
+ }
21582
+ async function publishDps2(params) {
21583
+ const { deviceId, dps } = params;
21584
+ const { schema } = deviceInfo || {};
21585
+ schema.map((item) => {
21586
+ const { id, code, property } = item;
21587
+ const { type } = property || {};
21588
+ if (Object.keys(dps).includes(`${id}`) && type === "raw") {
21589
+ const b = Buffer.from(dps[id], "hex");
21590
+ dps[id] = b.toString("base64");
21591
+ }
21592
+ });
21593
+ try {
21594
+ await publishDps({ deviceId, dps });
21595
+ ark.runtime.sendMessage(JSON.stringify({
21596
+ type: "mqtt",
21597
+ value: dps
21598
+ }));
21599
+ return {
21600
+ errorCode: 0,
21601
+ errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des,
21602
+ data: null
21603
+ };
21604
+ } catch (e) {
21605
+ return {
21606
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_PUBLISH_DPS_ERROR.code,
21607
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_PUBLISH_DPS_ERROR.des,
21608
+ data: e
21609
+ };
21610
+ }
21611
+ }
21612
+ async function getProductInfo2(params) {
21613
+ try {
21614
+ const productInfo = await getProductInfo({ productIds: [params.productId] });
21615
+ return {
21616
+ data: productInfo.result[0],
21617
+ errorCode: !!productInfo ? 0 : import_TYUniCode.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.code,
21618
+ errorMsg: !!productInfo ? import_TYUniCode.TYUniPluginError.SUCCESS.des : import_TYUniCode.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.des
21619
+ };
21620
+ } catch (e) {
21621
+ return {
21622
+ data: null,
21623
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.code,
21624
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.des
21625
+ };
21626
+ }
21627
+ }
21628
+ async function queryDps2(params) {
21629
+ try {
21630
+ const dps = await queryDps(params);
21631
+ return {
21632
+ data: dps,
21633
+ errorCode: !!dps ? 0 : import_TYUniCode.TYUniPluginError.DEVICEKIT_QUERY_DPS_ERROR.code,
21634
+ errorMsg: !!dps ? import_TYUniCode.TYUniPluginError.SUCCESS.des : import_TYUniCode.TYUniPluginError.DEVICEKIT_QUERY_DPS_ERROR.des
21635
+ };
21636
+ } catch (e) {
21637
+ return {
21638
+ data: null,
21639
+ errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_QUERY_DPS_ERROR.code,
21640
+ errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_QUERY_DPS_ERROR.des
21641
+ };
21642
+ }
21643
+ }
21644
+ ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "getDeviceInfo", getDeviceInfo2);
21645
+ ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "getProductInfo", getProductInfo2);
21646
+ ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "publishDps", publishDps2);
21647
+ ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "queryDps", queryDps2);
21648
+
21500
21649
  // worker/api/services/publishDps.ts
21501
21650
  var publishDps = async ({ deviceId, dps }) => {
21502
21651
  const manager = DpMqttManager.getInstance();
@@ -21529,6 +21678,15 @@ var publishDps = async ({ deviceId, dps }) => {
21529
21678
  const message = JSON.stringify(upData);
21530
21679
  console.log("publish", outTopic, message);
21531
21680
  client.publish(outTopic, message, () => {
21681
+ const { schema = {} } = deviceInfo || {};
21682
+ schema.map((item) => {
21683
+ const { id, property } = item;
21684
+ const { type } = property || {};
21685
+ if (Object.keys(dps).includes(`${id}`) && type === "raw") {
21686
+ const b = Buffer.from(dps[id], "base64");
21687
+ dps[id] = b.toString("hex");
21688
+ }
21689
+ });
21532
21690
  ark.miniapp.emitPluginEvent({
21533
21691
  name: "TYUniDeviceControlManager.onDpDataChange",
21534
21692
  data: {
@@ -21542,17 +21700,6 @@ var publishDps = async ({ deviceId, dps }) => {
21542
21700
  }
21543
21701
  };
21544
21702
 
21545
- // worker/api/services/queryDps.ts
21546
- var queryDps = async ({ deviceId, dpIds }) => {
21547
- const deviceInfo2 = await getDeviceInfo({ "deviceId": deviceId });
21548
- const dps = deviceInfo2?.result?.dps || {};
21549
- const result = {};
21550
- for (const dpId of dpIds) {
21551
- result[dpId] = dps[dpId];
21552
- }
21553
- return result;
21554
- };
21555
-
21556
21703
  // worker/api/services/saveProjectInfo.ts
21557
21704
  var saveProjectInfo = async ({ deviceId, productId }) => {
21558
21705
  await ark.storage.set(productId, JSON.stringify({
@@ -21566,7 +21713,20 @@ var saveProjectInfo = async ({ deviceId, productId }) => {
21566
21713
  return { ...JSON.parse(res1), ...JSON.parse(res2) };
21567
21714
  };
21568
21715
 
21569
- // worker/api/services/emitNetworkState.ts
21716
+ // worker/api/services/mockDeviceStatus.ts
21717
+ var bluetoothIsOn = true;
21718
+ var onlineStatus = {
21719
+ online: true,
21720
+ deviceId: "",
21721
+ onlineType: 1
21722
+ };
21723
+ function emitDeviceOnlineState(params) {
21724
+ console.log("--------emitDeviceOnlineState", params);
21725
+ ark.miniapp.emitPluginEvent({
21726
+ name: "TYUniDeviceControlManager.onDeviceOnlineStatusUpdate",
21727
+ data: { ...onlineStatus, ...params }
21728
+ });
21729
+ }
21570
21730
  var networkState = {
21571
21731
  networkType: "WIFI",
21572
21732
  signalStrength: 100,
@@ -21586,6 +21746,31 @@ function emitNetworkState(params) {
21586
21746
  data: { ...networkState, ...params }
21587
21747
  });
21588
21748
  }
21749
+ var bluetoothState = {
21750
+ available: true
21751
+ };
21752
+ function emitBluetoothState(params) {
21753
+ bluetoothIsOn = params.available;
21754
+ ark.miniapp.emitPluginEvent({
21755
+ name: "TYUniPhoneBluetoothManager.bluetoothAdapterStateChange",
21756
+ data: { ...bluetoothState, ...params }
21757
+ });
21758
+ }
21759
+ var bleConnectStatus = {
21760
+ status: "CONNECTED"
21761
+ };
21762
+ function emitBleConnectStatus(params) {
21763
+ ark.miniapp.emitPluginEvent({
21764
+ name: "TYUniBluetoothManager.onTYBLEConnectStatusChange",
21765
+ data: { ...bleConnectStatus, ...params }
21766
+ });
21767
+ }
21768
+ function emitDarkState(params) {
21769
+ ark.miniapp.emitPluginEvent({
21770
+ name: "App.onThemeChange",
21771
+ data: { ...params }
21772
+ });
21773
+ }
21589
21774
 
21590
21775
  // worker/utils/mqtt.ts
21591
21776
  var DpMqttManager = class {
@@ -21675,6 +21860,15 @@ var startMQTT = async ({ productId }) => {
21675
21860
  });
21676
21861
  break;
21677
21862
  case 5:
21863
+ const { schema = {} } = deviceInfo || {};
21864
+ schema.map((item) => {
21865
+ const { id, property } = item;
21866
+ const { type } = property || {};
21867
+ if (Object.keys(dps).includes(`${id}`) && type === "raw") {
21868
+ const b = Buffer.from(dps[id], "base64");
21869
+ dps[id] = b.toString("hex");
21870
+ }
21871
+ });
21678
21872
  ark.miniapp.emitPluginEvent({
21679
21873
  name: "TYUniDeviceControlManager.onDpDataChange",
21680
21874
  data: {
@@ -21720,106 +21914,6 @@ var isJSON = (str) => {
21720
21914
  }
21721
21915
  };
21722
21916
 
21723
- // worker/api/TYUniDeviceControlManager.ts
21724
- var import_TYUniCode = __toESM(require_dist());
21725
- var deviceInfo = null;
21726
- async function getDeviceInfo2(params) {
21727
- const { deviceId } = params;
21728
- if (!deviceId) {
21729
- return {
21730
- data: null,
21731
- errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.code,
21732
- errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.des
21733
- };
21734
- }
21735
- const response = await getDeviceInfo({ deviceId });
21736
- const { result: devInfo } = response || {};
21737
- let product = {};
21738
- try {
21739
- const presponse = await getProductInfo({ productIds: [devInfo.productId] });
21740
- const { result: productInfo } = presponse || {};
21741
- product = productInfo[0] || {};
21742
- } catch (e) {
21743
- console.log("\u672A\u83B7\u53D6\u5230\u4EA7\u54C1\u4FE1\u606F");
21744
- }
21745
- if (!devInfo) {
21746
- return {
21747
- data: null,
21748
- errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.code,
21749
- errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_DEVICE_ID_INVALID.des
21750
- };
21751
- }
21752
- deviceInfo = {
21753
- ...devInfo,
21754
- deviceOnline: devInfo.isOnline,
21755
- icon: devInfo.iconUrl,
21756
- schema: JSON.parse(devInfo.schema),
21757
- capability: product.capability
21758
- };
21759
- return {
21760
- data: deviceInfo,
21761
- errorCode: 0,
21762
- errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des
21763
- };
21764
- }
21765
- async function publishDps2(params) {
21766
- const { deviceId, dps } = params;
21767
- try {
21768
- await publishDps({ deviceId, dps });
21769
- ark.runtime.sendMessage(JSON.stringify({
21770
- type: "mqtt",
21771
- value: dps
21772
- }));
21773
- return {
21774
- errorCode: 0,
21775
- errorMsg: import_TYUniCode.TYUniPluginError.SUCCESS.des,
21776
- data: null
21777
- };
21778
- } catch (e) {
21779
- return {
21780
- errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_PUBLISH_DPS_ERROR.code,
21781
- errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_PUBLISH_DPS_ERROR.des,
21782
- data: e
21783
- };
21784
- }
21785
- }
21786
- async function getProductInfo2(params) {
21787
- try {
21788
- const productInfo = await getProductInfo({ productIds: [params.productId] });
21789
- return {
21790
- data: productInfo.result[0],
21791
- errorCode: !!productInfo ? 0 : import_TYUniCode.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.code,
21792
- errorMsg: !!productInfo ? import_TYUniCode.TYUniPluginError.SUCCESS.des : import_TYUniCode.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.des
21793
- };
21794
- } catch (e) {
21795
- return {
21796
- data: null,
21797
- errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.code,
21798
- errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_PRODUCT_ID_INVALID.des
21799
- };
21800
- }
21801
- }
21802
- async function queryDps2(params) {
21803
- try {
21804
- const dps = await queryDps(params);
21805
- return {
21806
- data: dps,
21807
- errorCode: !!dps ? 0 : import_TYUniCode.TYUniPluginError.DEVICEKIT_QUERY_DPS_ERROR.code,
21808
- errorMsg: !!dps ? import_TYUniCode.TYUniPluginError.SUCCESS.des : import_TYUniCode.TYUniPluginError.DEVICEKIT_QUERY_DPS_ERROR.des
21809
- };
21810
- } catch (e) {
21811
- return {
21812
- data: null,
21813
- errorCode: import_TYUniCode.TYUniPluginError.DEVICEKIT_QUERY_DPS_ERROR.code,
21814
- errorMsg: import_TYUniCode.TYUniPluginError.DEVICEKIT_QUERY_DPS_ERROR.des
21815
- };
21816
- }
21817
- }
21818
- ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "getDeviceInfo", getDeviceInfo2);
21819
- ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "getProductInfo", getProductInfo2);
21820
- ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "publishDps", publishDps2);
21821
- ark.miniapp.addPluginMethod("TYUniDeviceControlManager", "queryDps", queryDps2);
21822
-
21823
21917
  // worker/api/TYUniLocalizationManager.ts
21824
21918
  var import_lodash = __toESM(require_lodash());
21825
21919
  function getLangKey(params) {
@@ -21922,7 +22016,7 @@ function onBluetoothAdapterStateChange(listener) {
21922
22016
  }
21923
22017
  function bluetoothIsPowerOn(params) {
21924
22018
  return {
21925
- data: true,
22019
+ data: bluetoothIsOn,
21926
22020
  errorCode: 0,
21927
22021
  errorMsg: import_TYUniCode3.TYUniPluginError.SUCCESS.des
21928
22022
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-miniapp/ark-extension-virtual-device",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "files": [
5
5
  "manifest.json",
6
6
  "dist/"