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

ewelink-api-next

v1.0.4

Published

CoolKit v2 API Library

Downloads

358

Readme

ewelink-api-next

Node.js license Version

English | 简体中文

受到 ewelink-api 启发编写的 CoolKit v2 API 库

特点

  • 跟随官方文档更新
  • 简洁清晰的调用方法

使用说明

推荐使用 npm, 下载 ewelink-api-next(node >= 16.16)

npm i ewelink-api-next
# or pnpm i ewelink-api-next

示例

ESM: 设置 package.json 中的 { "type": "module" }

// eWeLink v2 API

import eWeLink from "ewelink-api-next";

const client = new eWeLink.WebAPI({
  appId: "xxx",
  appSecret: "xxx",
  region: "us",
  logObj: eWeLink.createLogger("us") // or console
});

try {
  const response = await client.user.login({ account: "[email protected]", password: "12345678", areaCode: "+1" });
  const userInfo = response.error === 0 ? response.data.user : {};
  console.log("userInfo:", userInfo);
} catch (err) {
  console.log("Failed to get user information:", err.message);
}
// eWeLink WebSocket API

import eWeLink from "ewelink-api-next";

const wsClient = new eWeLink.Ws({
  appId: "xxx",
  appSecret: "xxx",
  region: "us"
});

let ws = await wsClient.Connect.create({
  appId: wsClient?.appId || "",
  at: wsClient.at,
  region: "us",
  userApiKey: wsClient.userApiKey
});

setTimeout(() => {
  wsClient.Connect.updateState("xxxx", {
    switch: "on"
  });
}, 5000);
// eWeLink Lan Control
import eWeLink from "ewelink-api-next";

const lanClient = new eWeLink.Lan({
  selfApikey: "xxx",
  logObj: eWeLink.createLogger("lan")
});

lanClient.discovery((server) => {
  console.log("server:", server);
}); // Start Discovery Service

// 将设备信息保存到本地缓存

// 控制时需要传入 deviceId, secretKey, encrypt, iv
try {
  const res = await lanClient.zeroconf.switch({
    ip: "xxx",
    port: 80,
    data: {
      switch: "on"
    },
    deviceId: "xxx",
    secretKey: "xxx",
    encrypt: true,
    iv: "xxx"
  });
  console.info("Request result::", res);
  const res2 = await lanClient.zeroconf.switches({
    ip: "xxx",
    port: 80,
    data: {
      switches: [
        { switch: "on", outlet: 0 },
        { switch: "on", outlet: 1 },
        { switch: "on", outlet: 2 },
        { switch: "on", outlet: 3 }
      ]
    },
    deviceId: "xxx",
    secretKey: "xxx",
    encrypt: true,
    iv: "xxx"
  });
  console.info("Request result::", res2);
} catch (error: any) {
  console.info(error.message);
}

CommonJS: 使用 require 导入(ewelink-api-next@^1.0.2)

const eWeLink = require('ewelink-api-next').default

const client = new eWeLink.WebAPI({
    appId: 'xxx',
    appSecret: 'xxx',
    region: 'cn',
    logObj: eWeLink.createLogger('eu'),
  })

;(async () => {
  let response = await client.user.login({
    account: 'xxx',
    password: 'xxx',
    areaCode: '+1',
  })
  console.info(JSON.stringify(response))
})()

授权页登录方法可参考 https://github.com/nocmt/eWeLinkOAuthLoginDemo

方法说明

功能

  • [x] 首页管理
  • [x] 用户管理
  • [x] 设备管理
  • [x] 家庭房间
  • [x] 消息中心
  • [x] OAuth2.0
  • [x] 长连接控制
  • [x] 局域网控制

FAQ

1、请求接口时出现 407 错误

你当前使用的APPID可用的接口清单中不包括这个接口(受到应用类型的限制),比如:从eWeLink开发者中心创建的应用只能使用以下接口:

Supported API

2、请求首页、获取ThingList等接口 无法获取到设备数据

原因是:从eWeLink开发者中心创建的应用只免费授权了 sonoff、SONOFF、嵩诺、coolkit 品牌的权限,其他品牌的授权需要得到制造商的同意(付费后商务沟通)。

3、控制设备时返回 4002 错误

设备离线或者控制指令错误,指令具体查阅:UIID协议文档 - CoolKit开放平台 4.2

4、如何获取自己的apikey?

如果你没有登录、获取自己账号信息的接口权限,那么可以调用 GET@/v2/family、GET@/v2/device/thing、POST@/v2/device/thing等接口间接获取,家庭和设备都会关联在你的用户账号下,字段名称是 "apikey"。

修改日志

修改日志

致谢

| Item | Reason | |----------------------------------------------------------------|--------------------------| | ewelink-api | 社区项目,有借鉴其思路 | | wechat-api-next | 参考实现了项目结构,特别是新学到了混合模式的使用 |