npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tslfe/tacos-space

v0.0.7

Published

tacos os

Downloads

9

Readme

@tslfe/tacos-iot

基于@tslfe/tacos-sdk、 @tslfe/tacos-iot,提供数字空间的功能封装,可进行空间层面的指令下发、模式切换等操作

已封装的具体空间类型

| 序号 | 名称 | 描述 | | ---- | ------ | ------------------------------------ | | 1 | Space | 数字空间基类,其余所有空间均继承于此 | | 2 | Office | 办公区 |

开始


安装

npm install @tslfe/tacos-sdk --save
npm install @tslfe/tacos-iot --save or
yarn add @tslfe/tacos-sdk -S yarn add @tslfe/tacos-iot -S

示例

使用@tslfe/tacos-space创建数字空间实例需要三个步骤:

  1. 通过@tslfe/tacos-sdk与 tacos 平台建立连接,具体建立连接方式请参考@tslfe/tacos-sdk 文档
  2. 建立连接后可从@tslfe/tacos-space导入需要创建的数字空间实例类型,创建实例对象。如需创建无类型的基础数字空间实例,则可导入 Space
  3. 调用实例对象的 API 方法进行相关操作
import Tacos from "@tslfe/tacos-sdk";
import { Office } from "@tslfe/tacos-space";

// 第一步:通过connect与tacos建立连接
Tacos.connect({ tacosId: "<tacos实例ID>", signature: "<签名>" }).then((tacos) => {
  // 第二步:建立连接后创建具体IOT设备sdk实例对象
  let office = tacos.createInstance(Office, { id: "<空间id>" });
  // 第三步:调用实例对象的API方法,可直接下发指令或下发模式
  office.turnOnAC(); // 下发打开空调指令
  office.onWork(); // 切换上班模式
  // 也可通过space属性获取其空间基类实例,进行一些数字空间的基本操作
  office.space.getProperties(); // 获取空间属性
  office.space.getDevices("[type=Switch]"); // 获取当前空间下所有类型为switch的设备
});

API

基类 Space

基类 Space 是所有数字空间共同继承的模块,所有具体类型都可通过 space 属性访问 Space 类的所有方法

getSpaces

获取与当前数字空间相关联的某一类空间

  • 方法:getSpaces(pattern: string)

  • 参数:

    • pattern: 资源定位符目前仅支持以下几种资源定位方式

      • "./**/" 获取当前空间下所有子空间,递归获取
      • "/**/"" 获取当前空间的根空间下所有子空间,递归获取
      • "./" 或 "" 获取当前空间下的子空间,不会去获取子空间的子空间

      在资源定位符之后增加需要匹配的空间类型,目前仅支持以下的匹配格式:

      • "[type=Office]"
  • 返回值:Promise<Subspace>

  • 示例:

// 查询当前空间下所有办公区空间
space.getSpaces("./**/[type=Office]").then((res) => {
  // 其他操作
});

getDevices

获取当前空间下的设备集合

  • 方法:getDevices(pattern: string)
  • 参数:
    • pattern: 资源定位符的规则与getSpaces方法相同
  • 返回值:Promise<Group>
  • 示例:
// 查询当前空间下所有调光灯
space.getDevices("./**/[type=Light]").then((res) => {
  // 打开所有灯
  res.turnOn();
});

getSpaceModel

获取空间模型信息

  • 方法:getSpaceModel(cache?: boolean)
  • 参数:
    • cache: 是否使用缓存
  • 返回值:Promise<SpaceModel>

getProperties

获取空间属性集合

  • 方法:getProperties(cache?: boolean)
  • 参数:
    • cache: 是否使用缓存
  • 返回值:Promise<Record<string, any>>

getEvents

获取空间事件列表

  • 方法:getEvents(cache?: boolean)
  • 参数:
    • cache: 是否使用缓存
  • 返回值:Promise<Event[]>

getCommands

获取空间指令列表

  • 方法:getCommands(cache?: boolean)
  • 参数:
    • cache: 是否使用缓存
  • 返回值:Promise<Command[]>

getRules

获取空间规则列表

  • 方法:getRules(cache?: boolean)
  • 参数:
    • cache: 是否使用缓存
  • 返回值:Promise<Rule[]>

getSchedules

获取空间计划列表

  • 方法:getSchedules(cache?: boolean)
  • 参数:
    • cache: 是否使用缓存
  • 返回值:Promise<Schedule[]>

getPatterns

获取空间计划列表

  • 方法:getPatterns(cache?: boolean)
  • 参数:
    • cache: 是否使用缓存
  • 返回值:Promise<Pattern[]>

emitEvent

手动触发空间事件

  • 方法:emitEvent(eventCode: string)
  • 参数:
    • eventCode: 事件 code
  • 返回值:Promise<boolean>

execCommand

下发空间指令

  • 方法:execCommand(cmdCode: string, params: Record<string, any>)
  • 参数:
    • cmdCode: 指令 code
    • params: 指令参数
  • 返回值:Promise<boolean>

execPattern

