@switchbot/openapi-cli 1.0.0 → 1.1.0
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/LICENSE +21 -21
- package/README.md +376 -278
- package/dist/commands/completion.js +228 -228
- package/dist/commands/devices.js +163 -128
- package/dist/commands/devices.js.map +1 -1
- package/dist/commands/webhook.js +24 -24
- package/dist/devices/cache.d.ts +25 -0
- package/dist/devices/cache.js +74 -0
- package/dist/devices/cache.js.map +1 -0
- package/dist/index.js +38 -38
- package/package.json +62 -62
package/dist/index.js
CHANGED
|
@@ -22,44 +22,44 @@ registerDevicesCommand(program);
|
|
|
22
22
|
registerScenesCommand(program);
|
|
23
23
|
registerWebhookCommand(program);
|
|
24
24
|
registerCompletionCommand(program);
|
|
25
|
-
program.addHelpText('after', `
|
|
26
|
-
Credentials:
|
|
27
|
-
Provide SwitchBot API v1.1 credentials via either:
|
|
28
|
-
• environment variables SWITCHBOT_TOKEN and SWITCHBOT_SECRET (take priority), or
|
|
29
|
-
• ~/.switchbot/config.json written by 'switchbot config set-token'
|
|
30
|
-
• override the file path with --config <path>
|
|
31
|
-
|
|
32
|
-
Exit codes:
|
|
33
|
-
0 success (including --dry-run intercept)
|
|
34
|
-
1 runtime error (API error, network failure, missing credentials, etc.)
|
|
35
|
-
2 usage error (bad flag, unknown subcommand, invalid argument, unknown device type)
|
|
36
|
-
|
|
37
|
-
Environment:
|
|
38
|
-
SWITCHBOT_TOKEN credential token (takes priority over config file)
|
|
39
|
-
SWITCHBOT_SECRET credential secret (takes priority over config file)
|
|
40
|
-
NO_COLOR disable ANSI colors (auto-respected via chalk)
|
|
41
|
-
|
|
42
|
-
Examples:
|
|
43
|
-
$ switchbot config set-token <token> <secret>
|
|
44
|
-
$ switchbot devices list
|
|
45
|
-
$ switchbot devices list --json | jq '.deviceList[].deviceId'
|
|
46
|
-
$ switchbot devices describe <deviceId> # what commands does this device support?
|
|
47
|
-
$ switchbot devices commands <type> # offline lookup, e.g. Bot / Curtain / "Smart Lock"
|
|
48
|
-
$ switchbot devices status <deviceId> # live state: battery, position, temperature, …
|
|
49
|
-
$ switchbot devices command <deviceId> turnOn
|
|
50
|
-
$ switchbot devices command <deviceId> turnOn --dry-run
|
|
51
|
-
$ switchbot scenes execute <sceneId> --verbose
|
|
52
|
-
$ switchbot webhook setup https://your.host/hook
|
|
53
|
-
|
|
54
|
-
Discovery:
|
|
55
|
-
Don't know a device ID / what it supports?
|
|
56
|
-
switchbot devices list → find your deviceIds + types
|
|
57
|
-
switchbot devices describe <deviceId> → live: metadata + supported commands
|
|
58
|
-
switchbot devices status <deviceId> → live: current values (battery, position, …)
|
|
59
|
-
switchbot devices types → offline: list every known type
|
|
60
|
-
switchbot devices commands <type> → offline: commands + parameters + status fields for a type
|
|
61
|
-
|
|
62
|
-
Docs: https://github.com/OpenWonderLabs/SwitchBotAPI
|
|
25
|
+
program.addHelpText('after', `
|
|
26
|
+
Credentials:
|
|
27
|
+
Provide SwitchBot API v1.1 credentials via either:
|
|
28
|
+
• environment variables SWITCHBOT_TOKEN and SWITCHBOT_SECRET (take priority), or
|
|
29
|
+
• ~/.switchbot/config.json written by 'switchbot config set-token'
|
|
30
|
+
• override the file path with --config <path>
|
|
31
|
+
|
|
32
|
+
Exit codes:
|
|
33
|
+
0 success (including --dry-run intercept)
|
|
34
|
+
1 runtime error (API error, network failure, missing credentials, etc.)
|
|
35
|
+
2 usage error (bad flag, unknown subcommand, invalid argument, unknown device type)
|
|
36
|
+
|
|
37
|
+
Environment:
|
|
38
|
+
SWITCHBOT_TOKEN credential token (takes priority over config file)
|
|
39
|
+
SWITCHBOT_SECRET credential secret (takes priority over config file)
|
|
40
|
+
NO_COLOR disable ANSI colors (auto-respected via chalk)
|
|
41
|
+
|
|
42
|
+
Examples:
|
|
43
|
+
$ switchbot config set-token <token> <secret>
|
|
44
|
+
$ switchbot devices list
|
|
45
|
+
$ switchbot devices list --json | jq '.deviceList[].deviceId'
|
|
46
|
+
$ switchbot devices describe <deviceId> # what commands does this device support?
|
|
47
|
+
$ switchbot devices commands <type> # offline lookup, e.g. Bot / Curtain / "Smart Lock"
|
|
48
|
+
$ switchbot devices status <deviceId> # live state: battery, position, temperature, …
|
|
49
|
+
$ switchbot devices command <deviceId> turnOn
|
|
50
|
+
$ switchbot devices command <deviceId> turnOn --dry-run
|
|
51
|
+
$ switchbot scenes execute <sceneId> --verbose
|
|
52
|
+
$ switchbot webhook setup https://your.host/hook
|
|
53
|
+
|
|
54
|
+
Discovery:
|
|
55
|
+
Don't know a device ID / what it supports?
|
|
56
|
+
switchbot devices list → find your deviceIds + types
|
|
57
|
+
switchbot devices describe <deviceId> → live: metadata + supported commands
|
|
58
|
+
switchbot devices status <deviceId> → live: current values (battery, position, …)
|
|
59
|
+
switchbot devices types → offline: list every known type
|
|
60
|
+
switchbot devices commands <type> → offline: commands + parameters + status fields for a type
|
|
61
|
+
|
|
62
|
+
Docs: https://github.com/OpenWonderLabs/SwitchBotAPI
|
|
63
63
|
`);
|
|
64
64
|
// Map commander usage errors (unknown option, missing argument, etc.) to exit code 2.
|
|
65
65
|
program.exitOverride((err) => {
|
package/package.json
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@switchbot/openapi-cli",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Command-line interface for SwitchBot API v1.1",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"switchbot",
|
|
7
|
-
"cli",
|
|
8
|
-
"iot",
|
|
9
|
-
"smart-home",
|
|
10
|
-
"home-automation",
|
|
11
|
-
"openapi"
|
|
12
|
-
],
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"author": "chenliuyun <chenliuyun@onero.com>",
|
|
15
|
-
"homepage": "https://github.com/
|
|
16
|
-
"bugs": {
|
|
17
|
-
"url": "https://github.com/
|
|
18
|
-
},
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/
|
|
22
|
-
},
|
|
23
|
-
"type": "module",
|
|
24
|
-
"bin": {
|
|
25
|
-
"switchbot": "dist/index.js"
|
|
26
|
-
},
|
|
27
|
-
"files": [
|
|
28
|
-
"dist",
|
|
29
|
-
"README.md",
|
|
30
|
-
"LICENSE"
|
|
31
|
-
],
|
|
32
|
-
"engines": {
|
|
33
|
-
"node": ">=18"
|
|
34
|
-
},
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"access": "public"
|
|
37
|
-
},
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "tsc",
|
|
40
|
-
"dev": "tsx src/index.ts",
|
|
41
|
-
"start": "node dist/index.js",
|
|
42
|
-
"test": "vitest run",
|
|
43
|
-
"test:watch": "vitest",
|
|
44
|
-
"test:coverage": "vitest run --coverage",
|
|
45
|
-
"prepublishOnly": "npm run build && npm test"
|
|
46
|
-
},
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"axios": "^1.7.9",
|
|
49
|
-
"chalk": "^5.4.1",
|
|
50
|
-
"cli-table3": "^0.6.5",
|
|
51
|
-
"commander": "^12.1.0",
|
|
52
|
-
"uuid": "^11.0.5"
|
|
53
|
-
},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"@types/node": "^22.10.7",
|
|
56
|
-
"@types/uuid": "^10.0.0",
|
|
57
|
-
"@vitest/coverage-v8": "^2.1.9",
|
|
58
|
-
"tsx": "^4.19.2",
|
|
59
|
-
"typescript": "^5.7.3",
|
|
60
|
-
"vitest": "^2.1.9"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@switchbot/openapi-cli",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Command-line interface for SwitchBot API v1.1",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"switchbot",
|
|
7
|
+
"cli",
|
|
8
|
+
"iot",
|
|
9
|
+
"smart-home",
|
|
10
|
+
"home-automation",
|
|
11
|
+
"openapi"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "chenliuyun <chenliuyun@onero.com>",
|
|
15
|
+
"homepage": "https://github.com/OpenWonderLabs/switchbot-openapi-cli#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/OpenWonderLabs/switchbot-openapi-cli/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/OpenWonderLabs/switchbot-openapi-cli.git"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"bin": {
|
|
25
|
+
"switchbot": "dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc",
|
|
40
|
+
"dev": "tsx src/index.ts",
|
|
41
|
+
"start": "node dist/index.js",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"test:watch": "vitest",
|
|
44
|
+
"test:coverage": "vitest run --coverage",
|
|
45
|
+
"prepublishOnly": "npm run build && npm test"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"axios": "^1.7.9",
|
|
49
|
+
"chalk": "^5.4.1",
|
|
50
|
+
"cli-table3": "^0.6.5",
|
|
51
|
+
"commander": "^12.1.0",
|
|
52
|
+
"uuid": "^11.0.5"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^22.10.7",
|
|
56
|
+
"@types/uuid": "^10.0.0",
|
|
57
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
58
|
+
"tsx": "^4.19.2",
|
|
59
|
+
"typescript": "^5.7.3",
|
|
60
|
+
"vitest": "^2.1.9"
|
|
61
|
+
}
|
|
62
|
+
}
|