Skip to content

Commit

Permalink
v3.0.0 (#256)
Browse files Browse the repository at this point in the history
## [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
  • Loading branch information
donavanbecker authored Oct 5, 2024
1 parent bef3638 commit 6087873
Show file tree
Hide file tree
Showing 218 changed files with 10,013 additions and 10,487 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended" // uses the recommended rules from the @typescript-eslint/eslint-plugin
"plugin:@typescript-eslint/recommended", // uses the recommended rules from the @typescript-eslint/eslint-plugin
"plugin:jest/recommended" // enables eslint-plugin-jest
],
"parserOptions": {
"ecmaVersion": 2021,
Expand Down
27 changes: 25 additions & 2 deletions .github/workflows/beta-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ jobs:
enable_coverage: true
secrets:
token: ${{ secrets.GITHUB_TOKEN }}

lint:
needs: build_and_test
uses: OpenWonderLabs/.github/.github/workflows/eslint.yml@latest

publish:
needs: lint

if: ${{ github.repository == 'OpenWonderLabs/node-switchbot' }}

uses: OpenWonderLabs/.github/.github/workflows/npm-publish.yml@latest
with:
tag: 'beta'
Expand All @@ -29,3 +28,27 @@ jobs:
pre_id: 'beta'
secrets:
npm_auth_token: ${{ secrets.npm_token }}

pre-release:
needs: publish
if: ${{ github.repository == 'OpenWonderLabs/node-switchbot' }}
uses: OpenWonderLabs/.github/.github/workflows/pre-release.yml@latest
with:
npm_version: ${{ needs.publish.outputs.NPM_VERSION }}
body: |
**Beta Release**
**Version**: v${{ needs.publish.outputs.NPM_VERSION }}
[How To Test Beta Releases](https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Beta-Version)
github-releases-to-discord:
name: Discord Webhooks
needs: [build_and_test,publish]
if: ${{ github.repository == 'OpenWonderLabs/node-switchbot' }}
uses: OpenWonderLabs/.github/.github/workflows/discord-webhooks.yml@latest
with:
title: "Node-SwitchBot Beta Release"
description: |
Version `v${{ needs.publish.outputs.NPM_VERSION }}`
url: "https://github.com/homebridge/camera-utils/releases/tag/v${{ needs.publish.outputs.NPM_VERSION }}"
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_BETA || secrets.DISCORD_WEBHOOK_URL_LATEST }}
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ jobs:
uses: OpenWonderLabs/.github/.github/workflows/npm-publish.yml@latest
secrets:
npm_auth_token: ${{ secrets.npm_token }}

github-releases-to-discord:
name: Discord Webhooks
needs: [build_and_test,publish]
if: ${{ github.repository == 'OpenWonderLabs/node-switchbot' }}
uses: OpenWonderLabs/.github/.github/workflows/discord-webhooks.yml@latest
with:
title: "Node-SwitchBot Beta Release"
description: |
Version `v${{ needs.publish.outputs.NPM_VERSION }}`
url: "https://github.com/homebridge/camera-utils/releases/tag/v${{ needs.publish.outputs.NPM_VERSION }}"
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_BETA || secrets.DISCORD_WEBHOOK_URL_LATEST }}
1,144 changes: 1,144 additions & 0 deletions BLE.md

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

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

## [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**: https://github.com/OpenWonderLabs/node-switchbot/compare/v2.4.0...v3.0.0

## [2.4.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v2.4.0) (2024-09-13)

### What's Changed
Expand Down
185 changes: 185 additions & 0 deletions OpenAPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# SwitchBot OpenAPI Documentation

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.

## Table of Contents