手动执行模式

  • 方法:execPattern(patternCode: string)
  • 参数:
    • eventpatternCodeCode: 模式 code
  • 返回值:Promise<boolean>

air-condition

open()

启动空调

参数:无

close()

关闭空调

参数:无

frequent(value: number)

设置空调送风机频率

参数:

  • value:频率值

valveDegree(type: string, value: number)

设置不同情形下阀门开度

参数:

  • type:阀门类型
    • valve 冷热水阀开度
    • valve_in 回风阀开度
    • valve_out 送风阀开度
  • value:开度值

blowing-fan

open()

开启送风机

参数:无

close()

关闭送风机

参数:无

butterfly-valve

open()

开启电动蝶阀

参数:无

close()

关闭电动蝶阀

参数:无

degree(value: number)

设置电动蝶阀开度

参数:

  • value:开度值

chiller-master

open()

开启冷水主机

参数:无

close()

关闭冷水主机

参数:无

cool()

设置模式为制冷

参数:无

heat()

设置模式为制热

参数:无

pump()

设置模式为水泵

参数:无

temperature(type: string, value: number)

设置不同情形下的回水温度

参数:

  • type:回水类型
    • cool_in 制冷回水
    • cool_out 制冷出水
    • hot_in 制热回水
    • hot_out 制热出水
  • value:温度值

chiller-slave

openBlowingFan()

开启冷水从机的送风机

参数:无

closeBlowingFan()

关闭冷水从机的送风机

参数:无

openExhaustFan()

开启冷水从机的排风机

参数:无

closeExhaustFan()

关闭冷水从机的排风机

参数:无

curtain

open()

开启遮阳帘

参数:无

close()

关闭遮阳帘

参数:无

pause()

暂停遮阳帘

参数:无

degree(value: number)

设置遮阳帘开度

参数:

  • value:开度值

door

open()

开启电动门

参数:无

close()

关闭电动门

参数:无

exhaust-fan

open()

开启排风机

参数:无

close()

关闭排风机

参数:无

open()

开启电动门

参数:无

close()

关闭电动门

参数:无

创建 sdk 模块实例

  • 方法:createInstance<M extends (...args: any) => any, P>(sdk: M, props?: P): ReturnType<M>
  • 参数:
    • sdk: 定义的 sdk 模块
    • props: sdk 所需的参数
  • 返回值:sdk 模型实例
  • 示例:
import Tacos, { Device } from "@tslfe/tacos-sdk";
import { AxiosRequestConfig } from "axios";

Tacos.connectWithToken("").then((tacos) => {
  let device = tacos.createInstance(Device, { deviceId: "" });
  // 其它逻辑
});

destroy

销毁当前 tacos 实例

  • 方法:destroy(): void
  • 参数:
  • 返回值:无
  • 示例:
import Tacos, { Device } from "@tslfe/tacos-sdk";
import { AxiosRequestConfig } from "axios";

Tacos.connectWithToken("").then((tacos) => {
  // 其它逻辑
  tacos.destroy();
});

扩展

defineSDK

定义 SDK 模块, defineSDK 是一个高阶函数

  • 方法:defineSDK<P, S>(sdkOptions: TacosOptions<P, S>): (context: Context, props?: P) => TacosSDK & S
  • 参数:
    • sdkOptions: SDK 模块逻辑代码
  • 返回值:SDK 的构造器
  • 示例:
import { defineSDK } from "@tslfe/tacos-sdk";

export default defineSDK({
  setup() {
    let getVersion = function () {
      return "0.0.1";
    };
    return {
      name: "自定义的SDK模块",
      getVersion
    };
  }
});

定义 SDK 模块更多详情,点击查看

defineApi

定义 ajax 网络请求模块

  • 方法:defindAPI<T extends Record<string, Function>>(api: Api<T>): (request: Request)=>T & ThisType<Request>
  • 参数:
    • api: 网络请求逻辑代码
  • 返回值:API 的构造器
  • 实例:
import { defineApi } from "@tslfe/tacos-sdk";

export default defineApi({
  getDeviceModel(deviceId: string) {
    return this.get(`/device/model/${deviceId}`);
  }
});

SDK 模块

space

空间模块

getSubSpaces

获取子空间

  • 方法:getSubSpaces()
  • 参数
  • 返回值:当前空间的子空间实例
  • 示例
let subSpaces = space.getSubSpaces();

getDevices

获取空间下的所有设备列表

  • 方法:getDevices(type?: DeviceType, status?: DeviceStatus): Device[]
  • 参数
    • type?: 设备类型
    • status?: 设备状态
  • 返回值:空间下的设备列表实例
  • 示例
let devices = space.getDevices();

getDevice

获取空间下的所有设备

  • 参数
    • deviceId: string (设备 ID)
  • 返回值:Device
  • 示例
let devices = space.getDevice("<deviceId>");

getScenes

获取空间下的场景

  • 参数
  • 返回值:Device
  • 示例
let scenes = space.getScenes();

文档未完,待补充。。。

Device

设备模块

getModel

获取设备的产品物模型

  • 参数
  • 返回值:Model
  • 示例
