@switchbot/homebridge-switchbot 5.2.1-beta.0 → 5.2.1-beta.1
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 +72 -169
- package/.github/workflows/ci.yml +4 -1
- package/CLAUDE.md +13 -0
- package/docs/variables/default.html +1 -1
- package/package.json +1 -1
- package/src/device-types.js.map +0 -1
- package/src/deviceCommandMapper.js +0 -319
- package/src/deviceCommandMapper.js.map +0 -1
- package/src/errors.js +0 -32
- package/src/errors.js.map +0 -1
- package/src/settings.js +0 -8
- package/src/settings.js.map +0 -1
- package/src/switchbotClient.js +0 -247
- package/src/switchbotClient.js.map +0 -1
|
@@ -150,192 +150,95 @@ node -p "const v=require('./package.json').version.split('.'); v[2]=parseInt(v[2
|
|
|
150
150
|
3. Proceed with patch increment as fallback
|
|
151
151
|
4. Create or target the appropriate beta branch based on version increment
|
|
152
152
|
|
|
153
|
+
## Following node-switchbot Changes
|
|
154
|
+
|
|
155
|
+
node-switchbot tracks [pySwitchbot](https://github.com/sblibs/pySwitchbot). After node-switchbot
|
|
156
|
+
ships a change, this repo usually needs a follow-up PR so the plugin can use it:
|
|
157
|
+
|
|
158
|
+
1. Read the node-switchbot PR/release and list what consumers see: new device types, renamed or
|
|
159
|
+
split model identities (`modelName`, OpenAPI `deviceType`), new status fields, new commands.
|
|
160
|
+
2. Update `src/device-types.ts` (`DEVICE_TYPES`, `DEVICE_TYPE_NORMALIZATION_MAP`, including
|
|
161
|
+
lowercase product codes such as `woplugjp`), `DEVICE_CLASS_MAP` in `src/deviceFactory.ts`, and
|
|
162
|
+
accessory behaviour in `src/devices/genericDevice.ts`.
|
|
163
|
+
3. Make sure no existing saved `configDeviceType` stops resolving (normalization map or
|
|
164
|
+
`src/homebridge-ui/utils/device-migration.ts`).
|
|
165
|
+
4. Bump `node-switchbot` in `package.json` only to a version already published on npm.
|
|
166
|
+
5. Add `createDevice` tests under `test/device/` asserting each affected type's accessory class.
|
|
167
|
+
6. Run build, test and lint; commit the regenerated `config.schema.json` if `DEVICE_TYPES` changed.
|
|
168
|
+
|
|
153
169
|
## Working Effectively
|
|
154
170
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
1. **Install dependencies:**
|
|
159
|
-
```bash
|
|
160
|
-
npm install --legacy-peer-deps
|
|
161
|
-
```
|
|
162
|
-
- CRITICAL: Must use `--legacy-peer-deps` flag due to TypeDoc dependency conflicts
|
|
163
|
-
- Takes approximately 30-45 seconds
|
|
164
|
-
- This is a known workaround documented in the codebase
|
|
165
|
-
|
|
166
|
-
2. **Build the project:**
|
|
167
|
-
```bash
|
|
168
|
-
npm run build
|
|
169
|
-
```
|
|
170
|
-
- Takes approximately 7-10 seconds
|
|
171
|
-
- Compiles TypeScript and copies UI files
|
|
172
|
-
- Output goes to `dist/` directory
|
|
173
|
-
|
|
174
|
-
3. **Run tests:**
|
|
175
|
-
```bash
|
|
176
|
-
npm run test
|
|
177
|
-
```
|
|
178
|
-
- Takes approximately 2-3 seconds
|
|
179
|
-
- Currently minimal test suite (1 test file)
|
|
180
|
-
- Use `npm run test:watch` for continuous testing during development
|
|
181
|
-
|
|
182
|
-
4. **Generate documentation:**
|
|
183
|
-
```bash
|
|
184
|
-
npm run docs
|
|
185
|
-
```
|
|
186
|
-
- Takes approximately 5-10 seconds
|
|
187
|
-
- Generates TypeDoc documentation in `docs/` directory
|
|
188
|
-
|
|
189
|
-
### Full Build and Validation Workflow
|
|
190
|
-
Complete validation workflow (approximately 30-45 seconds total):
|
|
191
|
-
```bash
|
|
192
|
-
npm install --legacy-peer-deps && npm run build && npm run test && npm run docs && npm run docs:lint && npm run docs:theme
|
|
193
|
-
```
|
|
194
|
-
- NEVER CANCEL: Set timeout to 90+ seconds for this complete workflow
|
|
195
|
-
- This validates TypeScript compilation, plugin loading, and documentation generation
|
|
196
|
-
|
|
197
|
-
### Development Commands
|
|
198
|
-
|
|
199
|
-
- **Watch mode for development:**
|
|
200
|
-
```bash
|
|
201
|
-
npm run watch
|
|
202
|
-
```
|
|
203
|
-
- Builds, links plugin locally, and starts nodemon for file watching
|
|
204
|
-
- Requires local Homebridge installation
|
|
205
|
-
|
|
206
|
-
- **Clean build artifacts:**
|
|
207
|
-
```bash
|
|
208
|
-
npm run clean
|
|
209
|
-
```
|
|
210
|
-
- Removes `dist/` directory
|
|
211
|
-
|
|
212
|
-
- **Check for outdated dependencies:**
|
|
213
|
-
```bash
|
|
214
|
-
npm run check
|
|
215
|
-
```
|
|
216
|
-
- WARNING: This will fail due to dependency conflicts - use with `--legacy-peer-deps`
|
|
217
|
-
|
|
218
|
-
### Known Issues and Workarounds
|
|
219
|
-
|
|
220
|
-
- **Linting fails:** `npm run lint` and `npm run lint:fix` currently fail due to ESLint configuration conflicts with import/extensions rule. Document any code style issues manually.
|
|
221
|
-
|
|
222
|
-
- **Dependency conflicts:** Always use `--legacy-peer-deps` flag for npm install due to TypeDoc theme dependency version mismatches.
|
|
223
|
-
|
|
224
|
-
- **Coverage and docs artifacts:** Add `coverage/` and `docs/` to `.gitignore` to prevent committing build artifacts.
|
|
225
|
-
|
|
226
|
-
## Validation Scenarios
|
|
227
|
-
|
|
228
|
-
### Manual Plugin Validation
|
|
229
|
-
After making changes, ALWAYS run these validation steps:
|
|
230
|
-
|
|
231
|
-
1. **Verify plugin builds and loads:**
|
|
232
|
-
```bash
|
|
233
|
-
npm run build && node -e "
|
|
234
|
-
try {
|
|
235
|
-
const plugin = require('./dist/index.js');
|
|
236
|
-
console.log('Plugin loads successfully');
|
|
237
|
-
console.log('Plugin type:', typeof plugin.default);
|
|
238
|
-
} catch (e) {
|
|
239
|
-
console.error('Plugin load failed:', e.message);
|
|
240
|
-
}"
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
2. **Test plugin registration:**
|
|
244
|
-
- Plugin exports a default function that registers with Homebridge
|
|
245
|
-
- Uses `PLUGIN_NAME = '@switchbot/homebridge-switchbot'` and `PLATFORM_NAME = 'SwitchBot'`
|
|
246
|
-
- Main platform class is `SwitchBotPlatform`
|
|
247
|
-
|
|
248
|
-
3. **Validate TypeScript compilation:**
|
|
249
|
-
- Must have no TypeScript errors
|
|
250
|
-
- Check `dist/` directory contains all expected `.js`, `.d.ts`, and `.map` files
|
|
251
|
-
|
|
252
|
-
4. **Test documentation generation:**
|
|
253
|
-
```bash
|
|
254
|
-
npm run docs:lint
|
|
255
|
-
```
|
|
256
|
-
- Must pass without warnings when using `--treatWarningsAsErrors`
|
|
257
|
-
|
|
258
|
-
### Code Coverage Validation
|
|
259
|
-
Run comprehensive test coverage analysis:
|
|
171
|
+
Node `^22 || ^24`. Run these in order; each must pass before you commit:
|
|
172
|
+
|
|
260
173
|
```bash
|
|
261
|
-
npm
|
|
174
|
+
npm ci # CI uses: npm ci --legacy-peer-deps
|
|
175
|
+
npm run build # syncs DEVICE_TYPES into config.schema.json, cleans dist/, tsc, copies + builds the plugin UI
|
|
176
|
+
npm run test # vitest run
|
|
177
|
+
npm run lint # eslint (src, test, UI html/js) then tsc --noEmit
|
|
262
178
|
```
|
|
263
|
-
|
|
264
|
-
-
|
|
179
|
+
|
|
180
|
+
- `npm run lint:fix` fixes most style issues.
|
|
181
|
+
- `npm run build` needs `rsync` (used by `plugin-ui`).
|
|
182
|
+
- `npm run docs` / `npm run docs:lint` generate and check TypeDoc output; `prepublishOnly` runs them.
|
|
183
|
+
- `npm run watch` builds, links the plugin and runs nodemon against a local Homebridge;
|
|
184
|
+
`npm run watch:ui` also starts a dev Homebridge with Config UI X.
|
|
185
|
+
|
|
186
|
+
### Known pitfalls
|
|
187
|
+
|
|
188
|
+
- **Never commit compiled output under `src/`.** `.gitignore` excludes `src/**/*.js` and
|
|
189
|
+
`src/**/*.js.map`. Vitest resolves `./foo.js` imports to a real `src/foo.js` before `src/foo.ts`,
|
|
190
|
+
so a stale compiled copy silently replaces the source in tests.
|
|
191
|
+
- **`config.schema.json` is generated** from `DEVICE_TYPES` in `src/device-types.ts` during
|
|
192
|
+
`npm run build`. When `DEVICE_TYPES` changes, commit the regenerated schema in the same change.
|
|
193
|
+
- **`DEVICE_CLASS_MAP` keys in `src/deviceFactory.ts` are lowercase.** Unmapped types fall back to
|
|
194
|
+
`GenericDevice`, so add a test for every new type.
|
|
265
195
|
|
|
266
196
|
## Codebase Navigation
|
|
267
197
|
|
|
268
198
|
### Project Structure
|
|
269
199
|
```
|
|
270
|
-
├── src/
|
|
271
|
-
│ ├──
|
|
272
|
-
│
|
|
273
|
-
│
|
|
274
|
-
│
|
|
275
|
-
│
|
|
276
|
-
│ ├──
|
|
277
|
-
│
|
|
278
|
-
│
|
|
279
|
-
│ │
|
|
280
|
-
│
|
|
281
|
-
│
|
|
282
|
-
│
|
|
283
|
-
│ ├──
|
|
284
|
-
│
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
├── config.schema.json
|
|
288
|
-
|
|
289
|
-
├── docs/ # Generated TypeDoc documentation
|
|
290
|
-
└── coverage/ # Test coverage reports
|
|
200
|
+
├── src/
|
|
201
|
+
│ ├── index.ts # Plugin entry point (registers one platform that proxies HAP or Matter)
|
|
202
|
+
│ ├── SwitchBotHAPPlatform.ts # HomeKit (HAP) platform
|
|
203
|
+
│ ├── SwitchBotMatterPlatform.ts # Matter platform
|
|
204
|
+
│ ├── switchbotClient.ts # Wrapper around node-switchbot (BLE + OpenAPI)
|
|
205
|
+
│ ├── deviceFactory.ts # Device type -> accessory class (DEVICE_CLASS_MAP, createDevice)
|
|
206
|
+
│ ├── device-types.ts # DEVICE_TYPES (valid types) + DEVICE_TYPE_NORMALIZATION_MAP (aliases)
|
|
207
|
+
│ ├── deviceCommandMapper.ts # Per-type command handlers
|
|
208
|
+
│ ├── devices/
|
|
209
|
+
│ │ ├── deviceBase.ts # Base accessory class
|
|
210
|
+
│ │ └── genericDevice.ts # GenericDevice and every concrete accessory class
|
|
211
|
+
│ ├── homebridge-ui/ # Config UI X custom UI (server, endpoints, utils, public/)
|
|
212
|
+
│ ├── settings.ts # Config interfaces and constants
|
|
213
|
+
│ ├── errors.ts
|
|
214
|
+
│ └── utils.ts
|
|
215
|
+
├── test/ # Vitest specs (client, device, platform, homebridge-ui, utils, e2e)
|
|
216
|
+
├── scripts/ # sync-device-types, build-ui, free-dev-ports
|
|
217
|
+
├── config.schema.json # Homebridge config schema (configDeviceType enum is generated)
|
|
218
|
+
└── dist/ # Build output (not committed)
|
|
291
219
|
```
|
|
292
220
|
|
|
293
|
-
### Key Development Areas
|
|
294
|
-
|
|
295
|
-
- **Adding new devices:** Extend `src/device/device.ts` base class, implement in new file under `src/device/`
|
|
296
|
-
- **Adding IR devices:** Extend `src/irdevice/irdevice.ts` base class, implement in new file under `src/irdevice/`
|
|
297
|
-
- **Configuration changes:** Update `src/settings.ts` and `config.schema.json`
|
|
298
|
-
- **Platform modifications:** Edit `src/platform.ts` (main class with 2800+ lines)
|
|
299
|
-
- **Utility functions:** Modify `src/utils.ts` for shared functionality
|
|
300
|
-
|
|
301
|
-
### Device Connection Types
|
|
302
|
-
This plugin supports two connection methods to SwitchBot devices:
|
|
303
|
-
1. **OpenAPI Connection:** Requires SwitchBot Cloud API token/secret, works through SwitchBot Hub
|
|
304
|
-
2. **BLE (Bluetooth Low Energy):** Direct device connection, requires device MAC addresses
|
|
305
|
-
|
|
306
221
|
### Common Development Tasks
|
|
307
222
|
|
|
308
|
-
- **
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
- **
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
-
|
|
315
|
-
-
|
|
316
|
-
- Device MAC address validation is handled in utils.ts (`formatDeviceIdAsMac`)
|
|
317
|
-
- BLE connection handling is in the base device classes
|
|
318
|
-
|
|
319
|
-
## Build Time Expectations
|
|
223
|
+
- **New device type or identity from node-switchbot:** add it to `DEVICE_TYPES` and/or
|
|
224
|
+
`DEVICE_TYPE_NORMALIZATION_MAP` in `src/device-types.ts`, map it in `DEVICE_CLASS_MAP` in
|
|
225
|
+
`src/deviceFactory.ts`, then add a `createDevice` test under `test/device/`.
|
|
226
|
+
- **New accessory behaviour:** add or extend a class in `src/devices/genericDevice.ts`.
|
|
227
|
+
- **Saved configs that would stop resolving:** handle them in the normalization map or
|
|
228
|
+
`src/homebridge-ui/utils/device-migration.ts`.
|
|
229
|
+
- **Config UI changes:** edit `src/homebridge-ui/`, then `npm run build`.
|
|
230
|
+
- **node-switchbot upgrades:** bump the dependency only to a version already published on npm.
|
|
320
231
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
- **npm run docs:** 5-10 seconds
|
|
325
|
-
- **Complete validation workflow:** 30-45 seconds total
|
|
326
|
-
- **NEVER CANCEL:** Always wait for builds to complete, set timeouts to 90+ seconds for safety
|
|
232
|
+
### Device Connection Types
|
|
233
|
+
1. **OpenAPI:** SwitchBot Cloud token/secret; works through a SwitchBot Hub.
|
|
234
|
+
2. **BLE:** direct Bluetooth connection via node-switchbot (Linux/macOS).
|
|
327
235
|
|
|
328
236
|
## CI/CD Integration
|
|
329
237
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
Always run the complete validation workflow locally before committing:
|
|
336
|
-
```bash
|
|
337
|
-
npm run build && npm run test && npm run docs:lint
|
|
338
|
-
```
|
|
238
|
+
- `.github/workflows/ci.yml`: build, test and lint on Node 22 and 24 for pushes to `latest`/`beta-*`
|
|
239
|
+
and PRs to `latest`/`beta-*`.
|
|
240
|
+
- `.github/workflows/release.yml`: pushes to `beta-*` publish a beta to npm; pushes to `latest`
|
|
241
|
+
publish a stable release.
|
|
339
242
|
|
|
340
243
|
## Complete Workflow Examples
|
|
341
244
|
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -4,7 +4,7 @@ on:
|
|
|
4
4
|
push:
|
|
5
5
|
branches: ["main", "latest", "beta-*"]
|
|
6
6
|
pull_request:
|
|
7
|
-
branches: ["main", "latest"]
|
|
7
|
+
branches: ["main", "latest", "beta-*"]
|
|
8
8
|
|
|
9
9
|
permissions:
|
|
10
10
|
contents: read
|
|
@@ -33,3 +33,6 @@ jobs:
|
|
|
33
33
|
|
|
34
34
|
- name: Run tests
|
|
35
35
|
run: npm run test
|
|
36
|
+
|
|
37
|
+
- name: Lint
|
|
38
|
+
run: npm run lint
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# homebridge-switchbot
|
|
2
|
+
|
|
3
|
+
The project guide is shared with Copilot and imported here. It covers reference priority, branch
|
|
4
|
+
targeting, following node-switchbot changes, commands, structure and pitfalls:
|
|
5
|
+
|
|
6
|
+
@.github/copilot-instructions.md
|
|
7
|
+
|
|
8
|
+
## Claude-specific notes
|
|
9
|
+
|
|
10
|
+
- Conventional Commits (`feat:`, `fix:`, `docs:`, `test:`, `chore:`).
|
|
11
|
+
- If the right target branch is unclear, ask before opening the PR.
|
|
12
|
+
- PR description: what changed, why (link the node-switchbot PR/release), and any config migration
|
|
13
|
+
users need.
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
</div></li></ul></div>
|
|
29
29
|
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></div><aside class="tsd-sources">
|
|
30
30
|
<ul>
|
|
31
|
-
<li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/
|
|
31
|
+
<li>Defined in <a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/f710df77d4eb0c045f97c4955a23fca260364993/src/index.ts#L22">index.ts:22</a></li></ul></aside></div>
|
|
32
32
|
<div class="col-sidebar">
|
|
33
33
|
<div class="page-menu">
|
|
34
34
|
<div class="tsd-navigation settings">
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@switchbot/homebridge-switchbot",
|
|
3
3
|
"displayName": "SwitchBot",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "5.2.1-beta.
|
|
5
|
+
"version": "5.2.1-beta.1",
|
|
6
6
|
"description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
|
|
7
7
|
"author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
|
|
8
8
|
"contributors": [
|
package/src/device-types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"device-types.js","sourceRoot":"","sources":["device-types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,kBAAkB,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,CAAC;IACzE,gBAAgB,EAAE;QAChB,QAAQ;QACR,cAAc;QACd,eAAe;QACf,mBAAmB;QACnB,iBAAiB;QACjB,WAAW;QACX,YAAY;QACZ,gBAAgB;QAChB,kBAAkB;QAClB,gBAAgB;KACjB;IACD,SAAS,EAAE,CAAC,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,gBAAgB,CAAC;IACnF,UAAU,EAAE;QACV,oBAAoB;QACpB,eAAe;QACf,mBAAmB;QACnB,YAAY;QACZ,YAAY;QACZ,uBAAuB;QACvB,4BAA4B;QAC5B,oBAAoB;QACpB,qBAAqB;QACrB,aAAa;QACb,eAAe;KAChB;IACD,iBAAiB,EAAE;QACjB,oBAAoB;QACpB,0BAA0B;QAC1B,kBAAkB;QAClB,wBAAwB;QACxB,wBAAwB;QACxB,gBAAgB;QAChB,YAAY;QACZ,aAAa;QACb,OAAO;QACP,WAAW;QACX,YAAY;QACZ,UAAU;QACV,WAAW;QACX,eAAe;QACf,iBAAiB;QACjB,2BAA2B;QAC3B,yBAAyB;QACzB,YAAY;KACb;IACD,kBAAkB,EAAE;QAClB,oBAAoB;QACpB,MAAM;QACN,gBAAgB;QAChB,gBAAgB;QAChB,gBAAgB;QAChB,gBAAgB;QAChB,kBAAkB;QAClB,kBAAkB;KACnB;IACD,eAAe,EAAE;QACf,MAAM;QACN,UAAU;QACV,qCAAqC;QACrC,2BAA2B;QAC3B,mCAAmC;QACnC,yB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CAAA;IACxC,IAAI,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,0BAA0B;IAC1B,MAAM,UAAU,GAAG,6BAA6B,CAAC,SAAS,CAAC,CAAA;IAC3D,IAAI,UAAU,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,OAAO,UAAU,CAAA;IACnB,CAAC;IAED,yBAAyB;IACzB,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAqC;IACrE,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QAClD,OAAO,KAAK,CAAA;IACd,CAAC;IACD,MAAM,UAAU,GAAG,mBAAmB,EAAE,CAAA;IACxC,OAAO,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAA;AAC1C,CAAC"}
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
// deviceCommandMapper.ts
|
|
2
|
-
// Maps HAP/Matter commands to node-switchbot device methods for all supported device types
|
|
3
|
-
export const deviceTypeCommandMap = {
|
|
4
|
-
// SwitchBot AI Hub (read-only/generic)
|
|
5
|
-
'ai hub': {},
|
|
6
|
-
// SwitchBot Cameras (read-only/generic)
|
|
7
|
-
'indoor cam': {},
|
|
8
|
-
'pan/tilt cam': {},
|
|
9
|
-
'pan/tilt cam 2k': {},
|
|
10
|
-
'pan/tilt cam plus 2k': {},
|
|
11
|
-
'pan/tilt cam plus 3k': {},
|
|
12
|
-
// SwitchBot Air Purifiers (read-only/generic)
|
|
13
|
-
'air purifier pm2.5': {},
|
|
14
|
-
'air purifier table pm2.5': {},
|
|
15
|
-
'air purifier voc': {},
|
|
16
|
-
'air purifier table voc': {},
|
|
17
|
-
// SwitchBot Home Climate Panel (read-only/generic)
|
|
18
|
-
'home climate panel': {},
|
|
19
|
-
// SwitchBot WoIOSensor (read-only/generic)
|
|
20
|
-
'woiosensor': {},
|
|
21
|
-
// SwitchBot Candle Warmer Lamp
|
|
22
|
-
'candle warmer lamp': {
|
|
23
|
-
turnOn: async (device) => device.turnOn(),
|
|
24
|
-
turnOff: async (device) => device.turnOff(),
|
|
25
|
-
},
|
|
26
|
-
// SwitchBot Hubs (read-only/generic)
|
|
27
|
-
'hub': {},
|
|
28
|
-
'hub 2': {},
|
|
29
|
-
'hub 3': {},
|
|
30
|
-
'hub mini': {},
|
|
31
|
-
'hub plus': {},
|
|
32
|
-
// SwitchBot Robot Vacuum Cleaner K20 Plus Pro
|
|
33
|
-
'robot vacuum cleaner k20 plus pro': {
|
|
34
|
-
start: async (device) => device.start(),
|
|
35
|
-
stop: async (device) => device.stop(),
|
|
36
|
-
pause: async (device) => device.pause(),
|
|
37
|
-
dock: async (device) => device.dock(),
|
|
38
|
-
resume: async (device) => device.resume(),
|
|
39
|
-
locate: async (device) => device.locate(),
|
|
40
|
-
},
|
|
41
|
-
// SwitchBot Robot Vacuum Cleaner S1
|
|
42
|
-
'robot vacuum cleaner s1': {
|
|
43
|
-
start: async (device) => device.start(),
|
|
44
|
-
stop: async (device) => device.stop(),
|
|
45
|
-
pause: async (device) => device.pause(),
|
|
46
|
-
dock: async (device) => device.dock(),
|
|
47
|
-
resume: async (device) => device.resume(),
|
|
48
|
-
locate: async (device) => device.locate(),
|
|
49
|
-
},
|
|
50
|
-
// SwitchBot Robot Vacuum Cleaner S1 Plus
|
|
51
|
-
'robot vacuum cleaner s1 plus': {
|
|
52
|
-
start: async (device) => device.start(),
|
|
53
|
-
stop: async (device) => device.stop(),
|
|
54
|
-
pause: async (device) => device.pause(),
|
|
55
|
-
dock: async (device) => device.dock(),
|
|
56
|
-
resume: async (device) => device.resume(),
|
|
57
|
-
locate: async (device) => device.locate(),
|
|
58
|
-
},
|
|
59
|
-
// SwitchBot Robot Vacuum Cleaner S10
|
|
60
|
-
'robot vacuum cleaner s10': {
|
|
61
|
-
start: async (device) => device.start(),
|
|
62
|
-
stop: async (device) => device.stop(),
|
|
63
|
-
pause: async (device) => device.pause(),
|
|
64
|
-
dock: async (device) => device.dock(),
|
|
65
|
-
resume: async (device) => device.resume(),
|
|
66
|
-
locate: async (device) => device.locate(),
|
|
67
|
-
},
|
|
68
|
-
// SwitchBot Robot Vacuum Cleaner S20
|
|
69
|
-
'robot vacuum cleaner s20': {
|
|
70
|
-
start: async (device) => device.start(),
|
|
71
|
-
stop: async (device) => device.stop(),
|
|
72
|
-
pause: async (device) => device.pause(),
|
|
73
|
-
dock: async (device) => device.dock(),
|
|
74
|
-
resume: async (device) => device.resume(),
|
|
75
|
-
locate: async (device) => device.locate(),
|
|
76
|
-
},
|
|
77
|
-
// SwitchBot Relay Switch 2PM
|
|
78
|
-
'relay switch 2pm': {
|
|
79
|
-
turnOn: async (device) => device.turnOn(),
|
|
80
|
-
turnOff: async (device) => device.turnOff(),
|
|
81
|
-
},
|
|
82
|
-
// SwitchBot K10+
|
|
83
|
-
'k10+': {
|
|
84
|
-
start: async (device) => device.start(),
|
|
85
|
-
stop: async (device) => device.stop(),
|
|
86
|
-
pause: async (device) => device.pause(),
|
|
87
|
-
dock: async (device) => device.dock(),
|
|
88
|
-
resume: async (device) => device.resume(),
|
|
89
|
-
locate: async (device) => device.locate(),
|
|
90
|
-
},
|
|
91
|
-
// SwitchBot K10+ Pro
|
|
92
|
-
'k10+ pro': {
|
|
93
|
-
start: async (device) => device.start(),
|
|
94
|
-
stop: async (device) => device.stop(),
|
|
95
|
-
pause: async (device) => device.pause(),
|
|
96
|
-
dock: async (device) => device.dock(),
|
|
97
|
-
resume: async (device) => device.resume(),
|
|
98
|
-
locate: async (device) => device.locate(),
|
|
99
|
-
},
|
|
100
|
-
// SwitchBot Robot Vacuum Cleaner K10+ Pro Combo
|
|
101
|
-
'robot vacuum cleaner k10+ pro combo': {
|
|
102
|
-
start: async (device) => device.start(),
|
|
103
|
-
stop: async (device) => device.stop(),
|
|
104
|
-
pause: async (device) => device.pause(),
|
|
105
|
-
dock: async (device) => device.dock(),
|
|
106
|
-
resume: async (device) => device.resume(),
|
|
107
|
-
locate: async (device) => device.locate(),
|
|
108
|
-
},
|
|
109
|
-
// SwitchBot Robot Vacuum Cleaner K11+
|
|
110
|
-
'robot vacuum cleaner k11+': {
|
|
111
|
-
start: async (device) => device.start(),
|
|
112
|
-
stop: async (device) => device.stop(),
|
|
113
|
-
pause: async (device) => device.pause(),
|
|
114
|
-
dock: async (device) => device.dock(),
|
|
115
|
-
resume: async (device) => device.resume(),
|
|
116
|
-
locate: async (device) => device.locate(),
|
|
117
|
-
},
|
|
118
|
-
// SwitchBot MeterPro(CO2) (read-only)
|
|
119
|
-
'meterpro(co2)': {},
|
|
120
|
-
// SwitchBot Water Detector (read-only)
|
|
121
|
-
'water detector': {},
|
|
122
|
-
// SwitchBot Garage Door Opener
|
|
123
|
-
'garage door opener': {
|
|
124
|
-
open: async (device) => device.open(),
|
|
125
|
-
close: async (device) => device.close(),
|
|
126
|
-
stop: async (device) => device.stop(),
|
|
127
|
-
},
|
|
128
|
-
// SwitchBot Relay Switch 1
|
|
129
|
-
'relay switch 1': {
|
|
130
|
-
turnOn: async (device) => device.turnOn(),
|
|
131
|
-
turnOff: async (device) => device.turnOff(),
|
|
132
|
-
},
|
|
133
|
-
// SwitchBot Relay Switch 1PM
|
|
134
|
-
'relay switch 1pm': {
|
|
135
|
-
turnOn: async (device) => device.turnOn(),
|
|
136
|
-
turnOff: async (device) => device.turnOff(),
|
|
137
|
-
},
|
|
138
|
-
// SwitchBot Smart Radiator Thermostat (read-only or not directly controllable)
|
|
139
|
-
'smart radiator thermostat': {},
|
|
140
|
-
// SwitchBot Humidifier2
|
|
141
|
-
'humidifier2': {
|
|
142
|
-
turnOn: async (device) => device.turnOn(),
|
|
143
|
-
turnOff: async (device) => device.turnOff(),
|
|
144
|
-
setMode: async (device, body) => device.setMode(body?.parameter),
|
|
145
|
-
setHumidity: async (device, body) => device.setHumidity(body?.parameter),
|
|
146
|
-
},
|
|
147
|
-
// SwitchBot MeterPlus (read-only)
|
|
148
|
-
'meterplus': {},
|
|
149
|
-
// SwitchBot Meter Pro (read-only)
|
|
150
|
-
'meter pro': {},
|
|
151
|
-
// SwitchBot MeterPro (read-only)
|
|
152
|
-
'meterpro': {},
|
|
153
|
-
// SwitchBot RGBICWW Floor Lamp
|
|
154
|
-
'rgbicww floor lamp': {
|
|
155
|
-
turnOn: async (device) => device.turnOn(),
|
|
156
|
-
turnOff: async (device) => device.turnOff(),
|
|
157
|
-
setBrightness: async (device, body) => device.setBrightness(body?.parameter),
|
|
158
|
-
setColor: async (device, body) => device.setColor(body?.parameter),
|
|
159
|
-
},
|
|
160
|
-
// SwitchBot RGBICWW Strip Light
|
|
161
|
-
'rgbicww strip light': {
|
|
162
|
-
turnOn: async (device) => device.turnOn(),
|
|
163
|
-
turnOff: async (device) => device.turnOff(),
|
|
164
|
-
setBrightness: async (device, body) => device.setBrightness(body?.parameter),
|
|
165
|
-
setColor: async (device, body) => device.setColor(body?.parameter),
|
|
166
|
-
},
|
|
167
|
-
// SwitchBot Circulator Fan
|
|
168
|
-
'circulator fan': {
|
|
169
|
-
turnOn: async (device) => device.turnOn(),
|
|
170
|
-
turnOff: async (device) => device.turnOff(),
|
|
171
|
-
setSpeed: async (device, body) => device.setSpeed(body?.parameter),
|
|
172
|
-
swing: async (device) => device.swing(),
|
|
173
|
-
},
|
|
174
|
-
// SwitchBot Battery Circulator Fan
|
|
175
|
-
'battery circulator fan': {
|
|
176
|
-
turnOn: async (device) => device.turnOn(),
|
|
177
|
-
turnOff: async (device) => device.turnOff(),
|
|
178
|
-
setSpeed: async (device, body) => device.setSpeed(body?.parameter),
|
|
179
|
-
swing: async (device) => device.swing(),
|
|
180
|
-
},
|
|
181
|
-
// SwitchBot Standing Circulator Fan
|
|
182
|
-
'standing circulator fan': {
|
|
183
|
-
turnOn: async (device) => device.turnOn(),
|
|
184
|
-
turnOff: async (device) => device.turnOff(),
|
|
185
|
-
setSpeed: async (device, body) => device.setSpeed(body?.parameter),
|
|
186
|
-
swing: async (device) => device.swing(),
|
|
187
|
-
},
|
|
188
|
-
// SwitchBot Bot
|
|
189
|
-
'bot': {
|
|
190
|
-
turnOn: async (device) => device.turnOn(),
|
|
191
|
-
turnOff: async (device) => device.turnOff(),
|
|
192
|
-
press: async (device) => device.press(),
|
|
193
|
-
},
|
|
194
|
-
// SwitchBot Curtain
|
|
195
|
-
'curtain': {
|
|
196
|
-
open: async (device) => device.open(),
|
|
197
|
-
close: async (device) => device.close(),
|
|
198
|
-
pause: async (device) => device.pause(),
|
|
199
|
-
setPosition: async (device, body) => device.setPosition(body?.parameter),
|
|
200
|
-
},
|
|
201
|
-
// SwitchBot Blind Tilt
|
|
202
|
-
'blind tilt': {
|
|
203
|
-
open: async (device) => device.open(),
|
|
204
|
-
close: async (device) => device.close(),
|
|
205
|
-
pause: async (device) => device.pause(),
|
|
206
|
-
setPosition: async (device, body) => device.setPosition(body?.parameter),
|
|
207
|
-
},
|
|
208
|
-
// SwitchBot Roller Shade
|
|
209
|
-
'roller shade': {
|
|
210
|
-
open: async (device) => device.open(),
|
|
211
|
-
close: async (device) => device.close(),
|
|
212
|
-
pause: async (device) => device.pause(),
|
|
213
|
-
setPosition: async (device, body) => device.setPosition(body?.parameter),
|
|
214
|
-
},
|
|
215
|
-
// SwitchBot Plug
|
|
216
|
-
'plug': {
|
|
217
|
-
turnOn: async (device) => device.turnOn(),
|
|
218
|
-
turnOff: async (device) => device.turnOff(),
|
|
219
|
-
},
|
|
220
|
-
// SwitchBot Strip Light 3
|
|
221
|
-
'strip light 3': {
|
|
222
|
-
turnOn: async (device) => device.turnOn(),
|
|
223
|
-
turnOff: async (device) => device.turnOff(),
|
|
224
|
-
setBrightness: async (device, body) => device.setBrightness(body?.parameter),
|
|
225
|
-
setColor: async (device, body) => device.setColor(body?.parameter),
|
|
226
|
-
},
|
|
227
|
-
// SwitchBot Floor Lamp
|
|
228
|
-
'floor lamp': {
|
|
229
|
-
turnOn: async (device) => device.turnOn(),
|
|
230
|
-
turnOff: async (device) => device.turnOff(),
|
|
231
|
-
setBrightness: async (device, body) => device.setBrightness(body?.parameter),
|
|
232
|
-
setColor: async (device, body) => device.setColor(body?.parameter),
|
|
233
|
-
},
|
|
234
|
-
// SwitchBot RGBIC Neon Rope Light
|
|
235
|
-
'rgbic neon rope light': {
|
|
236
|
-
turnOn: async (device) => device.turnOn(),
|
|
237
|
-
turnOff: async (device) => device.turnOff(),
|
|
238
|
-
setBrightness: async (device, body) => device.setBrightness(body?.parameter),
|
|
239
|
-
setColor: async (device, body) => device.setColor(body?.parameter),
|
|
240
|
-
},
|
|
241
|
-
// SwitchBot RGBIC Neon Wire Rope Light
|
|
242
|
-
'rgbic neon wire rope light': {
|
|
243
|
-
turnOn: async (device) => device.turnOn(),
|
|
244
|
-
turnOff: async (device) => device.turnOff(),
|
|
245
|
-
setBrightness: async (device, body) => device.setBrightness(body?.parameter),
|
|
246
|
-
setColor: async (device, body) => device.setColor(body?.parameter),
|
|
247
|
-
},
|
|
248
|
-
// SwitchBot Plug Mini
|
|
249
|
-
'plug mini': {
|
|
250
|
-
turnOn: async (device) => device.turnOn(),
|
|
251
|
-
turnOff: async (device) => device.turnOff(),
|
|
252
|
-
},
|
|
253
|
-
// SwitchBot Color Bulb
|
|
254
|
-
'color bulb': {
|
|
255
|
-
turnOn: async (device) => device.turnOn(),
|
|
256
|
-
turnOff: async (device) => device.turnOff(),
|
|
257
|
-
setBrightness: async (device, body) => device.setBrightness(body?.parameter),
|
|
258
|
-
setColor: async (device, body) => device.setColor(body?.parameter),
|
|
259
|
-
},
|
|
260
|
-
// SwitchBot Light Strip
|
|
261
|
-
'light strip': {
|
|
262
|
-
turnOn: async (device) => device.turnOn(),
|
|
263
|
-
turnOff: async (device) => device.turnOff(),
|
|
264
|
-
setBrightness: async (device, body) => device.setBrightness(body?.parameter),
|
|
265
|
-
setColor: async (device, body) => device.setColor(body?.parameter),
|
|
266
|
-
},
|
|
267
|
-
// SwitchBot Fan
|
|
268
|
-
'fan': {
|
|
269
|
-
turnOn: async (device) => device.turnOn(),
|
|
270
|
-
turnOff: async (device) => device.turnOff(),
|
|
271
|
-
setSpeed: async (device, body) => device.setSpeed(body?.parameter),
|
|
272
|
-
swing: async (device) => device.swing(),
|
|
273
|
-
},
|
|
274
|
-
// SwitchBot Lock
|
|
275
|
-
'lock': {
|
|
276
|
-
lock: async (device) => device.lock(),
|
|
277
|
-
unlock: async (device) => device.unlock(),
|
|
278
|
-
},
|
|
279
|
-
// SwitchBot Curtain 3
|
|
280
|
-
'curtain3': {
|
|
281
|
-
open: async (device) => device.open(),
|
|
282
|
-
close: async (device) => device.close(),
|
|
283
|
-
pause: async (device) => device.pause(),
|
|
284
|
-
setPosition: async (device, body) => device.setPosition(body?.parameter),
|
|
285
|
-
},
|
|
286
|
-
// SwitchBot Meter
|
|
287
|
-
'meter': {}, // Read-only
|
|
288
|
-
// SwitchBot Motion Sensor
|
|
289
|
-
'motion sensor': {}, // Read-only
|
|
290
|
-
// SwitchBot Contact Sensor
|
|
291
|
-
'contact sensor': {}, // Read-only
|
|
292
|
-
// SwitchBot Humidifier
|
|
293
|
-
'humidifier': {
|
|
294
|
-
turnOn: async (device) => device.turnOn(),
|
|
295
|
-
turnOff: async (device) => device.turnOff(),
|
|
296
|
-
setMode: async (device, body) => device.setMode(body?.parameter),
|
|
297
|
-
setHumidity: async (device, body) => device.setHumidity(body?.parameter),
|
|
298
|
-
},
|
|
299
|
-
// SwitchBot Vacuum
|
|
300
|
-
'vacuum': {
|
|
301
|
-
start: async (device) => device.start(),
|
|
302
|
-
stop: async (device) => device.stop(),
|
|
303
|
-
pause: async (device) => device.pause(),
|
|
304
|
-
dock: async (device) => device.dock(),
|
|
305
|
-
resume: async (device) => device.resume(),
|
|
306
|
-
locate: async (device) => device.locate(),
|
|
307
|
-
},
|
|
308
|
-
// Add more device types and commands as needed
|
|
309
|
-
};
|
|
310
|
-
// Helper to get the handler for a device type and command
|
|
311
|
-
export function getDeviceCommandHandler(deviceType, command) {
|
|
312
|
-
const typeKey = deviceType.toLowerCase();
|
|
313
|
-
const typeMap = deviceTypeCommandMap[typeKey];
|
|
314
|
-
if (!typeMap) {
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
return typeMap[command];
|
|
318
|
-
}
|
|
319
|
-
//# sourceMappingURL=deviceCommandMapper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deviceCommandMapper.js","sourceRoot":"","sources":["deviceCommandMapper.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,2FAA2F;AAe3F,MAAM,CAAC,MAAM,oBAAoB,GAAyB;IACxD,uCAAuC;IACvC,QAAQ,EAAE,EAAE;IACZ,wCAAwC;IACxC,YAAY,EAAE,EAAE;IAChB,cAAc,EAAE,EAAE;IAClB,iBAAiB,EAAE,EAAE;IACrB,sBAAsB,EAAE,EAAE;IAC1B,sBAAsB,EAAE,EAAE;IAC1B,8CAA8C;IAC9C,oBAAoB,EAAE,EAAE;IACxB,0BAA0B,EAAE,EAAE;IAC9B,kBAAkB,EAAE,EAAE;IACtB,wBAAwB,EAAE,EAAE;IAC5B,mDAAmD;IACnD,oBAAoB,EAAE,EAAE;IACxB,2CAA2C;IAC3C,YAAY,EAAE,EAAE;IAChB,+BAA+B;IAC/B,oBAAoB,EAAE;QACpB,MAAM,EAAE,KAAK,EAAC,MAAM,EAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE;QACvC,OAAO,EAAE,KAAK,EAAC,MAAM,EAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE;KAC1C;IACD,qCAAqC;IACrC,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,UAAU,EAAE,EAAE;IACd,UAAU,EAAE,EAAE;IACd,8CAA8C;IAC9C,mCAAmC,EAAE;QACnC,KAAK,EAAE,KAAK,EAAC,M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AO,CAAC,OAAO,CAAC,CAAA;AACzB,CAAC"}
|
package/src/errors.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// Error classes for node-switchbot v4 compatibility
|
|
2
|
-
// Always use local fallback classes for compatibility; upstream error classes are not guaranteed to exist
|
|
3
|
-
const SwitchbotOperationError = class extends Error {
|
|
4
|
-
code;
|
|
5
|
-
cause;
|
|
6
|
-
constructor(message, code, cause) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = 'SwitchbotOperationError';
|
|
9
|
-
this.code = code;
|
|
10
|
-
this.cause = cause;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const SwitchbotAuthenticationError = class extends Error {
|
|
14
|
-
code;
|
|
15
|
-
cause;
|
|
16
|
-
constructor(message, code, cause) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = 'SwitchbotAuthenticationError';
|
|
19
|
-
this.code = code;
|
|
20
|
-
this.cause = cause;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const CharacteristicMissingError = class extends Error {
|
|
24
|
-
characteristic;
|
|
25
|
-
constructor(message, characteristic) {
|
|
26
|
-
super(message);
|
|
27
|
-
this.name = 'CharacteristicMissingError';
|
|
28
|
-
this.characteristic = characteristic;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
export { CharacteristicMissingError, SwitchbotAuthenticationError, SwitchbotOperationError };
|
|
32
|
-
//# sourceMappingURL=errors.js.map
|
package/src/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,0GAA0G;AAE1G,MAAM,uBAAuB,GAAG,KAAM,SAAQ,KAAK;IACjD,IAAI,CAAS;IACb,KAAK,CAAQ;IACb,YAAY,OAAe,EAAE,IAAa,EAAE,KAAa;QACvD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAA;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF,CAAA;AAED,MAAM,4BAA4B,GAAG,KAAM,SAAQ,KAAK;IACtD,IAAI,CAAS;IACb,KAAK,CAAQ;IACb,YAAY,OAAe,EAAE,IAAa,EAAE,KAAa;QACvD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAA;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;CACF,CAAA;AAED,MAAM,0BAA0B,GAAG,KAAM,SAAQ,KAAK;IACpD,cAAc,CAAQ;IACtB,YAAY,OAAe,EAAE,cAAsB;QACjD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;QACxC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACtC,CAAC;CACF,CAAA;AAED,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,CAAA"}
|
package/src/settings.js
DELETED
package/src/settings.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"settings.js","sourceRoot":"","sources":["settings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,iCAAiC,CAAA;AAC5D,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAA;AAYxC,MAAM,CAAC,MAAM,cAAc,GAAmC;IAC5D,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,IAAI;CAChB,CAAA"}
|
package/src/switchbotClient.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { getDeviceCommandHandler } from './deviceCommandMapper.js';
|
|
2
|
-
import { CharacteristicMissingError, SwitchbotAuthenticationError, SwitchbotOperationError } from './errors.js';
|
|
3
|
-
/**
|
|
4
|
-
* Thin wrapper around node-switchbot v4.0.0+
|
|
5
|
-
* Leverages upstream resilience features (retry, circuit breaker, connection intelligence)
|
|
6
|
-
* while maintaining plugin-specific features like write debouncing and OpenAPI fallback.
|
|
7
|
-
*/
|
|
8
|
-
export class SwitchBotClient {
|
|
9
|
-
cfg;
|
|
10
|
-
client = null;
|
|
11
|
-
writeDebounceMs = 100;
|
|
12
|
-
discoveryCacheTtlMs = 30_000;
|
|
13
|
-
lastDiscoveryAt = 0;
|
|
14
|
-
logger;
|
|
15
|
-
pendingWrites = new Map();
|
|
16
|
-
constructor(cfg) {
|
|
17
|
-
this.cfg = cfg;
|
|
18
|
-
this.logger = cfg?.logger;
|
|
19
|
-
if (!this.logger) {
|
|
20
|
-
throw new Error('SwitchBotClient requires a logger (Homebridge logger) in config');
|
|
21
|
-
}
|
|
22
|
-
if (typeof cfg?.writeDebounceMs === 'number') {
|
|
23
|
-
this.writeDebounceMs = cfg.writeDebounceMs;
|
|
24
|
-
}
|
|
25
|
-
if (typeof cfg?.discoveryCacheTtlMs === 'number') {
|
|
26
|
-
this.discoveryCacheTtlMs = Math.max(0, cfg.discoveryCacheTtlMs);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async init() {
|
|
30
|
-
if (this.client) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
// Dynamic import of node-switchbot v4 with native resilience features
|
|
35
|
-
const { SwitchBot } = await import('node-switchbot');
|
|
36
|
-
const rawNodeClientConfig = typeof this.cfg?.nodeClientConfig === 'object' ? this.cfg.nodeClientConfig : {};
|
|
37
|
-
const scanTimeout = this.resolveScanTimeoutMs(rawNodeClientConfig);
|
|
38
|
-
this.client = new SwitchBot({
|
|
39
|
-
token: this.cfg.openApiToken,
|
|
40
|
-
secret: this.cfg.openApiSecret,
|
|
41
|
-
// Enable built-in resilience features from node-switchbot v4.
|
|
42
|
-
enableFallback: true, // Auto-fallback from BLE to API
|
|
43
|
-
enableRetry: true, // Retry with exponential backoff
|
|
44
|
-
enableCircuitBreaker: true, // Circuit breaker per connection type
|
|
45
|
-
enableConnectionIntelligence: true, // Connection tracking and route preference
|
|
46
|
-
enableBLE: this.cfg.enableBLE !== false, // Use config value, default true
|
|
47
|
-
scanTimeout,
|
|
48
|
-
...rawNodeClientConfig,
|
|
49
|
-
});
|
|
50
|
-
this.lastDiscoveryAt = 0;
|
|
51
|
-
this.logger?.info?.('SwitchBot client initialized with native resilience features');
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
this.logger?.warn?.('Failed to load node-switchbot; will use OpenAPI fallback:', e);
|
|
55
|
-
this.client = null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async getDevice(id) {
|
|
59
|
-
if (this.client) {
|
|
60
|
-
try {
|
|
61
|
-
const fromManager = this.getManagedDevice(id);
|
|
62
|
-
if (fromManager) {
|
|
63
|
-
return fromManager;
|
|
64
|
-
}
|
|
65
|
-
const devices = await this.ensureDiscovered(false);
|
|
66
|
-
const fromDiscovery = devices.find((d) => d.id === id);
|
|
67
|
-
if (fromDiscovery) {
|
|
68
|
-
return fromDiscovery;
|
|
69
|
-
}
|
|
70
|
-
const refreshDevices = await this.ensureDiscovered(true);
|
|
71
|
-
return refreshDevices.find((d) => d.id === id);
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
if (e instanceof SwitchbotAuthenticationError) {
|
|
75
|
-
this.logger?.error?.(`Authentication error for getDevice(${id}):`, e.message);
|
|
76
|
-
throw e;
|
|
77
|
-
}
|
|
78
|
-
else if (e instanceof SwitchbotOperationError) {
|
|
79
|
-
this.logger?.warn?.(`Operation error for getDevice(${id}):`, e.message, e.code);
|
|
80
|
-
throw e;
|
|
81
|
-
}
|
|
82
|
-
else if (e instanceof CharacteristicMissingError) {
|
|
83
|
-
this.logger?.warn?.(`Characteristic missing for getDevice(${id}):`, e.characteristic);
|
|
84
|
-
throw e;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.logger?.warn?.(`Client getDevice failed for ${id}:`, e);
|
|
88
|
-
throw e;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
throw new SwitchbotOperationError('No SwitchBot client available', 'no_client');
|
|
93
|
-
}
|
|
94
|
-
async getDevices() {
|
|
95
|
-
if (this.client) {
|
|
96
|
-
try {
|
|
97
|
-
const fromManager = this.getManagedDevices();
|
|
98
|
-
if (fromManager.length > 0) {
|
|
99
|
-
return fromManager;
|
|
100
|
-
}
|
|
101
|
-
return await this.ensureDiscovered(false);
|
|
102
|
-
}
|
|
103
|
-
catch (e) {
|
|
104
|
-
this.logger?.warn?.('Client getDevices failed:', e);
|
|
105
|
-
throw e;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
throw new SwitchbotOperationError('No SwitchBot client available', 'no_client');
|
|
109
|
-
}
|
|
110
|
-
async setDeviceState(id, body) {
|
|
111
|
-
// Plugin-level debounce: coalesce rapid writes per device
|
|
112
|
-
if (!this.writeDebounceMs || this.writeDebounceMs <= 0) {
|
|
113
|
-
return this._doSetDeviceState(id, body);
|
|
114
|
-
}
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
const existing = this.pendingWrites.get(id);
|
|
117
|
-
if (existing) {
|
|
118
|
-
existing.body = body;
|
|
119
|
-
existing.resolvers.push({ resolve, reject });
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const resolvers = [{ resolve, reject }];
|
|
123
|
-
const timer = setTimeout(async () => {
|
|
124
|
-
const entry = this.pendingWrites.get(id);
|
|
125
|
-
if (!entry) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
this.pendingWrites.delete(id);
|
|
129
|
-
try {
|
|
130
|
-
const out = await this._doSetDeviceState(id, entry.body);
|
|
131
|
-
for (const r of entry.resolvers)
|
|
132
|
-
r.resolve(out);
|
|
133
|
-
}
|
|
134
|
-
catch (e) {
|
|
135
|
-
if (e instanceof SwitchbotAuthenticationError) {
|
|
136
|
-
this.logger?.error?.(`Authentication error for setDeviceState(${id}):`, e.message);
|
|
137
|
-
}
|
|
138
|
-
else if (e instanceof SwitchbotOperationError) {
|
|
139
|
-
this.logger?.warn?.(`Operation error for setDeviceState(${id}):`, e.message, e.code);
|
|
140
|
-
}
|
|
141
|
-
else if (e instanceof CharacteristicMissingError) {
|
|
142
|
-
this.logger?.warn?.(`Characteristic missing for setDeviceState(${id}):`, e.characteristic);
|
|
143
|
-
}
|
|
144
|
-
for (const r of entry.resolvers)
|
|
145
|
-
r.reject(e);
|
|
146
|
-
}
|
|
147
|
-
}, this.writeDebounceMs);
|
|
148
|
-
this.pendingWrites.set(id, { timer, body, resolvers });
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
async _doSetDeviceState(id, body) {
|
|
152
|
-
if (!this.client) {
|
|
153
|
-
throw new SwitchbotOperationError('No SwitchBot client available for setDeviceState', 'no_client');
|
|
154
|
-
}
|
|
155
|
-
try {
|
|
156
|
-
const device = await this.getDevice(id);
|
|
157
|
-
if (!device) {
|
|
158
|
-
throw new SwitchbotOperationError(`Device ${id} not found`, 'device_not_found');
|
|
159
|
-
}
|
|
160
|
-
const deviceType = (device.deviceType ?? '').toLowerCase();
|
|
161
|
-
const command = body?.command;
|
|
162
|
-
if (!command) {
|
|
163
|
-
throw new SwitchbotOperationError('No command specified in body', 'no_command');
|
|
164
|
-
}
|
|
165
|
-
const handler = getDeviceCommandHandler(deviceType, command);
|
|
166
|
-
if (!handler) {
|
|
167
|
-
throw new SwitchbotOperationError(`Unsupported command '${command}' for device type '${deviceType}'`, 'unsupported_command');
|
|
168
|
-
}
|
|
169
|
-
this.logger?.debug?.(`[${id}] Calling mapped command '${command}' for device type '${deviceType}'`);
|
|
170
|
-
return await handler(device, body);
|
|
171
|
-
}
|
|
172
|
-
catch (e) {
|
|
173
|
-
if (e instanceof SwitchbotAuthenticationError) {
|
|
174
|
-
this.logger?.error?.(`Authentication error for setDeviceState(${id}):`, e.message);
|
|
175
|
-
throw e;
|
|
176
|
-
}
|
|
177
|
-
else if (e instanceof SwitchbotOperationError) {
|
|
178
|
-
this.logger?.warn?.(`Operation error for setDeviceState(${id}):`, e.message, e.code);
|
|
179
|
-
throw e;
|
|
180
|
-
}
|
|
181
|
-
else if (e instanceof CharacteristicMissingError) {
|
|
182
|
-
this.logger?.warn?.(`Characteristic missing for setDeviceState(${id}):`, e.characteristic);
|
|
183
|
-
throw e;
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
this.logger?.warn?.(`Device command failed for ${id}:`, e);
|
|
187
|
-
throw e;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
async destroy() {
|
|
192
|
-
for (const [, pending] of this.pendingWrites) {
|
|
193
|
-
clearTimeout(pending.timer);
|
|
194
|
-
const err = new SwitchbotOperationError('Client destroyed before pending write was sent', 'client_destroyed');
|
|
195
|
-
for (const r of pending.resolvers) {
|
|
196
|
-
r.reject(err);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
this.pendingWrites.clear();
|
|
200
|
-
if (this.client?.cleanup) {
|
|
201
|
-
await this.client.cleanup();
|
|
202
|
-
}
|
|
203
|
-
this.client = null;
|
|
204
|
-
this.lastDiscoveryAt = 0;
|
|
205
|
-
}
|
|
206
|
-
resolveScanTimeoutMs(rawNodeClientConfig) {
|
|
207
|
-
if (typeof rawNodeClientConfig.scanTimeout === 'number' && Number.isFinite(rawNodeClientConfig.scanTimeout)) {
|
|
208
|
-
return Math.max(500, rawNodeClientConfig.scanTimeout);
|
|
209
|
-
}
|
|
210
|
-
if (typeof rawNodeClientConfig.scanDuration === 'number' && Number.isFinite(rawNodeClientConfig.scanDuration)) {
|
|
211
|
-
return Math.max(500, rawNodeClientConfig.scanDuration);
|
|
212
|
-
}
|
|
213
|
-
if (typeof this.cfg?.bleScanDurationSeconds === 'number') {
|
|
214
|
-
return Math.max(500, this.cfg.bleScanDurationSeconds * 1000);
|
|
215
|
-
}
|
|
216
|
-
return 5000;
|
|
217
|
-
}
|
|
218
|
-
getManagedDevice(id) {
|
|
219
|
-
const manager = this.client?.devices;
|
|
220
|
-
if (manager?.get) {
|
|
221
|
-
return manager.get(id);
|
|
222
|
-
}
|
|
223
|
-
return undefined;
|
|
224
|
-
}
|
|
225
|
-
getManagedDevices() {
|
|
226
|
-
const manager = this.client?.devices;
|
|
227
|
-
if (manager?.list) {
|
|
228
|
-
const list = manager.list();
|
|
229
|
-
return Array.isArray(list) ? list : [];
|
|
230
|
-
}
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
async ensureDiscovered(force) {
|
|
234
|
-
if (!this.client) {
|
|
235
|
-
throw new SwitchbotOperationError('No SwitchBot client available', 'no_client');
|
|
236
|
-
}
|
|
237
|
-
const fromManager = this.getManagedDevices();
|
|
238
|
-
const cacheValid = this.discoveryCacheTtlMs > 0 && (Date.now() - this.lastDiscoveryAt) < this.discoveryCacheTtlMs;
|
|
239
|
-
if (!force && cacheValid && fromManager.length > 0) {
|
|
240
|
-
return fromManager;
|
|
241
|
-
}
|
|
242
|
-
const discovered = await this.client.discover();
|
|
243
|
-
this.lastDiscoveryAt = Date.now();
|
|
244
|
-
return discovered;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
//# sourceMappingURL=switchbotClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"switchbotClient.js","sourceRoot":"","sources":["switchbotClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAU/G;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAClB,GAAG,CAAuB;IAC1B,MAAM,GAAqB,IAAI,CAAA;IAC/B,eAAe,GAAG,GAAG,CA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