Skip to content

Commit 6087873

Browse files
v3.0.0 (#256)
## [3.0.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v3.0.0) (2024-10-05) ### What's Changed #### ⚠️ Breaking Changes - Have added OpenAPI Functionality into `node-switchbot`, so now it is able to handle both APIs with just one module. - There are now two different Classes `SwitchBotBLE` and `SwitchBotOpenAPI` that can be used interact with the two different APIs - You will need to update your current setup from`SwitchBot` to `SwitchBotBLE` to be able to interact with the BLE API - Updated the documents to explain both the `BLE` and the `OpenAPI` Functionality within `node-switchbot` #### Other Changes - Housekeeping and update dependencies **Full Changelog**: v2.4.0...v3.0.0
1 parent bef3638 commit 6087873

File tree

218 files changed

+10013
-10487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+10013
-10487
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"extends": [
44
"eslint:recommended",
55
"plugin:@typescript-eslint/eslint-recommended",
6-
"plugin:@typescript-eslint/recommended" // uses the recommended rules from the @typescript-eslint/eslint-plugin
6+
"plugin:@typescript-eslint/recommended", // uses the recommended rules from the @typescript-eslint/eslint-plugin
7+
"plugin:jest/recommended" // enables eslint-plugin-jest
78
],
89
"parserOptions": {
910
"ecmaVersion": 2021,

.github/workflows/beta-release.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ jobs:
1212
enable_coverage: true
1313
secrets:
1414
token: ${{ secrets.GITHUB_TOKEN }}
15+
1516
lint:
1617
needs: build_and_test
1718
uses: OpenWonderLabs/.github/.github/workflows/eslint.yml@latest
1819

1920
publish:
2021
needs: lint
21-
2222
if: ${{ github.repository == 'OpenWonderLabs/node-switchbot' }}
23-
2423
uses: OpenWonderLabs/.github/.github/workflows/npm-publish.yml@latest
2524
with:
2625
tag: 'beta'
@@ -29,3 +28,27 @@ jobs:
2928
pre_id: 'beta'
3029
secrets:
3130
npm_auth_token: ${{ secrets.npm_token }}
31+
32+
pre-release:
33+
needs: publish
34+
if: ${{ github.repository == 'OpenWonderLabs/node-switchbot' }}
35+
uses: OpenWonderLabs/.github/.github/workflows/pre-release.yml@latest
36+
with:
37+
npm_version: ${{ needs.publish.outputs.NPM_VERSION }}
38+
body: |
39+
**Beta Release**
40+
**Version**: v${{ needs.publish.outputs.NPM_VERSION }}
41+
[How To Test Beta Releases](https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Beta-Version)
42+
43+
github-releases-to-discord:
44+
name: Discord Webhooks
45+
needs: [build_and_test,publish]
46+
if: ${{ github.repository == 'OpenWonderLabs/node-switchbot' }}
47+
uses: OpenWonderLabs/.github/.github/workflows/discord-webhooks.yml@latest
48+
with:
49+
title: "Node-SwitchBot Beta Release"
50+
description: |
51+
Version `v${{ needs.publish.outputs.NPM_VERSION }}`
52+
url: "https://github.com/homebridge/camera-utils/releases/tag/v${{ needs.publish.outputs.NPM_VERSION }}"
53+
secrets:
54+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_BETA || secrets.DISCORD_WEBHOOK_URL_LATEST }}

.github/workflows/release.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,16 @@ jobs:
2020
uses: OpenWonderLabs/.github/.github/workflows/npm-publish.yml@latest
2121
secrets:
2222
npm_auth_token: ${{ secrets.npm_token }}
23+
24+
github-releases-to-discord:
25+
name: Discord Webhooks
26+
needs: [build_and_test,publish]
27+
if: ${{ github.repository == 'OpenWonderLabs/node-switchbot' }}
28+
uses: OpenWonderLabs/.github/.github/workflows/discord-webhooks.yml@latest
29+
with:
30+
title: "Node-SwitchBot Beta Release"
31+
description: |
32+
Version `v${{ needs.publish.outputs.NPM_VERSION }}`
33+
url: "https://github.com/homebridge/camera-utils/releases/tag/v${{ needs.publish.outputs.NPM_VERSION }}"
34+
secrets:
35+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_BETA || secrets.DISCORD_WEBHOOK_URL_LATEST }}

