Skip to content

Commit a8c3d26

Browse files
v2.4.0 (#252)
## [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**: v2.3.0...v2.4.0
1 parent ae0ddbb commit a8c3d26

26 files changed

+14764
-6227
lines changed

CHANGELOG.md

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

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

5+
## [2.4.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v2.4.0) (2024-09-13)
6+
7+
### What's Changed
8+
- Added `celcius` and `fahrenheit` as based values sent for Sensors
9+
- Housekeeping and update dependencies
10+
11+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v2.3.0...v2.4.0
12+
513
## [2.3.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v2.3.0) (2024-07-21)
614

715
### What's Changed

README.md

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ The sample codes above will output the result as follows:
179179
"battery": 100
180180
}
181181
}
182+
```
183+
184+
```json
182185
{
183186
"id": "cb4eb903c96d",
184187
"address": "cb:4e:b9:03:c9:6d",
@@ -195,6 +198,9 @@ The sample codes above will output the result as follows:
195198
"battery": 100
196199
}
197200
}
201+
```
202+
203+
```json
198204
{
199205
"id": "ec58c5d00111",
200206
"address": "ec:58:c5:d0:01:11",
@@ -257,7 +263,8 @@ import { SwitchBot } from 'node-switchbot';
257263
You can get an `SwitchBot` constructor from the code above. Then you have to create a `SwitchBot` object from the `SwitchBot` constructor as follows:
258264

259265
```typescript
260-
const switchbot = new SwitchBot();
266+
const switchbot = new SwitchBot()
267+
switchbot.startScan()
261268
```
262269

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

348355
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:
349356

350-
| Property | Type | Required | Description |
351-
| :------- | :----- | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
357+
| Property | Type | Required | Description |
358+
| :------- | :----- | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
352359
| `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. |
353-
| `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. |
360+
| `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. |
354361

355362
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.
356363

@@ -385,8 +392,9 @@ The code snippet above will output the result as follows:
385392
serviceData: {
386393
model: 'T',
387394
modelName: 'WoSensorTH',
388-
temperature: { c: 25.8, f: 78.4 },
389-
fahrenheit: false,
395+
celsius: 25.8,
396+
fahrenheit: 78.4,
397+
fahrenheit_mode: false,
390398
humidity: 43,
391399
battery: 100
392400
}
@@ -855,6 +863,7 @@ switchbot
855863
```
856864

857865
---
866+
858867
## `WoPlugMini` object
859868

860869
The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
@@ -882,6 +891,7 @@ If no connection is established with the device, this method automatically estab
882891
---
883892

884893
---
894+
885895
## `WoSmartLock` object
886896

887897
The `WoSmartLock ` object represents a SmartLock, which is created through the discovery process triggered by the [`Switchbot.discover()`](#Switchbot-discover-method) method.
@@ -894,10 +904,10 @@ The `setKey()` method initialises the key information required for encrypted com
894904

895905
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.
896906

897-
| Property | Type | Description |
898-
| :--------------- | :------ | :------------------------------------------------------------------------------------------------------------------------------------- |
899-
| `keyId` | String | unique2 character ID for the key. (e.g., `"ff"`) returned from the SwitchBot api for your device |
900-
| `encryptionKey` | String | the unique encryption key returned from the SwitchBot api for your device |
907+
| Property | Type | Description |
908+
| :-------------- | :----- | :----------------------------------------------------------------------------------------------- |
909+
| `keyId` | String | unique2 character ID for the key. (e.g., `"ff"`) returned from the SwitchBot api for your device |
910+
| `encryptionKey` | String | the unique encryption key returned from the SwitchBot api for your device |
901911

902912
### `lock()` method
903913

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

924934
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.
925935

926-
927936
## Advertisement data
928937

929938
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:
@@ -1136,16 +1145,16 @@ Example of the advertisement data:
11361145

11371146
Structure of the `serviceData`:
11381147

1139-
| Property | Type | Description |
1140-
| :------------ | :------ | :---------------------------------------------------------------------------------- |
1141-
| `model` | String | This value is always `"j"` or `"g"`, which means "PlugMini" (JP or US). |
1142-
| `modelName` | String | This value is always `"WoPlugMini"`, which means "PlugMini". |
1143-
| `state ` | Boolean | This value indicates whether the plug mini is turned on (`true`) or not (`false`). |
1144-
| `delay` | Boolean | Indicates whether a delay is present. |
1145-
| `timer` | Boolean | Indicates whether a timer is present. |
1146-
| `syncUtcTime` | boolean | Indicates whether the UTC time has been synchronized. |
1147-
| `overload` | boolean | Indicates whether the Plug Mini is overloaded, more than 15A current overload. |
1148-
| `currentPower`| Float | Current power consumption in Watts. |
1148+
| Property | Type | Description |
1149+
| :------------- | :------ | :--------------------------------------------------------------------------------- |
1150+
| `model` | String | This value is always `"j"` or `"g"`, which means "PlugMini" (JP or US). |
1151+
| `modelName` | String | This value is always `"WoPlugMini"`, which means "PlugMini". |
1152+
| `state ` | Boolean | This value indicates whether the plug mini is turned on (`true`) or not (`false`). |
1153+
| `delay` | Boolean | Indicates whether a delay is present. |
1154+
| `timer` | Boolean | Indicates whether a timer is present. |
1155+
| `syncUtcTime` | boolean | Indicates whether the UTC time has been synchronized. |
1156+
| `overload` | boolean | Indicates whether the Plug Mini is overloaded, more than 15A current overload. |
1157+
| `currentPower` | Float | Current power consumption in Watts. |
11491158

11501159
---
11511160

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

11561165
```json
11571166
{
1158-
"id: 'd30864110b8c',
1159-
"address": 'd3:08:64:11:0b:8c',
1167+
"id": "d30864110b8c",
1168+
"address": "d3:08:64:11:0b:8c",
11601169
"rssi": -52,
11611170
"serviceData": {
11621171
"model": "o",
@@ -1172,29 +1181,27 @@ Example of the advertisement data:
11721181
"auto_lock_paused": false
11731182
}
11741183
}
1175-
11761184
```
11771185

11781186
Structure of the `serviceData`:
11791187

1180-
| Property | Type | Description |
1181-
| :---------------------------- | :------ | :---------------------------------------------------------------------------------- |
1182-
| `model` | String | This value is `"o"`, which means "Lock (WoSmartLock)". |
1183-
| `modelName` | String | This value is always `"WoSmartLock"`, which means "Lock". |
1184-
| `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
1185-
| `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
1186-
| `status` | String | This value indicates the current locked state. Possible values: |
1187-
| | | `"LOCKED"`, `"UNLOCKED"`, `"LOCKING"`, `"UNLOCKING"` |
1188-
| | | `"LOCKING_STOP"`, `"UNLOCKING_STOP"` (stuck when locking or unlocking respectively) |
1189-
| | | `"NOT_FULLY_LOCKED"` (eu model only), `"UNKNOWN"` (fallback: must be some error) |
1190-
| `update_from_secondary_lock` | Boolean | ?? |
1191-
| `door_open` | Boolean | door open status - whether the door is not detecting the sensor magnet |
1192-
| `double_lock_mode` | Boolean | dual lock mode enabled status - two locks working simultaneously |
1193-
| `unclosed_alarm` | Boolean | enabled status for door ajar alarm function |
1194-
| `unlocked_alarm` | Boolean | whether the alarm function is enabled for door left unlocked |
1195-
| `auto_lock_paused` | Boolean | auto lock mode paused |
1196-
| `night_latch` | Boolean | night latch mode enabled (eu firmware only) |
1197-
1188+
| Property | Type | Description |
1189+
| :--------------------------- | :------ | :---------------------------------------------------------------------------------- |
1190+
| `model` | String | This value is `"o"`, which means "Lock (WoSmartLock)". |
1191+
| `modelName` | String | This value is always `"WoSmartLock"`, which means "Lock". |
1192+
| `battery` | Integer | This value indicates the battery level (`1-100`, `%`). |
1193+
| `calibration` | Boolean | This value indicates the calibration status (`true` or `false`). |
1194+
| `status` | String | This value indicates the current locked state. Possible values: |
1195+
| | | `"LOCKED"`, `"UNLOCKED"`, `"LOCKING"`, `"UNLOCKING"` |
1196+
| | | `"LOCKING_STOP"`, `"UNLOCKING_STOP"` (stuck when locking or unlocking respectively) |
1197+
| | | `"NOT_FULLY_LOCKED"` (eu model only), `"UNKNOWN"` (fallback: must be some error) |
1198+
| `update_from_secondary_lock` | Boolean | ?? |
1199+
| `door_open` | Boolean | door open status - whether the door is not detecting the sensor magnet |
1200+
| `double_lock_mode` | Boolean | dual lock mode enabled status - two locks working simultaneously |
1201+
| `unclosed_alarm` | Boolean | enabled status for door ajar alarm function |
1202+
| `unlocked_alarm` | Boolean | whether the alarm function is enabled for door left unlocked |
1203+
| `auto_lock_paused` | Boolean | auto lock mode paused |
1204+
| `night_latch` | Boolean | night latch mode enabled (eu firmware only) |
11981205

11991206
## References
12001207

eslint.config.js

Lines changed: 46 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,50 @@
1-
import globals from "globals";
2-
import pluginJs from "@eslint/js";
3-
import tseslint from "typescript-eslint";
1+
import antfu from '@antfu/eslint-config'
42

5-
6-
export default [
7-
{ languageOptions: { globals: globals.browser } },
8-
pluginJs.configs.recommended,
9-
...tseslint.configs.recommended,
10-
{
11-
ignores: [".dist/*"]
12-
},
3+
export default antfu(
134
{
5+
ignores: ['dist', 'docs'],
6+
jsx: false,
7+
typescript: true,
8+
formatters: {
9+
markdown: true,
10+
},
1411
rules: {
15-
"quotes": [
16-
"warn",
17-
"single"
18-
],
19-
"indent": [
20-
"warn",
21-
2,
22-
{
23-
"SwitchCase": 1
24-
}
25-
],
26-
"linebreak-style": [
27-
"warn",
28-
"unix"
29-
],
30-
"semi": [
31-
"warn",
32-
"always"
33-
],
34-
"comma-dangle": [
35-
"warn",
36-
"always-multiline"
37-
],
38-
"dot-notation": "off",
39-
"eqeqeq": "warn",
40-
"curly": [
41-
"warn",
42-
"all"
43-
],
44-
"brace-style": [
45-
"warn"
46-
],
47-
"prefer-arrow-callback": [
48-
"warn"
49-
],
50-
"max-len": [
51-
"warn",
52-
150
53-
],
54-
"no-console": [
55-
"warn"
56-
], // use the provided Homebridge log method instead
57-
"no-non-null-assertion": [
58-
"off"
59-
],
60-
"comma-spacing": [
61-
"error"
62-
],
63-
"no-multi-spaces": [
64-
"warn",
12+
'curly': ['error', 'multi-line'],
13+
'import/extensions': ['error', 'ignorePackages'],
14+
'import/order': 0,
15+
'jsdoc/check-alignment': 'error',
16+
'jsdoc/check-line-alignment': 'error',
17+
'perfectionist/sort-exports': 'error',
18+
'perfectionist/sort-imports': [
19+
'error',
6520
{
66-
"ignoreEOLComments": true
67-
}
68-
],
69-
"no-trailing-spaces": [
70-
"warn"
71-
],
72-
"lines-between-class-members": [
73-
"warn",
74-
"always",
75-
{
76-
"exceptAfterSingleLine": true
77-
}
78-
],
79-
"@typescript-eslint/explicit-function-return-type": "off",
80-
"@typescript-eslint/no-non-null-assertion": "off",
81-
"@typescript-eslint/explicit-module-boundary-types": "off",
82-
"@typescript-eslint/no-explicit-any": "off"
83-
}
84-
}
85-
];
21+
groups: [
22+
'builtin-type',
23+
'external-type',
24+
'internal-type',
25+
['parent-type', 'sibling-type', 'index-type'],
26+
'builtin',
27+
'external',
28+
'internal',
29+
['parent', 'sibling', 'index'],
30+
'object',
31+
'unknown',
32+
],
33+
order: 'asc',
34+
type: 'natural',
35+
},
36+
],
37+
'perfectionist/sort-named-exports': 'error',
38+
'perfectionist/sort-named-imports': 'error',
39+
'sort-imports': 0,
40+
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
41+
'style/quote-props': ['error', 'consistent-as-needed'],
42+
'test/no-only-tests': 'error',
43+
'unicorn/no-useless-spread': 'error',
44+
'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }],
45+
'no-new': 0, // Disable the no-new rule
46+
'new-cap': 0, // Disable the new-cap rule
47+
'no-undef': 0, // Disable the no-undef rule
48+
},
49+
},
50+
)

0 commit comments

Comments
 (0)