Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/)

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

### What's Changed
- Added `celcius` and `fahrenheit` as based values sent for Sensors
- Housekeeping and update dependencies

**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v2.3.0...v2.4.0

## [2.3.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v2.3.0) (2024-07-21)

### What's Changed
Expand Down
91 changes: 49 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ The sample codes above will output the result as follows:
"battery": 100
}
}
```

```json
{
"id": "cb4eb903c96d",
"address": "cb:4e:b9:03:c9:6d",
Expand All @@ -195,6 +198,9 @@ The sample codes above will output the result as follows:
"battery": 100
}
}
```

```json
{
"id": "ec58c5d00111",
"address": "ec:58:c5:d0:01:11",
Expand Down Expand Up @@ -257,7 +263,8 @@ import { SwitchBot } from 'node-switchbot';
You can get an `SwitchBot` constructor from the code above. Then you have to create a `SwitchBot` object from the `SwitchBot` constructor as follows:

```typescript
const switchbot = new SwitchBot();
const switchbot = new SwitchBot()
switchbot.startScan()
```

The `SwitchBot` constructor takes an argument optionally. It must be a hash object containing the properties as follows:
Expand Down Expand Up @@ -347,10 +354,10 @@ The discovery process was finished.

The `startScan()` method starts to scan advertising packets coming from devices. This method takes an argument which is a hash object containing the parameters as follows:

| Property | Type | Required | Description |
| :------- | :----- | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Property | Type | Required | Description |
| :------- | :----- | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model` | String | Optional | `"H"`, `"T"`, `"c"`, `"g"` or `"j"`. If `"H"` is specified, this method will discover only Bots. If `"T"` is specified, this method will discover only Meters. If `"c"` is specified, this method will discover only Curtains. If `"g"` or `"j"` is specified, this method will discover only (US/JP) Plug Minis. |
| `id` | String | Optional | If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This value is case-insensitive, and colons are ignored. |
| `id` | String | Optional | If this value is set, this method will discover only a device whose ID is as same as this value. The ID is identical to the MAC address. This value is case-insensitive, and colons are ignored. |

Whenever a packet is received, the callback function set to the [`onadvertisement`](#Switchbot-onadvertisement-event-handler) property of the [`Switchbot`](#Switchbot-object) object will be called. When a packet is received, a hash object representing the packet will be passed to the callback function.

Expand Down Expand Up @@ -385,8 +392,9 @@ The code snippet above will output the result as follows:
serviceData: {
model: 'T',
modelName: 'WoSensorTH',
temperature: { c: 25.8, f: 78.4 },
fahrenheit: false,
celsius: 25.8,
fahrenheit: 78.4,
fahrenheit_mode: false,
humidity: 43,
battery: 100
}
Expand Down Expand Up @@ -855,6 +863,7 @@ switchbot
```

---

## `WoPlugMini` object

The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
Expand Down Expand Up @@ -882,6 +891,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 [`Switchbot.discover()`](#Switchbot-discover-method) method.
Expand All @@ -894,10 +904,10 @@ The `setKey()` method initialises the key information required for encrypted com

This must be set before any control commands are sent to the device. To obtain the key information you will need to use an external tool - see [`pySwitchbot`](https://github.com/Danielhiversen/pySwitchbot/tree/master?tab=readme-ov-file#obtaining-locks-encryption-key) project for an example script.

| Property | Type | Description |
| :--------------- | :------ | :------------------------------------------------------------------------------------------------------------------------------------- |
| `keyId` | String | unique2 character ID for the key. (e.g., `"ff"`) returned from the SwitchBot api for your device |
| `encryptionKey` | String | the unique encryption key returned from the SwitchBot api for your device |
| Property | Type | Description |
| :-------------- | :----- | :----------------------------------------------------------------------------------------------- |
| `keyId` | String | unique2 character ID for the key. (e.g., `"ff"`) returned from the SwitchBot api for your device |
| `encryptionKey` | String | the unique encryption key returned from the SwitchBot api for your device |

### `lock()` method

Expand All @@ -923,7 +933,6 @@ The `info()` method retreieves state information from the SmartLock, This method

If no connection is established with the device, this method automatically establishes a connection with the device, then finally closes the connection. You don't have to call the [`connect()`](#SwitchbotDevice-connect-method) method in advance.


## Advertisement data

After the [`startScan()`](#startscan-method) method is invoked, the [`onadvertisement`](#Switchbot-onadvertisement-event-handler) event handler will be called whenever an advertising packet comes from the switchbot devices. An object containing the properties as follows will be passed to the event handler:
Expand Down Expand Up @@ -1136,16 +1145,16 @@ Example of the advertisement data:

Structure of the `serviceData`:

| Property | Type | Description |
| :------------ | :------ | :---------------------------------------------------------------------------------- |
| `model` | String | This value is always `"j"` or `"g"`, which means "PlugMini" (JP or US). |
| `modelName` | String | This value is always `"WoPlugMini"`, which means "PlugMini". |
| `state ` | Boolean | This value indicates whether the plug mini is turned on (`true`) or not (`false`). |
| `delay` | Boolean | Indicates whether a delay is present. |
| `timer` | Boolean | Indicates whether a timer is present. |
| `syncUtcTime` | boolean | Indicates whether the UTC time has been synchronized. |
| `overload` | boolean | Indicates whether the Plug Mini is overloaded, more than 15A current overload. |
| `currentPower`| Float | Current power consumption in Watts. |
| Property | Type | Description |
| :------------- | :------ | :--------------------------------------------------------------------------------- |
| `model` | String | This value is always `"j"` or `"g"`, which means "PlugMini" (JP or US). |
| `modelName` | String | This value is always `"WoPlugMini"`, which means "PlugMini". |
| `state ` | Boolean | This value indicates whether the plug mini is turned on (`true`) or not (`false`). |
| `delay` | Boolean | Indicates whether a delay is present. |
| `timer` | Boolean | Indicates whether a timer is present. |
| `syncUtcTime` | boolean | Indicates whether the UTC time has been synchronized. |
| `overload` | boolean | Indicates whether the Plug Mini is overloaded, more than 15A current overload. |
| `currentPower` | Float | Current power consumption in Watts. |

---

Expand All @@ -1155,8 +1164,8 @@ Example of the advertisement data:

```json
{
"id: 'd30864110b8c',
"address": 'd3:08:64:11:0b:8c',
"id": "d30864110b8c",
"address": "d3:08:64:11:0b:8c",
"rssi": -52,
"serviceData": {
"model": "o",
Expand All @@ -1172,29 +1181,27 @@ Example of the advertisement data:
"auto_lock_paused": false
}
}

```

Structure of the `serviceData`:

| Property | Type | Description |
| :---------------------------- | :------ | :---------------------------------------------------------------------------------- |
| `model` | String | This value is `"o"`, which means "Lock (WoSmartLock)". |
| `modelName` | String | This value is always `"WoSmartLock"`, which means "Lock". |
| `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
| `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
| `status` | String | This value indicates the current locked state. Possible values: |
| | | `"LOCKED"`, `"UNLOCKED"`, `"LOCKING"`, `"UNLOCKING"` |
| | | `"LOCKING_STOP"`, `"UNLOCKING_STOP"` (stuck when locking or unlocking respectively) |
| | | `"NOT_FULLY_LOCKED"` (eu model only), `"UNKNOWN"` (fallback: must be some error) |
| `update_from_secondary_lock` | Boolean | ?? |
| `door_open` | Boolean | door open status - whether the door is not detecting the sensor magnet |
| `double_lock_mode` | Boolean | dual lock mode enabled status - two locks working simultaneously |
| `unclosed_alarm` | Boolean | enabled status for door ajar alarm function |
| `unlocked_alarm` | Boolean | whether the alarm function is enabled for door left unlocked |
| `auto_lock_paused` | Boolean | auto lock mode paused |
| `night_latch` | Boolean | night latch mode enabled (eu firmware only) |

| Property | Type | Description |
| :--------------------------- | :------ | :---------------------------------------------------------------------------------- |
| `model` | String | This value is `"o"`, which means "Lock (WoSmartLock)". |
| `modelName` | String | This value is always `"WoSmartLock"`, which means "Lock". |
| `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
| `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
| `status` | String | This value indicates the current locked state. Possible values: |
| | | `"LOCKED"`, `"UNLOCKED"`, `"LOCKING"`, `"UNLOCKING"` |
| | | `"LOCKING_STOP"`, `"UNLOCKING_STOP"` (stuck when locking or unlocking respectively) |
| | | `"NOT_FULLY_LOCKED"` (eu model only), `"UNKNOWN"` (fallback: must be some error) |
| `update_from_secondary_lock` | Boolean | ?? |
| `door_open` | Boolean | door open status - whether the door is not detecting the sensor magnet |
| `double_lock_mode` | Boolean | dual lock mode enabled status - two locks working simultaneously |
| `unclosed_alarm` | Boolean | enabled status for door ajar alarm function |
| `unlocked_alarm` | Boolean | whether the alarm function is enabled for door left unlocked |
| `auto_lock_paused` | Boolean | auto lock mode paused |
| `night_latch` | Boolean | night latch mode enabled (eu firmware only) |

## References

Expand Down
127 changes: 46 additions & 81 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,50 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import antfu from '@antfu/eslint-config'


export default [
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
ignores: [".dist/*"]
},
export default antfu(
{
ignores: ['dist', 'docs'],
jsx: false,
typescript: true,
formatters: {
markdown: true,
},
rules: {
"quotes": [
"warn",
"single"
],
"indent": [
"warn",
2,
{
"SwitchCase": 1
}
],
"linebreak-style": [
"warn",
"unix"
],
"semi": [
"warn",
"always"
],
"comma-dangle": [
"warn",
"always-multiline"
],
"dot-notation": "off",
"eqeqeq": "warn",
"curly": [
"warn",
"all"
],
"brace-style": [
"warn"
],
"prefer-arrow-callback": [
"warn"
],
"max-len": [
"warn",
150
],
"no-console": [
"warn"
], // use the provided Homebridge log method instead
"no-non-null-assertion": [
"off"
],
"comma-spacing": [
"error"
],
"no-multi-spaces": [
"warn",
'curly': ['error', 'multi-line'],
'import/extensions': ['error', 'ignorePackages'],
'import/order': 0,
'jsdoc/check-alignment': 'error',
'jsdoc/check-line-alignment': 'error',
'perfectionist/sort-exports': 'error',
'perfectionist/sort-imports': [
'error',
{
"ignoreEOLComments": true
}
],
"no-trailing-spaces": [
"warn"
],
"lines-between-class-members": [
"warn",
"always",
{
"exceptAfterSingleLine": true
}
],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
];
groups: [
'builtin-type',
'external-type',
'internal-type',
['parent-type', 'sibling-type', 'index-type'],
'builtin',
'external',
'internal',
['parent', 'sibling', 'index'],
'object',
'unknown',
],
order: 'asc',
type: 'natural',
},
],
'perfectionist/sort-named-exports': 'error',
'perfectionist/sort-named-imports': 'error',
'sort-imports': 0,
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'style/quote-props': ['error', 'consistent-as-needed'],
'test/no-only-tests': 'error',
'unicorn/no-useless-spread': 'error',
'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }],
'no-new': 0, // Disable the no-new rule
'new-cap': 0, // Disable the new-cap rule
'no-undef': 0, // Disable the no-undef rule
},
},
)
Loading