- [OpenAPI](#openapi)
- [Importing and Setting Up](#importing-and-setting-up)
- [`SwitchBotOpenAPI` Object](#switchbotopenapi-object)
- [`getDevices()` Method](#getdevices-method)
- [`controlDevice()` Method](#controldevice-method)
- [`getDeviceStatus()` Method](#getdevicestatus-method)
- [`setupWebhook()` Method](#setupwebhook-method)
- [`deleteWebhook()` Method](#deletewebhook-method)
- [Logging](#logging)
- [Supported Devices](#supported-devices)

## OpenAPI

### Importing and Setting Up

To use the `SwitchBotOpenAPI` class, you need to import it and create an instance with your SwitchBot token and secret.

```typescript
import { SwitchBotOpenAPI } from 'node-switchbot'

const switchBotAPI = new SwitchBotOpenAPI('your-token', 'your-secret')

// Example usage
switchBotAPI.getDevices().then((devices) => {
console.log('Devices:', devices)
}).catch((error) => {
console.error('Error getting devices:', error)
})
```

### SwitchBotOpenAPI Object

The `SwitchBotOpenAPI` object provides several methods to interact with SwitchBot devices. Below are examples of how to use each method.

#### `getDevices()` Method

Fetches the list of devices associated with your SwitchBot account.

```typescript
async function getDevices() {
try {
const devices = await switchBotAPI.getDevices()
console.log('Devices:', devices)
} catch (error) {
console.error('Error getting devices:', error)
}
}

// Example usage
getDevices()
```

#### `controlDevice()` Method

Sends a command to control a specific device.

```typescript
async function controlDevice(deviceId, command, parameter) {
try {
const response = await switchBotAPI.controlDevice(deviceId, command, parameter)
console.log('Control Device Response:', response)
} catch (error) {
console.error('Error controlling device:', error)
}
}

// Example usage
controlDevice('your-device-id', 'turnOn', 'default')
```

#### `getDeviceStatus()` Method

Fetches the current status of a specific device.

```typescript
async function getDeviceStatus(deviceId) {
try {
const status = await switchBotAPI.getDeviceStatus(deviceId)
console.log('Device Status:', status)
} catch (error) {
console.error('Error getting device status:', error)
}
}

// Example usage
getDeviceStatus('your-device-id')
```

#### `setupWebhook()` Method

Sets up a webhook to receive events from SwitchBot devices.

```typescript
async function setupWebhook(url) {
try {
await switchBotAPI.setupWebhook(url)
console.log('Webhook setup successfully')
} catch (error) {
console.error('Error setting up webhook:', error)
}
}

// Example usage
setupWebhook('http://your-webhook-url')
```

#### `deleteWebhook()` Method

Deletes an existing webhook.

```typescript
async function deleteWebhook(url) {
try {
await switchBotAPI.deleteWebhook(url)
console.log('Webhook deleted successfully')
} catch (error) {
console.error('Error deleting webhook:', error)
}
}

// Example usage
deleteWebhook('http://your-webhook-url')
```

### Logging

To be able to receive logging that this module is pushing out you will need to subscribt to the events.

```typescript
this.switchBotAPI.on('log', (log) => {
switch (log.level) {
case LogLevel.SUCCESS:
this.successLog(log.message)
break
case LogLevel.DEBUGSUCCESS:
this.debugSuccessLog(log.message)
break
case LogLevel.WARN:
this.warnLog(log.message)
break
case LogLevel.DEBUGWARN:
this.debugWarnLog(log.message)
break
case LogLevel.ERROR:
this.errorLog(log.message)
break
case LogLevel.DEBUGERROR:
this.debugErrorLog(log.message)
break
case LogLevel.DEBUG:
this.debugLog(log.message)
break
case LogLevel.INFO:
default:
this.infoLog(log.message)
}
})
```

### Supported Devices

The following devices are supported.

| Device | OpenAPI Support | Webhook Support |
| ------------------------- | --------------- | --------------- |
| SwitchBot Bot | Yes | Yes |
| SwitchBot Curtain | Yes | Yes |
| SwitchBot Meter | Yes | Yes |
| SwitchBot Motion Sensor | Yes | Yes |
| SwitchBot Contact Sensor | Yes | Yes |
| SwitchBot Plug Mini | Yes | Yes |
| SwitchBot Smart Lock | Yes | Yes |
| SwitchBot Humidifier | Yes | Yes |
| SwitchBot Color Bulb | Yes | Yes |
| SwitchBot LED Strip Light | Yes | Yes |

### Summary

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.
Loading

0 comments on commit 6087873

Please sign in to comment.