let model = device.getModel();

getStates

主动查询获取设备状态

  • 参数
    • refresh: boolean = false
  • 返回值:Model
  • 示例
let states = device.getStates(true);

execFunction

直接执行设备的功能

  • 参数
    • func: string
    • params: Record<string, any>
  • 返回值:boolean
  • 示例
let bool = device.execFunction("<funcName>", "<params>");

execFunctions

批量执行设备的功能

  • 参数
    • funcs: Array<{func: string, params: Record<string, any>}>
  • 返回值:boolean
  • 示例
let bool = device.execFunctions([{ func: `<funcName>`, params: "<params>" }]);

addStateListener

监听设备变化,监听设备事件

  • 参数
    • callback: (ds?: DeviceState) => void
  • 返回值:boolean
  • 示例
device.addStateListener((deviceState) => {
  // 其它业务逻辑...
});

buildDeviceExecutor

创建设备快捷的控制器

  • 参数
  • 返回值: Promise<{command: {}, functions: {}}>
  • 示例
import { TacosResponse } from "./request";

device.buildDeviceExecutor().then((exe) => {
  exe.command["fresh_valve_in_degree_value"](50).then((res: TacosResponse) => {
    // 其它逻辑...
  });
});

文档未完,待补充。。。

Model

物模型模块

exportModel

导出物模型结构

  • 参数
  • 返回值:
  • 示例
// 待完善...

getFunctions

获取功能集

  • 参数
  • 返回值:
  • 示例
// 待完善...

addFunction

增加功能

  • 参数
  • 返回值:
  • 示例
// 待完善...

getFunction

获取单个功能

  • 参数
  • 返回值:
  • 示例
// 待完善...

updateFunction

更新功能

  • 参数
  • 返回值:
  • 示例
// 待完善...

deleteFunction

删除功能

  • 参数
  • 返回值:
  • 示例
// 待完善...

getCommands

获取指令集

  • 参数
  • 返回值:
  • 示例
// 待完善...

getCommand

查询指令

  • 参数
  • 返回值:
  • 示例
// 待完善...

addCommand

新增指令

  • 参数
  • 返回值:
  • 示例
// 待完善...

updateCommand

修改指令

  • 参数
  • 返回值:
  • 示例
// 待完善...

deleteCommand

删除指令

  • 参数
  • 返回值:
  • 示例
// 待完善...

getProperties

获取属性集

  • 参数
  • 返回值:
  • 示例
// 待完善...

getProperty

获取属性

  • 参数
  • 返回值:
  • 示例
// 待完善...

addProperty

新增属性

  • 参数
  • 返回值:
  • 示例
// 待完善...

updateProperty

修改属性

  • 参数
  • 返回值:
  • 示例
// 待完善...

deleteProperty

删除属性

  • 参数
  • 返回值:
  • 示例
// 待完善...

getEvents

获取事件集

  • 参数
  • 返回值:
  • 示例
// 待完善...

getEvent

获取单个事件

  • 参数
  • 返回值:
  • 示例
// 待完善...

addEvent

新增事件

  • 参数
  • 返回值:
  • 示例
// 待完善...

updateEvent

修改事件

  • 参数
  • 返回值:
  • 示例
// 待完善...

deleteEvent

删除事件

  • 参数
  • 返回值:
  • 示例
// 待完善...

扩展 SDK 模块

通过@tslfe/tacos-sdk提供的方法可封装更上层的 SDK 模块,或者封装自己的 IOT 库。

defineSDK

  • 参数
    • sdkOptions: TacosOptions
  • 返回值:(context: Context, props?: P) => TacosSDK
  • 示例:
  1. 自定义 SDK 模块 light.ts
import { defineSDK, Device, Context } from "@tslfe/tacos-sdk";

export default defineSDK({
  /**
   * 参数说明
   * @param props 当前模块需要的入参,需实例化时传入(数据类型根据需要自定定义)
   * @param context 上下文,实例化时自动注入
   * @param onDestroy 销毁的生命周期,实例化时自动注入
   */
  setup({ props, context }: { props: any; context: Context }, { onDestroy }) {
    // 实例化device的deviceId,可定义在props中通过外部传入
    let device = this.createInstace(Device, { deviceId: props.id });
    let open = function () {
      return device.buildDeviceExecutor().then((exe) => {
        exe.command["light_open"]();
      });
    };

    let close = function () {
      return device.buildDeviceExecutor().then((exe) => {
        exe.command["light_close"]();
      });
    };

    return { open, close };
  }
});
  1. 使用自定义的 SDK 模块
import Tacos from "@tslfe/tacos-sdk";
import Light from "./light";

// 第一步:通过connect与tacos建立连接
Tacos.connect({ tacosId: "<tacos实例ID>", signature: "<签名>" }).then((tacos) => {
  // 第二步:建立连接后创建灯的实例对象
  let device = tacos.createInstance(Light, { id: "<设备ID>" });
  // 第三步:设备控制
  // 开灯
  device.open();
  // 关灯
  device.close();
});