BLE.md

Lines changed: 1144 additions & 0 deletions
Large diffs are not rendered by default.

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
44

5+
## [3.0.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v3.0.0) (2024-10-05)
6+
7+
### What's Changed
8+
#### ⚠️ Breaking Changes
9+
- Have added OpenAPI Functionality into `node-switchbot`, so now it is able to handle both APIs with just one module.
10+
- There are now two different Classes `SwitchBotBLE` and `SwitchBotOpenAPI` that can be used interact with the two different APIs
11+
- You will need to update your current setup from`SwitchBot` to `SwitchBotBLE` to be able to interact with the BLE API
12+
- Updated the documents to explain both the `BLE` and the `OpenAPI` Functionality within `node-switchbot`
13+
14+
#### Other Changes
15+
- Housekeeping and update dependencies
16+
17+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v2.4.0...v3.0.0
18+
519
## [2.4.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v2.4.0) (2024-09-13)
620

721
### What's Changed

OpenAPI.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# SwitchBot OpenAPI Documentation
2+
3+
The `SwitchBotOpenAPI` class allows you to interact with SwitchBot devices using the SwitchBot OpenAPI. This documentation provides an overview of how to install, set up, and use the various methods available in the `SwitchBotOpenAPI` class.
4+
5+
## Table of Contents
6+
7+
- [OpenAPI](#openapi)
8+
- [Importing and Setting Up](#importing-and-setting-up)
9+
- [`SwitchBotOpenAPI` Object](#switchbotopenapi-object)
10+
- [`getDevices()` Method](#getdevices-method)
11+
- [`controlDevice()` Method](#controldevice-method)
12+
- [`getDeviceStatus()` Method](#getdevicestatus-method)
13+
- [`setupWebhook()` Method](#setupwebhook-method)
14+
- [`deleteWebhook()` Method](#deletewebhook-method)
15+
- [Logging](#logging)
16+
- [Supported Devices](#supported-devices)
17+
18+
## OpenAPI
19+
20+
### Importing and Setting Up
21+
22+
To use the `SwitchBotOpenAPI` class, you need to import it and create an instance with your SwitchBot token and secret.
23+
24+
```typescript
25+
import { SwitchBotOpenAPI } from 'node-switchbot'
26+
27+
const switchBotAPI = new SwitchBotOpenAPI('your-token', 'your-secret')
28+
29+
// Example usage
30+
switchBotAPI.getDevices().then((devices) => {
31+
console.log('Devices:', devices)
32+
}).catch((error) => {
33+
console.error('Error getting devices:', error)
34+
})
35+
```
36+
37+
### SwitchBotOpenAPI Object
38+
39+
The `SwitchBotOpenAPI` object provides several methods to interact with SwitchBot devices. Below are examples of how to use each method.
40+
41+
#### `getDevices()` Method
42+
43+
Fetches the list of devices associated with your SwitchBot account.
44+
45+
```typescript
46+
async function getDevices() {
47+
try {
48+
const devices = await switchBotAPI.getDevices()
49+
console.log('Devices:', devices)
50+
} catch (error) {
51+
console.error('Error getting devices:', error)
52+
}
53+
}
54+
55+
// Example usage
56+
getDevices()
57+
```
58+
59+
#### `controlDevice()` Method
60+
61+
Sends a command to control a specific device.
62+
63+
```typescript
64+
async function controlDevice(deviceId, command, parameter) {
65+
try {
66+
const response = await switchBotAPI.controlDevice(deviceId, command, parameter)
67+
console.log('Control Device Response:', response)
68+
} catch (error) {
69+
console.error('Error controlling device:', error)
70+
}
71+
}
72+
73+
// Example usage
74+
controlDevice('your-device-id', 'turnOn', 'default')
75+
```
76+
77+
#### `getDeviceStatus()` Method
78+
79+
Fetches the current status of a specific device.
80+
81+
```typescript
82+
async function getDeviceStatus(deviceId) {
83+
try {
84+
const status = await switchBotAPI.getDeviceStatus(deviceId)
85+
console.log('Device Status:', status)
86+
} catch (error) {
87+
console.error('Error getting device status:', error)
88+
}
89+
}
90+
91+
// Example usage
92+
getDeviceStatus('your-device-id')
93+
```
94+
95+
#### `setupWebhook()` Method
96+
97+
Sets up a webhook to receive events from SwitchBot devices.
98+
99+
```typescript
100+
async function setupWebhook(url) {
101+
try {
102+
await switchBotAPI.setupWebhook(url)
103+
console.log('Webhook setup successfully')
104+
} catch (error) {
105+
console.error('Error setting up webhook:', error)
106+
}
107+
}
108+
109+
// Example usage
110+
setupWebhook('http://your-webhook-url')
111+
```
112+
113+
#### `deleteWebhook()` Method
114+
115+
Deletes an existing webhook.
116+
117+
```typescript
118+
async function deleteWebhook(url) {
119+
try {
120+
await switchBotAPI.deleteWebhook(url)
121+
console.log('Webhook deleted successfully')
122+
} catch (error) {
123+
console.error('Error deleting webhook:', error)
124+
}
125+
}
126+
127+
// Example usage
128+
deleteWebhook('http://your-webhook-url')
129+
```
130+
131+
### Logging
132+
133+
To be able to receive logging that this module is pushing out you will need to subscribt to the events.
134+
135+
```typescript
136+
this.switchBotAPI.on('log', (log) => {
137+
switch (log.level) {
138+
case LogLevel.SUCCESS:
139+
this.successLog(log.message)
140+
break
141+
case LogLevel.DEBUGSUCCESS:
142+
this.debugSuccessLog(log.message)
143+
break
144+
case LogLevel.WARN:
145+
this.warnLog(log.message)
146+
break
147+
case LogLevel.DEBUGWARN:
148+
this.debugWarnLog(log.message)
149+
break
150+
case LogLevel.ERROR:
151+
this.errorLog(log.message)
152+
break
153+
case LogLevel.DEBUGERROR:
154+
this.debugErrorLog(log.message)
155+
break
156+
case LogLevel.DEBUG:
157+
this.debugLog(log.message)
158+
break
159+
case LogLevel.INFO:
160+
default:
161+
this.infoLog(log.message)
162+
}
163+
})
164+
```
165+
166+
### Supported Devices
167+
168+
The following devices are supported.
169+
170+
| Device | OpenAPI Support | Webhook Support |
171+
| ------------------------- | --------------- | --------------- |
172+
| SwitchBot Bot | Yes | Yes |
173+
| SwitchBot Curtain | Yes | Yes |
174+
| SwitchBot Meter | Yes | Yes |
175+
| SwitchBot Motion Sensor | Yes | Yes |
176+
| SwitchBot Contact Sensor | Yes | Yes |
177+
| SwitchBot Plug Mini | Yes | Yes |
178+
| SwitchBot Smart Lock | Yes | Yes |
179+
| SwitchBot Humidifier | Yes | Yes |
180+
| SwitchBot Color Bulb | Yes | Yes |
181+
| SwitchBot LED Strip Light | Yes | Yes |
182+
183+
### Summary
184+
185+
The `SwitchBotOpenAPI` class provides a powerful way to interact with your SwitchBot devices programmatically. By following the examples provided, you can easily integrate SwitchBot device control and monitoring into your applications.

0 commit comments

Comments
 (0)