node-switchbot 3.6.0-beta.1 → 3.6.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +165 -0
- package/CHANGELOG.md +23 -0
- package/dist/device.d.ts +247 -13
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +658 -78
- package/dist/device.js.map +1 -1
- package/dist/device.test.d.ts +2 -0
- package/dist/device.test.d.ts.map +1 -0
- package/dist/device.test.js +152 -0
- package/dist/device.test.js.map +1 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/parameter-checker.d.ts +1 -0
- package/dist/parameter-checker.d.ts.map +1 -1
- package/dist/parameter-checker.js +19 -11
- package/dist/parameter-checker.js.map +1 -1
- package/dist/parameter-checker.test.d.ts +2 -0
- package/dist/parameter-checker.test.d.ts.map +1 -0
- package/dist/parameter-checker.test.js +56 -0
- package/dist/parameter-checker.test.js.map +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +21 -16
- package/dist/settings.js.map +1 -1
- package/dist/settings.test.js +13 -1
- package/dist/settings.test.js.map +1 -1
- package/dist/switchbot-ble.d.ts +8 -11
- package/dist/switchbot-ble.d.ts.map +1 -1
- package/dist/switchbot-ble.js +88 -73
- package/dist/switchbot-ble.js.map +1 -1
- package/dist/switchbot-ble.test.d.ts +2 -0
- package/dist/switchbot-ble.test.d.ts.map +1 -0
- package/dist/switchbot-ble.test.js +32 -0
- package/dist/switchbot-ble.test.js.map +1 -0
- package/dist/switchbot-openapi.d.ts +4 -7
- package/dist/switchbot-openapi.d.ts.map +1 -1
- package/dist/switchbot-openapi.js +19 -10
- package/dist/switchbot-openapi.js.map +1 -1
- package/dist/switchbot-openapi.test.d.ts +2 -0
- package/dist/switchbot-openapi.test.d.ts.map +1 -0
- package/dist/switchbot-openapi.test.js +36 -0
- package/dist/switchbot-openapi.test.js.map +1 -0
- package/dist/types/ble-guards.d.ts +12 -0
- package/dist/types/ble-guards.d.ts.map +1 -0
- package/dist/types/ble-guards.js +10 -0
- package/dist/types/ble-guards.js.map +1 -0
- package/dist/types/ble-guards.test.d.ts +2 -0
- package/dist/types/ble-guards.test.d.ts.map +1 -0
- package/dist/types/ble-guards.test.js +62 -0
- package/dist/types/ble-guards.test.js.map +1 -0
- package/dist/types/{bledevicestatus.d.ts → ble.d.ts} +135 -116
- package/dist/types/ble.d.ts.map +1 -0
- package/dist/types/ble.js +2 -0
- package/dist/types/ble.js.map +1 -0
- package/dist/types/openapi.d.ts +623 -0
- package/dist/types/openapi.d.ts.map +1 -0
- package/dist/types/openapi.js +3 -0
- package/dist/types/openapi.js.map +1 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Advertising.html +4 -4
- package/docs/classes/ErrorUtils.html +25 -0
- package/docs/classes/ParameterChecker.html +69 -0
- package/docs/classes/SwitchBotBLE.html +9 -11
- package/docs/classes/SwitchBotOpenAPI.html +9 -9
- package/docs/classes/SwitchbotDevice.html +12 -12
- package/docs/classes/ValidationUtils.html +51 -0
- package/docs/classes/WoAirPurifier.html +83 -0
- package/docs/classes/WoAirPurifierTable.html +83 -0
- package/docs/classes/WoBlindTilt.html +21 -21
- package/docs/classes/WoBulb.html +19 -19
- package/docs/classes/WoCeilingLight.html +22 -22
- package/docs/classes/WoContact.html +13 -13
- package/docs/classes/WoCurtain.html +18 -18
- package/docs/classes/WoHand.html +18 -18
- package/docs/classes/WoHub2.html +13 -13
- package/docs/classes/WoHub3.html +52 -0
- package/docs/classes/WoHumi.html +20 -20
- package/docs/classes/WoHumi2.html +20 -20
- package/docs/classes/WoIOSensorTH.html +13 -13
- package/docs/classes/WoKeypad.html +13 -13
- package/docs/classes/WoLeak.html +13 -13
- package/docs/classes/WoPlugMiniJP.html +18 -18
- package/docs/classes/WoPlugMiniUS.html +18 -18
- package/docs/classes/WoPresence.html +13 -13
- package/docs/classes/WoRelaySwitch1.html +15 -15
- package/docs/classes/WoRelaySwitch1PM.html +15 -15
- package/docs/classes/WoRemote.html +13 -13
- package/docs/classes/WoSensorTH.html +12 -12
- package/docs/classes/WoSensorTHPlus.html +12 -12
- package/docs/classes/WoSensorTHPro.html +12 -12
- package/docs/classes/WoSensorTHProCO2.html +12 -12
- package/docs/classes/WoSmartLock.html +23 -23
- package/docs/classes/WoSmartLockPro.html +23 -23
- package/docs/classes/WoStrip.html +20 -20
- package/docs/enums/LogLevel.html +2 -2
- package/docs/enums/SwitchBotBLEModel.html +5 -2
- package/docs/enums/SwitchBotBLEModelFriendlyName.html +9 -2
- package/docs/enums/SwitchBotBLEModelName.html +5 -2
- package/docs/enums/SwitchBotModel.html +5 -2
- package/docs/functions/updateBaseURL.html +3 -0
- package/docs/hierarchy.html +1 -1
- package/docs/interfaces/AdvertisementData.html +2 -2
- package/docs/interfaces/Chars.html +2 -2
- package/docs/interfaces/ColorLightServiceDataBase.html +17 -0
- package/docs/interfaces/ErrorObject.html +2 -2
- package/docs/interfaces/LockBaseServiceData.html +15 -0
- package/docs/interfaces/NobleTypes.html +2 -3
- package/docs/interfaces/Params.html +2 -2
- package/docs/interfaces/PlugMiniServiceDataBase.html +12 -0
- package/docs/interfaces/Rule.html +2 -2
- package/docs/interfaces/ServiceData.html +2 -2
- package/docs/interfaces/SwitchBotBLEDevice.html +5 -2
- package/docs/interfaces/SwitchBotScanner.html +6 -0
- package/docs/interfaces/TemperatureServiceDataBase.html +10 -0
- package/docs/interfaces/WebhookDetail.html +2 -2
- package/docs/interfaces/ad.html +2 -2
- package/docs/interfaces/body.html +2 -2
- package/docs/interfaces/bodyChange.html +2 -2
- package/docs/interfaces/deleteWebhookResponse.html +2 -2
- package/docs/interfaces/device.html +2 -2
- package/docs/interfaces/deviceList.html +2 -2
- package/docs/interfaces/deviceStatus.html +2 -2
- package/docs/interfaces/deviceStatusRequest.html +2 -2
- package/docs/interfaces/deviceWebhook.html +2 -2
- package/docs/interfaces/deviceWebhookContext.html +2 -2
- package/docs/interfaces/devices.html +2 -2
- package/docs/interfaces/infraredRemoteList.html +2 -2
- package/docs/interfaces/irdevice.html +2 -2
- package/docs/interfaces/pushRequest.html +5 -0
- package/docs/interfaces/pushResponse.html +3 -2
- package/docs/interfaces/pushResponseBody.html +3 -0
- package/docs/interfaces/queryWebhookResponse.html +2 -2
- package/docs/interfaces/setupWebhookResponse.html +2 -2
- package/docs/interfaces/updateWebhookResponse.html +2 -2
- package/docs/interfaces/webhookRequest.html +2 -2
- package/docs/modules.html +1 -1
- package/docs/types/BLEDeviceServiceData.html +1 -0
- package/docs/types/{indoorCam.html → IndoorCam.html} +1 -1
- package/docs/types/MacAddress.html +1 -1
- package/docs/types/airPurifier.html +1 -0
- package/docs/types/airPurifierPM25WebhookContext.html +1 -0
- package/docs/types/airPurifierServiceData.html +1 -0
- package/docs/types/airPurifierStatus.html +1 -0
- package/docs/types/airPurifierTable.html +1 -0
- package/docs/types/airPurifierTablePM25WebhookContext.html +1 -0
- package/docs/types/airPurifierTableServiceData.html +1 -0
- package/docs/types/airPurifierTableStatus.html +1 -0
- package/docs/types/airPurifierTableVOC.html +1 -0
- package/docs/types/airPurifierTableVOCStatus.html +1 -0
- package/docs/types/airPurifierTableVOCWebhookContext.html +1 -0
- package/docs/types/airPurifierTableWebhookContext.html +1 -0
- package/docs/types/airPurifierVOC.html +1 -0
- package/docs/types/airPurifierVOCStatus.html +1 -0
- package/docs/types/airPurifierVOCWebhookContext.html +1 -0
- package/docs/types/airPurifierWebhookContext.html +1 -0
- package/docs/types/batteryCirculatorFan.html +1 -1
- package/docs/types/batteryCirculatorFanServiceData.html +1 -1
- package/docs/types/batteryCirculatorFanStatus.html +1 -1
- package/docs/types/batteryCirculatorFanWebhookContext.html +1 -1
- package/docs/types/blindTilt.html +1 -1
- package/docs/types/blindTiltServiceData.html +1 -1
- package/docs/types/blindTiltStatus.html +1 -1
- package/docs/types/blindTiltWebhookContext.html +1 -1
- package/docs/types/bot.html +1 -1
- package/docs/types/botServiceData.html +1 -1
- package/docs/types/botStatus.html +1 -1
- package/docs/types/botWebhookContext.html +1 -1
- package/docs/types/ceilingLight.html +1 -1
- package/docs/types/ceilingLightPro.html +1 -1
- package/docs/types/ceilingLightProServiceData.html +1 -1
- package/docs/types/ceilingLightProStatus.html +1 -1
- package/docs/types/ceilingLightProWebhookContext.html +1 -1
- package/docs/types/ceilingLightServiceData.html +1 -1
- package/docs/types/ceilingLightStatus.html +1 -1
- package/docs/types/ceilingLightWebhookContext.html +1 -1
- package/docs/types/circulatorFanStatus.html +1 -1
- package/docs/types/circulatorFanWebhookContext.html +1 -1
- package/docs/types/colorBulb.html +1 -1
- package/docs/types/colorBulbServiceData.html +1 -1
- package/docs/types/colorBulbStatus.html +1 -1
- package/docs/types/colorBulbWebhookContext.html +1 -1
- package/docs/types/commandType.html +2 -0
- package/docs/types/contactSensor.html +1 -1
- package/docs/types/contactSensorServiceData.html +1 -1
- package/docs/types/contactSensorStatus.html +1 -1
- package/docs/types/contactSensorWebhookContext.html +1 -1
- package/docs/types/curtain.html +1 -1
- package/docs/types/curtain3.html +1 -1
- package/docs/types/curtain3ServiceData.html +1 -1
- package/docs/types/curtain3WebhookContext.html +1 -1
- package/docs/types/curtainServiceData.html +1 -1
- package/docs/types/curtainStatus.html +1 -1
- package/docs/types/curtainWebhookContext.html +1 -1
- package/docs/types/floorCleaningRobotS10.html +1 -1
- package/docs/types/floorCleaningRobotS10Status.html +1 -1
- package/docs/types/floorCleaningRobotS10WebhookContext.html +1 -1
- package/docs/types/hub2.html +1 -1
- package/docs/types/hub2ServiceData.html +1 -1
- package/docs/types/hub2Status.html +1 -1
- package/docs/types/hub2WebhookContext.html +1 -1
- package/docs/types/hub3ServiceData.html +1 -0
- package/docs/types/humidifier.html +1 -1
- package/docs/types/humidifier2ServiceData.html +1 -1
- package/docs/types/humidifier2Status.html +1 -1
- package/docs/types/humidifier2WebhookContext.html +1 -1
- package/docs/types/humidifierServiceData.html +1 -1
- package/docs/types/humidifierStatus.html +1 -1
- package/docs/types/humidifierWebhookContext.html +1 -1
- package/docs/types/indoorCameraWebhookContext.html +1 -1
- package/docs/types/keypad.html +1 -1
- package/docs/types/keypadDetectorServiceData.html +1 -1
- package/docs/types/keypadTouch.html +1 -1
- package/docs/types/keypadTouchWebhookContext.html +1 -1
- package/docs/types/keypadWebhookContext.html +1 -1
- package/docs/types/lock.html +1 -1
- package/docs/types/lockPro.html +1 -1
- package/docs/types/lockProServiceData.html +1 -1
- package/docs/types/lockProStatus.html +1 -1
- package/docs/types/lockProWebhookContext.html +1 -1
- package/docs/types/lockServiceData.html +1 -1
- package/docs/types/lockStatus.html +1 -1
- package/docs/types/lockWebhookContext.html +1 -1
- package/docs/types/meter.html +1 -1
- package/docs/types/meterPlus.html +1 -1
- package/docs/types/meterPlusServiceData.html +1 -1
- package/docs/types/meterPlusStatus.html +1 -1
- package/docs/types/meterPlusWebhookContext.html +1 -1
- package/docs/types/meterPro.html +1 -1
- package/docs/types/meterProCO2ServiceData.html +1 -1
- package/docs/types/meterProCO2Status.html +1 -1
- package/docs/types/meterProCO2WebhookContext.html +1 -1
- package/docs/types/meterProServiceData.html +1 -1
- package/docs/types/meterProStatus.html +1 -1
- package/docs/types/meterProWebhookContext.html +1 -1
- package/docs/types/meterServiceData.html +1 -1
- package/docs/types/meterStatus.html +1 -1
- package/docs/types/meterWebhookContext.html +1 -1
- package/docs/types/motionSensor.html +1 -1
- package/docs/types/motionSensorServiceData.html +1 -1
- package/docs/types/motionSensorStatus.html +1 -1
- package/docs/types/motionSensorWebhookContext.html +1 -1
- package/docs/types/onadvertisement.html +1 -1
- package/docs/types/ondiscover.html +1 -1
- package/docs/types/outdoorMeter.html +1 -1
- package/docs/types/outdoorMeterServiceData.html +1 -1
- package/docs/types/outdoorMeterStatus.html +1 -1
- package/docs/types/outdoorMeterWebhookContext.html +1 -1
- package/docs/types/panTiltCamWebhookContext.html +1 -1
- package/docs/types/pantiltCam.html +1 -1
- package/docs/types/pantiltCam2k.html +1 -1
- package/docs/types/plug.html +1 -1
- package/docs/types/plugMini.html +1 -1
- package/docs/types/plugMiniJPServiceData.html +1 -1
- package/docs/types/plugMiniJPWebhookContext.html +1 -1
- package/docs/types/plugMiniStatus.html +1 -1
- package/docs/types/plugMiniUSServiceData.html +1 -1
- package/docs/types/plugMiniUSWebhookContext.html +1 -1
- package/docs/types/plugStatus.html +1 -1
- package/docs/types/plugWebhookContext.html +1 -1
- package/docs/types/relaySwitch1Context.html +1 -1
- package/docs/types/relaySwitch1PMContext.html +1 -1
- package/docs/types/relaySwitch1PMServiceData.html +1 -1
- package/docs/types/relaySwitch1PMStatus.html +1 -1
- package/docs/types/relaySwitch1ServiceData.html +1 -1
- package/docs/types/relaySwitch1Status.html +1 -1
- package/docs/types/remote.html +1 -1
- package/docs/types/remoteServiceData.html +1 -1
- package/docs/types/robotVacuumCleanerS1.html +1 -1
- package/docs/types/robotVacuumCleanerS1Plus.html +1 -1
- package/docs/types/robotVacuumCleanerS1PlusStatus.html +1 -1
- package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +1 -1
- package/docs/types/robotVacuumCleanerS1Status.html +1 -1
- package/docs/types/robotVacuumCleanerS1WebhookContext.html +1 -1
- package/docs/types/robotVacuumCleanerServiceData.html +1 -1
- package/docs/types/stripLight.html +1 -1
- package/docs/types/stripLightServiceData.html +1 -1
- package/docs/types/stripLightStatus.html +1 -1
- package/docs/types/stripLightWebhookContext.html +1 -1
- package/docs/types/waterLeakDetector.html +1 -1
- package/docs/types/waterLeakDetectorServiceData.html +1 -1
- package/docs/types/waterLeakDetectorStatus.html +1 -1
- package/docs/types/waterLeakDetectorWebhookContext.html +1 -1
- package/docs/variables/parameterChecker.html +1 -0
- package/docs/variables/urls.html +1 -0
- package/package.json +8 -8
- package/dist/types/bledevicestatus.d.ts.map +0 -1
- package/dist/types/bledevicestatus.js +0 -2
- package/dist/types/bledevicestatus.js.map +0 -1
- package/dist/types/devicelist.d.ts +0 -90
- package/dist/types/devicelist.d.ts.map +0 -1
- package/dist/types/devicelist.js +0 -2
- package/dist/types/devicelist.js.map +0 -1
- package/dist/types/devicepush.d.ts +0 -13
- package/dist/types/devicepush.d.ts.map +0 -1
- package/dist/types/devicepush.js +0 -2
- package/dist/types/devicepush.js.map +0 -1
- package/dist/types/deviceresponse.d.ts +0 -12
- package/dist/types/deviceresponse.d.ts.map +0 -1
- package/dist/types/deviceresponse.js +0 -2
- package/dist/types/deviceresponse.js.map +0 -1
- package/dist/types/devicestatus.d.ts +0 -194
- package/dist/types/devicestatus.d.ts.map +0 -1
- package/dist/types/devicestatus.js +0 -3
- package/dist/types/devicestatus.js.map +0 -1
- package/dist/types/devicewebhookstatus.d.ts +0 -236
- package/dist/types/devicewebhookstatus.d.ts.map +0 -1
- package/dist/types/devicewebhookstatus.js +0 -2
- package/dist/types/devicewebhookstatus.js.map +0 -1
- package/dist/types/irdevicelist.d.ts +0 -10
- package/dist/types/irdevicelist.d.ts.map +0 -1
- package/dist/types/irdevicelist.js +0 -2
- package/dist/types/irdevicelist.js.map +0 -1
- package/docs/interfaces/switchbot.html +0 -3
- package/jest.config.js +0 -3
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Node-SwitchBot Development Instructions
|
|
2
|
+
|
|
3
|
+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
|
|
4
|
+
|
|
5
|
+
## Working Effectively
|
|
6
|
+
|
|
7
|
+
### Bootstrap and Setup
|
|
8
|
+
- Install Node.js (^20 || ^22 || ^24): Use the existing version if available
|
|
9
|
+
- Install dependencies: `npm install` -- takes ~5-25 seconds (varies by cache). **NEVER CANCEL**
|
|
10
|
+
- Build the project: `npm run build` -- takes ~5 seconds. **NEVER CANCEL**
|
|
11
|
+
- Run tests: `npm run test` -- takes ~1 second with 12 tests. **NEVER CANCEL**
|
|
12
|
+
|
|
13
|
+
### Development Workflow
|
|
14
|
+
- **ALWAYS run these commands in order when starting work:**
|
|
15
|
+
1. `npm install`
|
|
16
|
+
2. `npm run build`
|
|
17
|
+
3. `npm run test`
|
|
18
|
+
4. `npm run lint`
|
|
19
|
+
- **Build and validate EVERY change**: After any code modification, always run `npm run build && npm run test && npm run lint`
|
|
20
|
+
- **NEVER skip linting**: Run `npm run lint` before committing or the CI (.github/workflows/build.yml) will fail
|
|
21
|
+
- **Use lint:fix for automatic fixes**: `npm run lint:fix` to automatically fix ESLint issues
|
|
22
|
+
|
|
23
|
+
### Platform Requirements and Constraints
|
|
24
|
+
- **BLE functionality requires Linux-based OS only** (Raspbian, Ubuntu, etc.)
|
|
25
|
+
- **Windows and macOS are NOT supported** for BLE operations (use OpenAPI instead)
|
|
26
|
+
- **Node.js versions**: Must use ^20, ^22, or ^24 (currently using v20.19.4)
|
|
27
|
+
- **ES Modules**: This project uses `"type": "module"` - always use ES import/export syntax
|
|
28
|
+
|
|
29
|
+
### Testing and Validation
|
|
30
|
+
- **Basic functionality test**: After any changes to core classes, run this validation:
|
|
31
|
+
```javascript
|
|
32
|
+
const { SwitchBotBLE, SwitchBotOpenAPI } = require('./dist/index.js');
|
|
33
|
+
const ble = new SwitchBotBLE(); // Should not throw
|
|
34
|
+
const api = new SwitchBotOpenAPI('test', 'test'); // Should not throw
|
|
35
|
+
```
|
|
36
|
+
- **Complete test suite**: `npm run test` (12 tests) -- should always pass before committing
|
|
37
|
+
- **Test coverage**: `npm run test-coverage` to see coverage report (~15% coverage is normal)
|
|
38
|
+
- **Documentation generation**: `npm run docs` generates TypeDoc documentation in ./docs/
|
|
39
|
+
|
|
40
|
+
### Build and Timing Expectations
|
|
41
|
+
- **npm install**: ~5-25 seconds (varies by cache) -- **NEVER CANCEL**. Set timeout to 5+ minutes for safety
|
|
42
|
+
- **npm run build**: ~5 seconds -- **NEVER CANCEL**. Set timeout to 2+ minutes for safety
|
|
43
|
+
- **npm run test**: ~1 second (12 tests) -- **NEVER CANCEL**. Set timeout to 2+ minutes for safety
|
|
44
|
+
- **npm run lint**: ~3 seconds -- **NEVER CANCEL**. Set timeout to 2+ minutes for safety
|
|
45
|
+
- **npm run docs**: ~2 seconds -- **NEVER CANCEL**. Set timeout to 2+ minutes for safety
|
|
46
|
+
|
|
47
|
+
## Project Structure and Key Files
|
|
48
|
+
|
|
49
|
+
### Source Code Organization
|
|
50
|
+
- **src/index.ts**: Main export file - exports SwitchBotBLE, SwitchBotOpenAPI, and device classes
|
|
51
|
+
- **src/switchbot-ble.ts**: Bluetooth Low Energy interface for direct device control
|
|
52
|
+
- **src/switchbot-openapi.ts**: HTTP API interface for cloud-based SwitchBot control
|
|
53
|
+
- **src/device.ts**: Individual device classes (WoHand, WoCurtain, WoSmartLock, etc.)
|
|
54
|
+
- **src/types/**: TypeScript type definitions for all device interfaces
|
|
55
|
+
- **src/settings.ts**: Configuration constants and API URLs
|
|
56
|
+
- **dist/**: Compiled JavaScript output (generated by `npm run build`)
|
|
57
|
+
|
|
58
|
+
### Configuration Files
|
|
59
|
+
- **package.json**: Main project config - scripts, dependencies, ES module config
|
|
60
|
+
- **tsconfig.json**: TypeScript compilation settings (target: ES2022, module: ES2022)
|
|
61
|
+
- **eslint.config.js**: ESLint configuration using @antfu/eslint-config
|
|
62
|
+
- **jest.config.js**: Test configuration (uses Vitest, not Jest)
|
|
63
|
+
- **.gitignore**: Excludes dist/, node_modules/, coverage/, and build artifacts
|
|
64
|
+
|
|
65
|
+
### Documentation
|
|
66
|
+
- **README.md**: Main project documentation and installation instructions
|
|
67
|
+
- **BLE.md**: Comprehensive BLE usage documentation and device examples
|
|
68
|
+
- **OpenAPI.md**: OpenAPI usage documentation and authentication setup
|
|
69
|
+
- **CHANGELOG.md**: Version history and release notes
|
|
70
|
+
- **docs/**: Generated TypeDoc API documentation (HTML format)
|
|
71
|
+
|
|
72
|
+
## Common Development Tasks
|
|
73
|
+
|
|
74
|
+
### Adding New Device Support
|
|
75
|
+
- **Add device class**: Create new class in src/device.ts extending SwitchbotDevice
|
|
76
|
+
- **Update exports**: Add export to src/index.ts
|
|
77
|
+
- **Add type definitions**: Create types in src/types/ if needed
|
|
78
|
+
- **Test basic instantiation**: Ensure the device class can be imported and instantiated
|
|
79
|
+
- **Always run full build and test cycle**: `npm run build && npm run test && npm run lint`
|
|
80
|
+
|
|
81
|
+
### API Changes and Extensions
|
|
82
|
+
- **OpenAPI changes**: Modify src/switchbot-openapi.ts
|
|
83
|
+
- **BLE changes**: Modify src/switchbot-ble.ts
|
|
84
|
+
- **Update type definitions**: Modify corresponding files in src/types/
|
|
85
|
+
- **Always verify exports**: Check that new functionality is exported in src/index.ts
|
|
86
|
+
- **Test import functionality**: Verify new exports can be imported correctly
|
|
87
|
+
|
|
88
|
+
### Working with Dependencies
|
|
89
|
+
- **Noble (BLE)**: @stoprocent/noble for Bluetooth functionality - Linux only
|
|
90
|
+
- **HTTP requests**: Uses undici for HTTP calls (not axios or fetch)
|
|
91
|
+
- **Async operations**: Uses async-mutex for concurrency control
|
|
92
|
+
- **Adding dependencies**: Use `npm install --save` for runtime deps, `--save-dev` for dev deps
|
|
93
|
+
|
|
94
|
+
## Validation and Quality Assurance
|
|
95
|
+
|
|
96
|
+
### Pre-commit Checklist
|
|
97
|
+
1. **Build succeeds**: `npm run build` completes without errors
|
|
98
|
+
2. **All tests pass**: `npm run test` shows all 12 tests passing
|
|
99
|
+
3. **Linting passes**: `npm run lint` shows no errors
|
|
100
|
+
4. **Documentation builds**: `npm run docs` generates without warnings
|
|
101
|
+
5. **Basic import works**: Can import and instantiate main classes
|
|
102
|
+
|
|
103
|
+
### Manual Testing Scenarios
|
|
104
|
+
- **SwitchBotBLE instantiation**: `new SwitchBotBLE()` should not throw errors
|
|
105
|
+
- **SwitchBotOpenAPI instantiation**: `new SwitchBotOpenAPI('token', 'secret')` should not throw
|
|
106
|
+
- **Module exports**: All exported classes should be importable from main package
|
|
107
|
+
- **TypeScript compilation**: No TypeScript errors in dist/ output
|
|
108
|
+
- **Documentation completeness**: Check that new public APIs appear in generated docs
|
|
109
|
+
|
|
110
|
+
### CI/CD Integration
|
|
111
|
+
- **GitHub Actions**: Build runs on push to 'latest' branch and PRs
|
|
112
|
+
- **External workflows**: Uses OpenWonderLabs/.github/.github/workflows/nodejs-build-and-test.yml
|
|
113
|
+
- **Required checks**: Build, test, and lint must all pass
|
|
114
|
+
- **Coverage reporting**: Test coverage is tracked and reported
|
|
115
|
+
|
|
116
|
+
## Troubleshooting Common Issues
|
|
117
|
+
|
|
118
|
+
### BLE Not Working
|
|
119
|
+
- **Check OS**: BLE only works on Linux-based systems
|
|
120
|
+
- **Install noble prerequisites**: May need additional system libraries for @stoprocent/noble
|
|
121
|
+
- **Use OpenAPI instead**: For Windows/macOS development, use SwitchBotOpenAPI class
|
|
122
|
+
|
|
123
|
+
### Build Failures
|
|
124
|
+
- **Check Node.js version**: Must be ^20, ^22, or ^24
|
|
125
|
+
- **Clean and rebuild**: `npm run clean && npm install && npm run build`
|
|
126
|
+
- **TypeScript errors**: Check tsconfig.json settings and type definitions
|
|
127
|
+
|
|
128
|
+
### Test Failures
|
|
129
|
+
- **Run individual tests**: Use `npm run test:watch` for interactive testing
|
|
130
|
+
- **Check imports**: Ensure all imports use correct ES module syntax
|
|
131
|
+
- **Verify exports**: Check that src/index.ts exports all necessary components
|
|
132
|
+
|
|
133
|
+
### Linting Errors
|
|
134
|
+
- **Auto-fix**: Use `npm run lint:fix` to automatically fix many issues
|
|
135
|
+
- **ESLint config**: Review eslint.config.js for current rules
|
|
136
|
+
- **Import sorting**: ESLint enforces specific import order - use lint:fix
|
|
137
|
+
|
|
138
|
+
## Frequently Referenced Information
|
|
139
|
+
|
|
140
|
+
### Package Scripts (from package.json)
|
|
141
|
+
```bash
|
|
142
|
+
npm run build # Clean and compile TypeScript
|
|
143
|
+
npm run test # Run test suite with Vitest
|
|
144
|
+
npm run lint # Run ESLint on src/**/*.ts
|
|
145
|
+
npm run lint:fix # Auto-fix ESLint issues
|
|
146
|
+
npm run docs # Generate TypeDoc documentation
|
|
147
|
+
npm run clean # Remove dist/ directory
|
|
148
|
+
npm run watch # Build and link for development
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Main Exports (from src/index.ts)
|
|
152
|
+
- **SwitchBotBLE**: Bluetooth interface class
|
|
153
|
+
- **SwitchBotOpenAPI**: HTTP API interface class
|
|
154
|
+
- **SwitchbotDevice**: Base device class
|
|
155
|
+
- **Device classes**: WoHand, WoCurtain, WoSmartLock, etc.
|
|
156
|
+
- **Type definitions**: All device status and response types
|
|
157
|
+
|
|
158
|
+
### Dependencies Summary
|
|
159
|
+
- **@stoprocent/noble**: BLE functionality (Linux only)
|
|
160
|
+
- **undici**: HTTP client for API requests
|
|
161
|
+
- **async-mutex**: Concurrency control
|
|
162
|
+
- **TypeScript**: Language and compilation
|
|
163
|
+
- **Vitest**: Testing framework
|
|
164
|
+
- **ESLint**: Code linting with @antfu/eslint-config
|
|
165
|
+
- **TypeDoc**: API documentation generation
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
|
|
4
4
|
|
|
5
|
+
## [3.6.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v3.6.0) (2025-08-27)
|
|
6
|
+
|
|
7
|
+
### What's Changed
|
|
8
|
+
- Housekeeping and update dependencies
|
|
9
|
+
- **BREAKING**: Fixed compatibility with `@stoprocent/noble` v2.3.4 and `@stoprocent/bluetooth-hci-socket` v2.2.3
|
|
10
|
+
- **Enhancement**: Added comprehensive input validation utilities (`ValidationUtils` class)
|
|
11
|
+
- **Enhancement**: Improved error handling with more descriptive error messages
|
|
12
|
+
- **Enhancement**: Added command constants to replace magic numbers for better maintainability
|
|
13
|
+
- **Enhancement**: Enhanced type safety with proper TypeScript assertions
|
|
14
|
+
- **Enhancement**: Improved buffer validation with configurable minimum length
|
|
15
|
+
- **Enhancement**: Better resource cleanup in error scenarios with try-catch-finally blocks
|
|
16
|
+
- **Enhancement**: Removed deprecated parameter checker in favor of modern validation
|
|
17
|
+
- **Fix**: Updated `noble._state` to `noble.state` for compatibility with newer noble versions
|
|
18
|
+
- **Fix**: Enhanced NobleTypes interface to properly support newer noble version
|
|
19
|
+
- **Code Quality**: Improved JSDoc documentation throughout device classes
|
|
20
|
+
- **Code Quality**: Standardized validation across all device classes
|
|
21
|
+
- **Docs**: Updated BLE.md and OpenAPI.md for new validation and error handling features
|
|
22
|
+
- **Internal**: Refactored device instantiation logic for consistency
|
|
23
|
+
- **Internal**: Improved test coverage for validation utilities and error scenarios
|
|
24
|
+
- **Chore**: Synced package scripts and documentation with latest development workflow
|
|
25
|
+
|
|
26
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v3.5.1...v3.6.0
|
|
27
|
+
|
|
5
28
|
## [3.5.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v3.5.1) (2025-07-25)
|
|
6
29
|
|
|
7
30
|
### What's Changed
|
package/dist/device.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type Noble from '@stoprocent/noble';
|
|
2
|
-
import type {
|
|
3
|
-
import type { batteryCirculatorFanServiceData, blindTiltServiceData, botServiceData, ceilingLightProServiceData, ceilingLightServiceData, colorBulbServiceData, contactSensorServiceData, curtain3ServiceData, curtainServiceData, hub2ServiceData, humidifier2ServiceData, humidifierServiceData, keypadDetectorServiceData, lockProServiceData, lockServiceData, meterPlusServiceData, meterProCO2ServiceData, meterProServiceData, meterServiceData, motionSensorServiceData, outdoorMeterServiceData, plugMiniJPServiceData, plugMiniUSServiceData, relaySwitch1PMServiceData, relaySwitch1ServiceData, remoteServiceData, robotVacuumCleanerServiceData, stripLightServiceData, waterLeakDetectorServiceData } from './types/bledevicestatus.js';
|
|
1
|
+
import type { Characteristic, Noble, Peripheral } from '@stoprocent/noble';
|
|
2
|
+
import type { airPurifierServiceData, airPurifierTableServiceData, batteryCirculatorFanServiceData, blindTiltServiceData, botServiceData, ceilingLightProServiceData, ceilingLightServiceData, colorBulbServiceData, contactSensorServiceData, curtain3ServiceData, curtainServiceData, hub2ServiceData, hub3ServiceData, humidifier2ServiceData, humidifierServiceData, keypadDetectorServiceData, lockProServiceData, lockServiceData, meterPlusServiceData, meterProCO2ServiceData, meterProServiceData, meterServiceData, motionSensorServiceData, outdoorMeterServiceData, plugMiniJPServiceData, plugMiniUSServiceData, relaySwitch1PMServiceData, relaySwitch1ServiceData, remoteServiceData, robotVacuumCleanerServiceData, stripLightServiceData, waterLeakDetectorServiceData } from './types/ble.js';
|
|
4
3
|
import { Buffer } from 'node:buffer';
|
|
5
4
|
import { EventEmitter } from 'node:events';
|
|
6
5
|
export type MacAddress = string;
|
|
@@ -8,7 +7,7 @@ export interface ad {
|
|
|
8
7
|
id: string;
|
|
9
8
|
address: string;
|
|
10
9
|
rssi: number;
|
|
11
|
-
serviceData: botServiceData | colorBulbServiceData | contactSensorServiceData | curtainServiceData | curtain3ServiceData | stripLightServiceData | lockServiceData | lockProServiceData | meterServiceData | meterPlusServiceData | meterProServiceData | meterProCO2ServiceData | motionSensorServiceData | outdoorMeterServiceData | plugMiniUSServiceData | plugMiniJPServiceData | blindTiltServiceData | ceilingLightServiceData | ceilingLightProServiceData | hub2ServiceData | batteryCirculatorFanServiceData | waterLeakDetectorServiceData | humidifierServiceData | humidifier2ServiceData | robotVacuumCleanerServiceData | keypadDetectorServiceData | relaySwitch1PMServiceData | relaySwitch1ServiceData | remoteServiceData;
|
|
10
|
+
serviceData: airPurifierServiceData | airPurifierTableServiceData | botServiceData | colorBulbServiceData | contactSensorServiceData | curtainServiceData | curtain3ServiceData | stripLightServiceData | lockServiceData | lockProServiceData | meterServiceData | meterPlusServiceData | meterProServiceData | meterProCO2ServiceData | motionSensorServiceData | outdoorMeterServiceData | plugMiniUSServiceData | plugMiniJPServiceData | blindTiltServiceData | ceilingLightServiceData | ceilingLightProServiceData | hub2ServiceData | hub3ServiceData | batteryCirculatorFanServiceData | waterLeakDetectorServiceData | humidifierServiceData | humidifier2ServiceData | robotVacuumCleanerServiceData | keypadDetectorServiceData | relaySwitch1PMServiceData | relaySwitch1ServiceData | remoteServiceData;
|
|
12
11
|
[key: string]: unknown;
|
|
13
12
|
}
|
|
14
13
|
export type ondiscover = (device: SwitchbotDevice) => Promise<void> | void;
|
|
@@ -29,6 +28,7 @@ export declare interface SwitchBotBLEDevice {
|
|
|
29
28
|
MeterPro: DeviceInfo;
|
|
30
29
|
MeterProCO2: DeviceInfo;
|
|
31
30
|
Hub2: DeviceInfo;
|
|
31
|
+
Hub3: DeviceInfo;
|
|
32
32
|
OutdoorMeter: DeviceInfo;
|
|
33
33
|
MotionSensor: DeviceInfo;
|
|
34
34
|
ContactSensor: DeviceInfo;
|
|
@@ -42,11 +42,14 @@ export declare interface SwitchBotBLEDevice {
|
|
|
42
42
|
CeilingLightPro: DeviceInfo;
|
|
43
43
|
BlindTilt: DeviceInfo;
|
|
44
44
|
Unknown: DeviceInfo;
|
|
45
|
+
AirPurifier: DeviceInfo;
|
|
46
|
+
AirPurifierTable: DeviceInfo;
|
|
45
47
|
}
|
|
46
48
|
export declare enum SwitchBotModel {
|
|
47
49
|
HubMini = "W0202200",
|
|
48
50
|
HubPlus = "SwitchBot Hub S1",
|
|
49
51
|
Hub2 = "W3202100",
|
|
52
|
+
Hub3 = "W3302100",
|
|
50
53
|
Bot = "SwitchBot S1",
|
|
51
54
|
Curtain = "W0701600",
|
|
52
55
|
Curtain3 = "W2400000",
|
|
@@ -89,7 +92,9 @@ export declare enum SwitchBotModel {
|
|
|
89
92
|
WaterDetector = "W4402000",
|
|
90
93
|
RelaySwitch1 = "W5502300",
|
|
91
94
|
RelaySwitch1PM = "W5502310",
|
|
92
|
-
Unknown = "Unknown"
|
|
95
|
+
Unknown = "Unknown",
|
|
96
|
+
AirPurifier = "W5302300",
|
|
97
|
+
AirPurifierTable = "W5302310"
|
|
93
98
|
}
|
|
94
99
|
export declare enum SwitchBotBLEModel {
|
|
95
100
|
Bot = "H",
|
|
@@ -102,6 +107,7 @@ export declare enum SwitchBotBLEModel {
|
|
|
102
107
|
MeterPro = "4",
|
|
103
108
|
MeterProCO2 = "5",
|
|
104
109
|
Hub2 = "v",
|
|
110
|
+
Hub3 = "V",
|
|
105
111
|
OutdoorMeter = "w",
|
|
106
112
|
MotionSensor = "s",
|
|
107
113
|
ContactSensor = "d",
|
|
@@ -119,11 +125,14 @@ export declare enum SwitchBotBLEModel {
|
|
|
119
125
|
RelaySwitch1 = ";",
|
|
120
126
|
RelaySwitch1PM = "<",
|
|
121
127
|
Remote = "b",
|
|
122
|
-
Unknown = "Unknown"
|
|
128
|
+
Unknown = "Unknown",
|
|
129
|
+
AirPurifier = "+",
|
|
130
|
+
AirPurifierTable = "7"
|
|
123
131
|
}
|
|
124
132
|
export declare enum SwitchBotBLEModelName {
|
|
125
133
|
Bot = "WoHand",
|
|
126
134
|
Hub2 = "WoHub2",
|
|
135
|
+
Hub3 = "WoHub3",
|
|
127
136
|
ColorBulb = "WoBulb",
|
|
128
137
|
Curtain = "WoCurtain",
|
|
129
138
|
Curtain3 = "WoCurtain3",
|
|
@@ -148,11 +157,14 @@ export declare enum SwitchBotBLEModelName {
|
|
|
148
157
|
RelaySwitch1 = "WoRelaySwitch1Plus",
|
|
149
158
|
RelaySwitch1PM = "WoRelaySwitch1PM",
|
|
150
159
|
Remote = "WoRemote",
|
|
160
|
+
AirPurifier = "WoAirPurifier",
|
|
161
|
+
AirPurifierTable = "WoAirPurifierTable",
|
|
151
162
|
Unknown = "Unknown"
|
|
152
163
|
}
|
|
153
164
|
export declare enum SwitchBotBLEModelFriendlyName {
|
|
154
165
|
Bot = "Bot",
|
|
155
166
|
Hub2 = "Hub 2",
|
|
167
|
+
Hub3 = "Hub 3",
|
|
156
168
|
ColorBulb = "Color Bulb",
|
|
157
169
|
Curtain = "Curtain",
|
|
158
170
|
Curtain3 = "Curtain 3",
|
|
@@ -179,14 +191,20 @@ export declare enum SwitchBotBLEModelFriendlyName {
|
|
|
179
191
|
RelaySwitch1 = "Relay Switch 1",
|
|
180
192
|
RelaySwitch1PM = "Relay Switch 1PM",
|
|
181
193
|
Remote = "Remote",
|
|
182
|
-
|
|
194
|
+
AirPurifier = "Air Purifier",
|
|
195
|
+
AirPurifierTable = "Air Purifier Table",
|
|
196
|
+
Unknown = "Unknown",
|
|
197
|
+
AirPurifierVOC = "Air Purifier VOC",
|
|
198
|
+
AirPurifierTableVOC = "Air Purifier Table VOC",
|
|
199
|
+
AirPurifierPM2_5 = "Air Purifier PM2.5",
|
|
200
|
+
AirPurifierTablePM2_5 = "Air Purifier Table PM2.5"
|
|
183
201
|
}
|
|
184
202
|
export interface Params {
|
|
185
203
|
duration?: number;
|
|
186
204
|
model?: string;
|
|
187
205
|
id?: string;
|
|
188
206
|
quick?: boolean;
|
|
189
|
-
noble?:
|
|
207
|
+
noble?: Noble;
|
|
190
208
|
}
|
|
191
209
|
export interface ErrorObject {
|
|
192
210
|
code: string;
|
|
@@ -198,8 +216,7 @@ export interface Chars {
|
|
|
198
216
|
device: Characteristic | null;
|
|
199
217
|
}
|
|
200
218
|
export interface NobleTypes {
|
|
201
|
-
noble:
|
|
202
|
-
state: 'unknown' | 'resetting' | 'unsupported' | 'unauthorized' | 'poweredOff' | 'poweredOn';
|
|
219
|
+
noble: Noble;
|
|
203
220
|
peripheral: Peripheral;
|
|
204
221
|
}
|
|
205
222
|
export interface ServiceData {
|
|
@@ -233,6 +250,108 @@ export declare enum LogLevel {
|
|
|
233
250
|
DEBUG = "debug",
|
|
234
251
|
INFO = "info"
|
|
235
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Utility class for comprehensive input validation with improved error messages.
|
|
255
|
+
*/
|
|
256
|
+
export declare class ValidationUtils {
|
|
257
|
+
/**
|
|
258
|
+
* Validates percentage value (0-100).
|
|
259
|
+
* @param value - The value to validate
|
|
260
|
+
* @param paramName - The parameter name for error reporting
|
|
261
|
+
* @throws {RangeError} When value is not within valid range
|
|
262
|
+
* @throws {TypeError} When value is not a number
|
|
263
|
+
*/
|
|
264
|
+
static validatePercentage(value: number, paramName?: string): void;
|
|
265
|
+
/**
|
|
266
|
+
* Validates RGB color value (0-255).
|
|
267
|
+
* @param value - The color value to validate
|
|
268
|
+
* @param colorName - The color name for error reporting
|
|
269
|
+
* @throws {RangeError} When value is not within valid range
|
|
270
|
+
* @throws {TypeError} When value is not a number
|
|
271
|
+
*/
|
|
272
|
+
static validateRGB(value: number, colorName?: string): void;
|
|
273
|
+
/**
|
|
274
|
+
* Validates buffer and throws descriptive error.
|
|
275
|
+
* @param buffer - The buffer to validate
|
|
276
|
+
* @param expectedLength - Optional expected length
|
|
277
|
+
* @param paramName - The parameter name for error reporting
|
|
278
|
+
* @throws {TypeError} When buffer is not a Buffer
|
|
279
|
+
* @throws {RangeError} When buffer length doesn't match expected
|
|
280
|
+
*/
|
|
281
|
+
static validateBuffer(buffer: any, expectedLength?: number, paramName?: string): asserts buffer is Buffer;
|
|
282
|
+
/**
|
|
283
|
+
* Validates string input with comprehensive checks.
|
|
284
|
+
* @param value - The value to validate
|
|
285
|
+
* @param paramName - The parameter name for error reporting
|
|
286
|
+
* @param minLength - Minimum required length
|
|
287
|
+
* @param maxLength - Optional maximum length
|
|
288
|
+
* @throws {TypeError} When value is not a string
|
|
289
|
+
* @throws {RangeError} When string length is invalid
|
|
290
|
+
*/
|
|
291
|
+
static validateString(value: any, paramName?: string, minLength?: number, maxLength?: number): asserts value is string;
|
|
292
|
+
/**
|
|
293
|
+
* Validates numeric range with enhanced checks.
|
|
294
|
+
* @param value - The value to validate
|
|
295
|
+
* @param min - Minimum allowed value
|
|
296
|
+
* @param max - Maximum allowed value
|
|
297
|
+
* @param paramName - The parameter name for error reporting
|
|
298
|
+
* @param mustBeInteger - Whether the value must be an integer
|
|
299
|
+
* @throws {TypeError} When value is not a number
|
|
300
|
+
* @throws {RangeError} When value is outside valid range
|
|
301
|
+
*/
|
|
302
|
+
static validateRange(value: number, min: number, max: number, paramName?: string, mustBeInteger?: boolean): void;
|
|
303
|
+
/**
|
|
304
|
+
* Validates MAC address format.
|
|
305
|
+
* @param address - The MAC address to validate
|
|
306
|
+
* @param paramName - The parameter name for error reporting
|
|
307
|
+
* @throws {TypeError} When address is not a string
|
|
308
|
+
* @throws {Error} When address format is invalid
|
|
309
|
+
*/
|
|
310
|
+
static validateMacAddress(address: any, paramName?: string): asserts address is string;
|
|
311
|
+
/**
|
|
312
|
+
* Validates that a value is one of the allowed enum values.
|
|
313
|
+
* @param value - The value to validate
|
|
314
|
+
* @param allowedValues - Array of allowed values
|
|
315
|
+
* @param paramName - The parameter name for error reporting
|
|
316
|
+
* @throws {Error} When value is not in allowed values
|
|
317
|
+
*/
|
|
318
|
+
static validateEnum<T>(value: any, allowedValues: readonly T[], paramName?: string): asserts value is T;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Enhanced error handling utilities.
|
|
322
|
+
*/
|
|
323
|
+
export declare class ErrorUtils {
|
|
324
|
+
/**
|
|
325
|
+
* Creates a timeout error with context.
|
|
326
|
+
* @param operation - The operation that timed out
|
|
327
|
+
* @param timeoutMs - The timeout duration in milliseconds
|
|
328
|
+
* @returns A descriptive timeout error
|
|
329
|
+
*/
|
|
330
|
+
static createTimeoutError(operation: string, timeoutMs: number): Error;
|
|
331
|
+
/**
|
|
332
|
+
* Creates a connection error with context.
|
|
333
|
+
* @param deviceId - The device ID that failed to connect
|
|
334
|
+
* @param cause - The underlying cause of the connection failure
|
|
335
|
+
* @returns A descriptive connection error
|
|
336
|
+
*/
|
|
337
|
+
static createConnectionError(deviceId: string, cause?: Error): Error;
|
|
338
|
+
/**
|
|
339
|
+
* Creates a command error with context.
|
|
340
|
+
* @param command - The command that failed
|
|
341
|
+
* @param deviceId - The device ID
|
|
342
|
+
* @param cause - The underlying cause
|
|
343
|
+
* @returns A descriptive command error
|
|
344
|
+
*/
|
|
345
|
+
static createCommandError(command: string, deviceId: string, cause?: Error): Error;
|
|
346
|
+
/**
|
|
347
|
+
* Wraps an async operation with timeout and enhanced error handling.
|
|
348
|
+
* @param operation - The async operation to wrap
|
|
349
|
+
* @param timeoutMs - Timeout in milliseconds
|
|
350
|
+
* @param operationName - Name of the operation for error messages
|
|
351
|
+
* @returns Promise that resolves with the operation result or rejects with timeout
|
|
352
|
+
*/
|
|
353
|
+
static withTimeout<T>(operation: Promise<T>, timeoutMs: number, operationName: string): Promise<T>;
|
|
354
|
+
}
|
|
236
355
|
/**
|
|
237
356
|
* Represents a Switchbot Device.
|
|
238
357
|
*/
|
|
@@ -255,7 +374,7 @@ export declare class SwitchbotDevice extends EventEmitter {
|
|
|
255
374
|
* @param peripheral The peripheral object from noble.
|
|
256
375
|
* @param noble The Noble object.
|
|
257
376
|
*/
|
|
258
|
-
constructor(peripheral: NobleTypes['peripheral'], noble:
|
|
377
|
+
constructor(peripheral: NobleTypes['peripheral'], noble: Noble);
|
|
259
378
|
/**
|
|
260
379
|
* Logs a message with the specified log level.
|
|
261
380
|
* @param level The severity level of the log (e.g., 'info', 'warn', 'error').
|
|
@@ -341,13 +460,13 @@ export declare class SwitchbotDevice extends EventEmitter {
|
|
|
341
460
|
*/
|
|
342
461
|
private waitForCommandResponse;
|
|
343
462
|
/**
|
|
344
|
-
* Reads data from a characteristic with
|
|
463
|
+
* Reads data from a characteristic with enhanced timeout and error handling.
|
|
345
464
|
* @param char The characteristic to read from.
|
|
346
465
|
* @returns A Promise that resolves with the data buffer.
|
|
347
466
|
*/
|
|
348
467
|
private readCharacteristic;
|
|
349
468
|
/**
|
|
350
|
-
* Writes data to a characteristic with
|
|
469
|
+
* Writes data to a characteristic with enhanced timeout and error handling.
|
|
351
470
|
* @param char The characteristic to write to.
|
|
352
471
|
* @param buf The data buffer.
|
|
353
472
|
* @returns A Promise that resolves when the write is complete.
|
|
@@ -374,6 +493,7 @@ export declare class Advertising {
|
|
|
374
493
|
* Validates if the buffer is a valid Buffer object with a minimum length.
|
|
375
494
|
*
|
|
376
495
|
* @param {any} buffer - The buffer to validate.
|
|
496
|
+
* @param {number} minLength - The minimum required length.
|
|
377
497
|
* @returns {boolean} - True if the buffer is valid, false otherwise.
|
|
378
498
|
*/
|
|
379
499
|
private static validateBuffer;
|
|
@@ -722,6 +842,20 @@ export declare class WoHub2 extends SwitchbotDevice {
|
|
|
722
842
|
static parseServiceData(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<hub2ServiceData | null>;
|
|
723
843
|
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
|
|
724
844
|
}
|
|
845
|
+
/**
|
|
846
|
+
* Class representing a WoHub3 device.
|
|
847
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md
|
|
848
|
+
*/
|
|
849
|
+
export declare class WoHub3 extends SwitchbotDevice {
|
|
850
|
+
/**
|
|
851
|
+
* Parses the service data for WoHub3.
|
|
852
|
+
* @param {Buffer} manufacturerData - The manufacturer data buffer.
|
|
853
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
854
|
+
* @returns {Promise<hub3ServiceData | null>} - Parsed service data or null if invalid.
|
|
855
|
+
*/
|
|
856
|
+
static parseServiceData(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<hub3ServiceData | null>;
|
|
857
|
+
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
|
|
858
|
+
}
|
|
725
859
|
/**
|
|
726
860
|
* Class representing a WoHumi device.
|
|
727
861
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/tree/latest/devicetypes
|
|
@@ -1314,5 +1448,105 @@ export declare class WoStrip extends SwitchbotDevice {
|
|
|
1314
1448
|
*/
|
|
1315
1449
|
operateStripLight(bytes: number[]): Promise<boolean>;
|
|
1316
1450
|
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Class representing a SwitchBot Air Purifier device.
|
|
1453
|
+
* @extends SwitchbotDevice
|
|
1454
|
+
*/
|
|
1455
|
+
export declare class WoAirPurifier extends SwitchbotDevice {
|
|
1456
|
+
/**
|
|
1457
|
+
* Parses service data for air purifier devices.
|
|
1458
|
+
* @param {Buffer | null} serviceData - The service data buffer.
|
|
1459
|
+
* @param {Buffer | null} manufacturerData - The manufacturer data buffer.
|
|
1460
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
1461
|
+
* @returns {airPurifierServiceData | null} - The parsed service data or null.
|
|
1462
|
+
*/
|
|
1463
|
+
static parseServiceData(serviceData: Buffer | null, manufacturerData: Buffer | null, emitLog?: (level: string, message: string) => void): airPurifierServiceData | null;
|
|
1464
|
+
/**
|
|
1465
|
+
* Sets the state of the air purifier.
|
|
1466
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
1467
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
1468
|
+
* @private
|
|
1469
|
+
*/
|
|
1470
|
+
setState(reqByteArray: number[]): Promise<boolean>;
|
|
1471
|
+
/**
|
|
1472
|
+
* Turns the air purifier on.
|
|
1473
|
+
* @returns {Promise<boolean>} - Resolves with true if the air purifier is turned on.
|
|
1474
|
+
*/
|
|
1475
|
+
turnOn(): Promise<boolean>;
|
|
1476
|
+
/**
|
|
1477
|
+
* Turns the air purifier off.
|
|
1478
|
+
* @returns {Promise<boolean>} - Resolves with true if the air purifier is turned off.
|
|
1479
|
+
*/
|
|
1480
|
+
turnOff(): Promise<boolean>;
|
|
1481
|
+
/**
|
|
1482
|
+
* Sets the speed of the air purifier.
|
|
1483
|
+
* @param {number} speed - The speed value (0-100).
|
|
1484
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
1485
|
+
*/
|
|
1486
|
+
setSpeed(speed: number): Promise<boolean>;
|
|
1487
|
+
/**
|
|
1488
|
+
* Sets the mode of the air purifier.
|
|
1489
|
+
* @param {number} mode - The mode value (1-4).
|
|
1490
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
1491
|
+
*/
|
|
1492
|
+
setMode(mode: number): Promise<boolean>;
|
|
1493
|
+
/**
|
|
1494
|
+
* Operates the air purifier with the given byte array.
|
|
1495
|
+
* @public
|
|
1496
|
+
* @param {number[]} bytes - The byte array to send.
|
|
1497
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
1498
|
+
*/
|
|
1499
|
+
operateAirPurifier(bytes: number[]): Promise<boolean>;
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Class representing a SwitchBot Air Purifier Table device.
|
|
1503
|
+
* @extends SwitchbotDevice
|
|
1504
|
+
*/
|
|
1505
|
+
export declare class WoAirPurifierTable extends SwitchbotDevice {
|
|
1506
|
+
/**
|
|
1507
|
+
* Parses service data for air purifier table devices.
|
|
1508
|
+
* @param {Buffer | null} serviceData - The service data buffer.
|
|
1509
|
+
* @param {Buffer | null} manufacturerData - The manufacturer data buffer.
|
|
1510
|
+
* @param {Function} emitLog - The function to emit log messages.
|
|
1511
|
+
* @returns {airPurifierTableServiceData | null} - The parsed service data or null.
|
|
1512
|
+
*/
|
|
1513
|
+
static parseServiceData(serviceData: Buffer | null, manufacturerData: Buffer | null, emitLog?: (level: string, message: string) => void): airPurifierTableServiceData | null;
|
|
1514
|
+
/**
|
|
1515
|
+
* Sets the state of the air purifier table.
|
|
1516
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
1517
|
+
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
|
|
1518
|
+
* @private
|
|
1519
|
+
*/
|
|
1520
|
+
setState(reqByteArray: number[]): Promise<boolean>;
|
|
1521
|
+
/**
|
|
1522
|
+
* Turns the air purifier table on.
|
|
1523
|
+
* @returns {Promise<boolean>} - Resolves with true if the air purifier table is turned on.
|
|
1524
|
+
*/
|
|
1525
|
+
turnOn(): Promise<boolean>;
|
|
1526
|
+
/**
|
|
1527
|
+
* Turns the air purifier table off.
|
|
1528
|
+
* @returns {Promise<boolean>} - Resolves with true if the air purifier table is turned off.
|
|
1529
|
+
*/
|
|
1530
|
+
turnOff(): Promise<boolean>;
|
|
1531
|
+
/**
|
|
1532
|
+
* Sets the speed of the air purifier table.
|
|
1533
|
+
* @param {number} speed - The speed value (0-100).
|
|
1534
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
1535
|
+
*/
|
|
1536
|
+
setSpeed(speed: number): Promise<boolean>;
|
|
1537
|
+
/**
|
|
1538
|
+
* Sets the mode of the air purifier table.
|
|
1539
|
+
* @param {number} mode - The mode value (1-4).
|
|
1540
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
1541
|
+
*/
|
|
1542
|
+
setMode(mode: number): Promise<boolean>;
|
|
1543
|
+
/**
|
|
1544
|
+
* Operates the air purifier table with the given byte array.
|
|
1545
|
+
* @public
|
|
1546
|
+
* @param {number[]} bytes - The byte array to send.
|
|
1547
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
1548
|
+
*/
|
|
1549
|
+
operateAirPurifierTable(bytes: number[]): Promise<boolean>;
|
|
1550
|
+
}
|
|
1317
1551
|
export {};
|
|
1318
1552
|
//# sourceMappingURL=device.d.ts.map
|