智能小程序 Ray 开发智能设备模型面板 SDK —— API 接口汇总(一)

init

描述

根据当前小程序环境启动参数自动获取 deviceId 异步生成一个智能设备模型实例对象。其中第一个类型入参为当前设备的 dp schema 描述,第二个类型入参为自定义的设备 abilities 能力

类型

declare type SmartDeviceModelOptions = {
  deviceId?: string;
  abilities?: SmartDeviceModelAbility;
  mixin?: SmartDeviceModel<ReadonlyDpSchemaList, SmartDeviceModelAbility>[];
  logConfig?: LogConfig;
  /**
   * 智能设备模型拦截器,非稳定 API
   *
   * @unstable
   */
  interceptors?: {
    request?: {
      /**
       * @default [logger]
       */
      publishDps?: PublishDpsInterceptor<any>[];
    };
    response?: {
      /**
       * @default [logger]
       */
      onDpDataChange?: OnDpDataChangeInterceptor<any>[];
      /**
       * @default [logger]
       */
      onDeviceOnlineStatusUpdate?: OnDeviceOnlineStatusUpdateInterceptor<any>[];
      /**
       * @default [logger]
       */
      onDeviceInfoUpdated?: OnDeviceInfoUpdatedInterceptor<any>[];
      /**
       * @default [logger]
       */
      onNetworkStatusChange?: OnNetworkStatusChangeInterceptor<any>[];
      /**
       * @default [logger]
       */
      onBluetoothAdapterStateChange?: OnBluetoothAdapterStateChangeInterceptor<any>[];
    };
  };
};
 
export default class SmartDeviceModel<
  S extends ReadonlyDpSchemaList,
  A extends SmartDeviceModelAbility = SmartDeviceModelAbility,
> {
  static init: <
    S1 extends ReadonlyDpSchemaList,
    A1 extends SmartDeviceModelAbility = SmartDeviceModelAbility,
  >(
    options?: SmartDeviceModelOptions,
  ) => Promise<SmartDeviceModel<S1, A1>>;
}

👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。 

 

请求参数

参数数据类型说明是否必填
optionsSmartDeviceModelOptions初始化智能设备模型配置项

返回参数

参数数据类型说明
SmartDeviceInstancePromise<SmartDeviceModel<S1, A1>>智能设备模型实例

请求示例

import { SmartDeviceModel } from '@ray-js/panel-sdk';
 
const schema = [
  {
    attr: 0,
    canTrigger: true,
    code: 'power',
    defaultRecommend: false,
    editPermission: false,
    executable: true,
    extContent: '',
    iconname: 'icon-dp_power2',
    id: 1,
    mode: 'rw',
    name: '开关',
    property: {
      type: 'bool',
    },
    type: 'obj',
  },
] as const; // 注意此处的 as const 非常重要,必须强制断言成常量
 
type Schema = typeof schema;
 
type LampAbilities = {
  toggleMusic: (a: string) => void;
};
 
const device = await SmartDeviceModel.init<Schema, LampAbilities>();

返回示例

 

onInitialized

描述

智能设备模型初始化完毕事件

类型

export default class SmartDeviceModel<
  S extends ReadonlyDpSchemaList,
  A extends SmartDeviceModelAbility = SmartDeviceModelAbility,
> {
  static onInitialized: (listener: () => void) => number;
}

请求参数

参数数据类型说明是否必填
param(listener: () => void) => number初始化完毕回调事件

返回参数

请求示例

import { SmartDeviceModel } from '@ray-js/panel-sdk';
 
SmartDeviceModel.onInitialized(() => {
  console.log('智能设备初始化完毕!');
});

返回示例

1

👉 立即免费领取开发资源,体验涂鸦 MiniApp 小程序开发。 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IoT砖家涂拉拉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值