Skip to content

Commit

Permalink
v3.0.1
Browse files Browse the repository at this point in the history
## [3.0.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v3.0.1) (2024-10-05)

### What's Changed
- Hot Fix for `baseURL` which is used for sending `OpenAPI` commands
- Housekeeping and update dependencies

**Full Changelog**: v3.0.0...v3.0.1
  • Loading branch information
donavanbecker committed Oct 5, 2024
1 parent 6087873 commit 122b974
Show file tree
Hide file tree
Showing 155 changed files with 417 additions and 341 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
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 }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_LATEST }}
58 changes: 29 additions & 29 deletions BLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ To use the `SwitchBotBLE` class in `node-switchbot`, you need to import it and c
import { SwitchBotBLE } from 'node-switchbot'

// Example usage
const switchbotBLE = new SwitchBotBLE()
const switchBotBLE = new SwitchBotBLE()

try {
await switchbotBLE.startScan()
await switchBotBLE.startScan()
} catch (e: any) {
console.error(`Failed to start BLE scanning. Error:${e}`)
}
Expand All @@ -100,7 +100,7 @@ The sample code below shows how to pass a `Noble` object to the `Switchbot` cons
// Create a Noble object
const noble = require('@stoprocent/noble');

const switchbotBLE = new SwitchBotBLE({ 'noble': Noble })
const switchBotBLE = new SwitchBotBLE({ 'noble': Noble })
```

In the code snippet above, the variable `switchbot` is an `SwitchBotBLE` object. The `SwitchBotBLE` object has a lot of methods as described in sections below.
Expand All @@ -119,7 +119,7 @@ The `discover` method finds devices. This method returns a `Promise` object. Thi
In the code snippet below, no parameter is passed to the method:

```Typescript
switchbotBLE.discover().then((device_list) => {
switchBotBLE.discover().then((device_list) => {
// Do something...
}).catch((error) => {
console.error(error);
Expand All @@ -131,7 +131,7 @@ If no parameter is passed to the method as the code above, an `Array` object wil
If you want a quick response, you can set the `quick` property to `true`.

```Typescript
switchbotBLE.discover({
switchBotBLE.discover({
duration: 5000,
quick: true
}).then((device_list) => {
Expand All @@ -148,11 +148,11 @@ As the `quick` property is set to `true`, the `resolve()` function will be calle
The `ondiscover` property on the [`Switchbot`](#Switchbot-object) object is an event handler called whenever a device is newly found in the discovery process. A [`SwitchbotDevice`](#SwitchbotDevice-object) object is passed to the callback function set to the `ondiscover` property.

```Typescript
switchbotBLE.ondiscover = (device) => {
switchBotBLE.ondiscover = (device) => {
console.log(device.id + ' (' + device.modelName + ')');
};

switchbotBLE.discover().then(() => {
switchBotBLE.discover().then(() => {
console.log('The discovery process was finished.');
}).catch((error) => {
console.error(error);
Expand Down Expand Up @@ -180,19 +180,19 @@ Whenever a packet is received, the callback function set to the [`onadvertisemen

```Typescript
// Set a callback function called when a packet is received
switchbotBLE.onadvertisement = (ad) => {
switchBotBLE.onadvertisement = (ad) => {
console.log(ad);
};

// Start to scan advertising packets
switchbotBLE.startScan({
switchBotBLE.startScan({
id: 'cb:4e:b9:03:c9:6d',
}).then(() => {
// Wait for 30 seconds
return switchbotBLE.wait(30000);
return switchBotBLE.wait(30000);
}).then(() => {
// Stop to scan
switchbotBLE.stopScan();
switchBotBLE.stopScan();
process.exit();
}).catch((error) => {
console.error(error);
Expand Down Expand Up @@ -226,7 +226,7 @@ The `serviceData` property depends on the model of the device. See the section "
If a callback function is set to the `onadvertisement` property, the callback function will be called whenever an advertising packet is received from a device during the scan is active (from the moment when the [`startScan()`](#startscan-method) method is called, to the moment when the [`stopScan()`](#Switchbot-stopScan-method) method is called).

```typescript
switchbotBLE.onadvertisement = async (ad: any) => {
switchBotBLE.onadvertisement = async (ad: any) => {
try {
this.bleEventHandler[ad.address]?.(ad.serviceData)
} catch (e: any) {
Expand All @@ -243,7 +243,7 @@ The `stopScan()` method stops to scan advertising packets coming from devices. T

```typescript
try {
switchbotBLE.stopScan()
switchBotBLE.stopScan()
console.log('Stopped BLE scanning to close listening.')
} catch (e: any) {
console.error(`Failed to stop BLE scanning, error:${e.message}`)
Expand All @@ -257,12 +257,12 @@ The `wait()` method waits for the specified milliseconds. This method takes an i
This method has nothing to do with Switchbot devices. It's just a utility method. See the section "[Quick Start](#Quick-Start)" for details of the usage of this method.

```typescript
await switchbotBLE.wait(1000)
await switchBotBLE.wait(1000)
```

### `SwitchBotDevice` Object

The `SwitchbotDevice` object represents a Switchbot device (Bot, Meter, Curtain, Contact or Motion), which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
The `SwitchbotDevice` object represents a Switchbot device (Bot, Meter, Curtain, Contact or Motion), which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.

Actually, the `SwitchbotDevice` object is a super class of the [`WoHand`](#SwitchbotDeviceWoHand-object) and `WoSensorTH` objects. The [`WoHand`](#SwitchbotDeviceWoHand-object) object represents a Bot, the `WoSensorTH` object represents a Meter.

Expand Down Expand Up @@ -367,7 +367,7 @@ switchbot
})
.then(() => {
console.log("Waiting for 5 seconds...");
return switchbotBLE.wait(5000);
return switchBotBLE.wait(5000);
})
.then(() => {
console.log("Putting the arm up...");
Expand Down Expand Up @@ -461,7 +461,7 @@ The `ondisconnect` event handler will be called when the connection with the dev

### `WoHand` Object

The `WoHand` object represents a Bot, which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
The `WoHand` object represents a Bot, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.

Actually, the `WoHand` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.

Expand Down Expand Up @@ -589,7 +589,7 @@ switchbot

### `WoCurtain` Object

The `WoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
The `WoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.

Actually, the `WoCurtain` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.

Expand Down Expand Up @@ -698,7 +698,7 @@ switchbot

### `WoPlugMini` Object

The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.

Actually, the `WoPlugMini ` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.

Expand All @@ -722,7 +722,7 @@ If no connection is established with the device, this method automatically estab

### `WoSmartLock` Object

The `WoSmartLock ` object represents a SmartLock, which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
The `WoSmartLock ` object represents a SmartLock, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.

Actually, the `WoSmartLock ` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.

Expand Down Expand Up @@ -769,19 +769,19 @@ After the [`startScan()`](#startscan-method) method is invoked, the [`onadvertis
// Load the node-switchbot and get a `Switchbot` constructor object
import { SwitchBotBLE } from 'node-switchbot';
// Create a `Switchbot` object
const switchbotBLE = new SwitchBotBLE();
const switchBotBLE = new SwitchBotBLE();

(async () => {
// Start to monitor advertisement packets
await switchbotBLE.startScan();
await switchBotBLE.startScan();
// Set an event handler
switchbotBLE.onadvertisement = (ad) => {
switchBotBLE.onadvertisement = (ad) => {
console.log(JSON.stringify(ad, null, ' '));
};
// Wait 10 seconds
await switchbotBLE.wait(10000);
await switchBotBLE.wait(10000);
// Stop to monitor
switchbotBLE.stopScan();
switchBotBLE.stopScan();
process.exit();
})();
```
Expand Down Expand Up @@ -1062,11 +1062,11 @@ This sample discovers a Bot (WoHand), then put the Bot's arm down, finally put i
// Load the node-switchbot and get a `Switchbot` constructor object
import { SwitchBotBLE } from 'node-switchbot';
// Create a `Switchbot` object
const switchbotBLE = new SwitchBotBLE();
const switchBotBLE = new SwitchBotBLE();

(async () => {
// Find a Bot (WoHand)
const bot_list = await switchbotBLE.discover({ model: "H", quick: true });
const bot_list = await switchBotBLE.discover({ model: "H", quick: true });
if (bot_list.length === 0) {
throw new Error("No device was found.");
}
Expand All @@ -1075,14 +1075,14 @@ const switchbotBLE = new SwitchBotBLE();
// Put the Bot's arm down (stretch the arm)
await device.down();
// Wait for 5 seconds
await switchbotBLE.wait(5000);
await switchBotBLE.wait(5000);
// Put the Bot's arm up (retract the arm)
await device.up();
process.exit();
})();
```

In order to manipulate the arm of your Bot, you have to discover your Bot using the [`discover()`](#Switchbot-discover-method) method. The object `{ model: 'H' }` passed to the method means that only Bots will be discovered. That is, Meters will be ignored.
In order to manipulate the arm of your Bot, you have to discover your Bot using the [`discover()`](#discover-method) method. The object `{ model: 'H' }` passed to the method means that only Bots will be discovered. That is, Meters will be ignored.

In this code, you can get a [`WoHand`](#SwitchbotDeviceWoHand-object) object representing the found Bot. Using the [`down()`](#SwitchbotDeviceWoHand-down-method) and [`up()`](#SwitchbotDeviceWoHand-up-method) methods of the object, you can move the arm. In addition to these methods, you can use the [`press()`](#SwitchbotDeviceWoHand-press-method), [`turnOn()`](#SwitchbotDeviceWoHand-turnOn-method), and [`turnOff()`](#SwitchbotDeviceWoHand-turnOff-method) methods as well.

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

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

## [3.0.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v3.0.1) (2024-10-05)

### What's Changed
- Hot Fix for `baseURL` which is used for sending `OpenAPI` commands
- Housekeeping and update dependencies

**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v3.0.0...v3.0.1

## [3.0.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v3.0.0) (2024-10-05)

### What's Changed
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 122b974

Please sign in to comment.