@switchbot/openapi-cli 1.0.0 → 1.0.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/LICENSE +21 -21
- package/README.md +376 -278
- package/dist/commands/completion.js +228 -228
- package/dist/commands/devices.js +128 -128
- package/dist/commands/webhook.js +24 -24
- package/dist/index.js +38 -38
- package/package.json +62 -62
package/dist/commands/devices.js
CHANGED
|
@@ -5,52 +5,52 @@ export function registerDevicesCommand(program) {
|
|
|
5
5
|
const devices = program
|
|
6
6
|
.command('devices')
|
|
7
7
|
.description('Manage and control SwitchBot devices')
|
|
8
|
-
.addHelpText('after', `
|
|
9
|
-
Typical workflow:
|
|
10
|
-
1. Discover your devices → switchbot devices list
|
|
11
|
-
2. Describe a specific device → switchbot devices describe <id>
|
|
12
|
-
3. Or look up a type offline → switchbot devices types
|
|
13
|
-
switchbot devices commands <type>
|
|
14
|
-
4. Send a command → switchbot devices command <id> <cmd> [param]
|
|
15
|
-
|
|
16
|
-
Online subcommands (hit the SwitchBot API):
|
|
17
|
-
list List all physical + IR remote devices on your account
|
|
18
|
-
status Query a device's real-time status values
|
|
19
|
-
command Send a control command (turnOn, setColor, setAll, startClean, …)
|
|
20
|
-
describe Show one device's metadata + its supported commands + status fields
|
|
21
|
-
|
|
22
|
-
Offline subcommands (built-in catalog, no API call):
|
|
23
|
-
types List every device type this CLI knows about
|
|
24
|
-
commands Show commands + parameter formats + status fields for a type
|
|
25
|
-
|
|
26
|
-
Run any subcommand with --help for its own flags and examples.
|
|
8
|
+
.addHelpText('after', `
|
|
9
|
+
Typical workflow:
|
|
10
|
+
1. Discover your devices → switchbot devices list
|
|
11
|
+
2. Describe a specific device → switchbot devices describe <id>
|
|
12
|
+
3. Or look up a type offline → switchbot devices types
|
|
13
|
+
switchbot devices commands <type>
|
|
14
|
+
4. Send a command → switchbot devices command <id> <cmd> [param]
|
|
15
|
+
|
|
16
|
+
Online subcommands (hit the SwitchBot API):
|
|
17
|
+
list List all physical + IR remote devices on your account
|
|
18
|
+
status Query a device's real-time status values
|
|
19
|
+
command Send a control command (turnOn, setColor, setAll, startClean, …)
|
|
20
|
+
describe Show one device's metadata + its supported commands + status fields
|
|
21
|
+
|
|
22
|
+
Offline subcommands (built-in catalog, no API call):
|
|
23
|
+
types List every device type this CLI knows about
|
|
24
|
+
commands Show commands + parameter formats + status fields for a type
|
|
25
|
+
|
|
26
|
+
Run any subcommand with --help for its own flags and examples.
|
|
27
27
|
`);
|
|
28
28
|
// switchbot devices list
|
|
29
29
|
devices
|
|
30
30
|
.command('list')
|
|
31
31
|
.description('List all physical devices and IR remote devices on the account')
|
|
32
|
-
.addHelpText('after', `
|
|
33
|
-
Output columns: deviceId, deviceName, type, controlType, family, roomID, room, hub, cloud
|
|
34
|
-
|
|
35
|
-
type - physical deviceType (e.g. "Bot", "Curtain") or "[IR] <remoteType>"
|
|
36
|
-
controlType - functional classification from the API (e.g. "Bot", "Switch",
|
|
37
|
-
"TV") — may differ from 'type' and groups devices by behavior
|
|
38
|
-
family - home/family name (IR remotes inherit this from their bound Hub)
|
|
39
|
-
roomID - internal room identifier (IR remotes inherit from their
|
|
40
|
-
bound Hub; — when unassigned/unknown)
|
|
41
|
-
room - room name this device is assigned to (IR remotes inherit from
|
|
42
|
-
Hub; — when unassigned/unknown)
|
|
43
|
-
hub - "—" when the device is its own hub or hubDeviceId is empty
|
|
44
|
-
cloud - ✓/✗: whether cloud service is enabled (— for IR remotes)
|
|
45
|
-
|
|
46
|
-
controlType, family/room, and roomID require the 'src: OpenClaw' header, which
|
|
47
|
-
this CLI always sends. (IR family/room inheritance is computed client-side for
|
|
48
|
-
the table; --json returns the raw API body unchanged.)
|
|
49
|
-
|
|
50
|
-
Examples:
|
|
51
|
-
$ switchbot devices list
|
|
52
|
-
$ switchbot devices list --json | jq '.deviceList[] | select(.familyName == "家里")'
|
|
53
|
-
$ switchbot devices list --json | jq '[.deviceList[], .infraredRemoteList[]] | group_by(.familyName)'
|
|
32
|
+
.addHelpText('after', `
|
|
33
|
+
Output columns: deviceId, deviceName, type, controlType, family, roomID, room, hub, cloud
|
|
34
|
+
|
|
35
|
+
type - physical deviceType (e.g. "Bot", "Curtain") or "[IR] <remoteType>"
|
|
36
|
+
controlType - functional classification from the API (e.g. "Bot", "Switch",
|
|
37
|
+
"TV") — may differ from 'type' and groups devices by behavior
|
|
38
|
+
family - home/family name (IR remotes inherit this from their bound Hub)
|
|
39
|
+
roomID - internal room identifier (IR remotes inherit from their
|
|
40
|
+
bound Hub; — when unassigned/unknown)
|
|
41
|
+
room - room name this device is assigned to (IR remotes inherit from
|
|
42
|
+
Hub; — when unassigned/unknown)
|
|
43
|
+
hub - "—" when the device is its own hub or hubDeviceId is empty
|
|
44
|
+
cloud - ✓/✗: whether cloud service is enabled (— for IR remotes)
|
|
45
|
+
|
|
46
|
+
controlType, family/room, and roomID require the 'src: OpenClaw' header, which
|
|
47
|
+
this CLI always sends. (IR family/room inheritance is computed client-side for
|
|
48
|
+
the table; --json returns the raw API body unchanged.)
|
|
49
|
+
|
|
50
|
+
Examples:
|
|
51
|
+
$ switchbot devices list
|
|
52
|
+
$ switchbot devices list --json | jq '.deviceList[] | select(.familyName == "家里")'
|
|
53
|
+
$ switchbot devices list --json | jq '[.deviceList[], .infraredRemoteList[]] | group_by(.familyName)'
|
|
54
54
|
`)
|
|
55
55
|
.action(async () => {
|
|
56
56
|
try {
|
|
@@ -107,24 +107,24 @@ Examples:
|
|
|
107
107
|
.command('status')
|
|
108
108
|
.description('Query the real-time status of a specific device')
|
|
109
109
|
.argument('<deviceId>', 'Device ID from "devices list" (physical devices only; IR remotes have no status)')
|
|
110
|
-
.addHelpText('after', `
|
|
111
|
-
Returned fields vary by device type — e.g. Bot returns power/battery, Meter
|
|
112
|
-
returns temperature/humidity/battery, Curtain returns slidePosition/moving,
|
|
113
|
-
Color Bulb returns brightness/color/colorTemperature, etc.
|
|
114
|
-
|
|
115
|
-
To see exactly which status fields a given type returns BEFORE calling the
|
|
116
|
-
API, use the offline catalog:
|
|
117
|
-
|
|
118
|
-
switchbot devices commands <type> (prints the "Status fields" section)
|
|
119
|
-
|
|
120
|
-
IR remote devices cannot be queried — the SwitchBot API returns no status
|
|
121
|
-
channel for them. Use 'devices list' to confirm a deviceId is a physical
|
|
122
|
-
device (not in the 'infraredRemoteList').
|
|
123
|
-
|
|
124
|
-
Examples:
|
|
125
|
-
$ switchbot devices status ABC123DEF456
|
|
126
|
-
$ switchbot devices status ABC123DEF456 --json
|
|
127
|
-
$ switchbot devices status ABC123DEF456 --json | jq '.battery'
|
|
110
|
+
.addHelpText('after', `
|
|
111
|
+
Returned fields vary by device type — e.g. Bot returns power/battery, Meter
|
|
112
|
+
returns temperature/humidity/battery, Curtain returns slidePosition/moving,
|
|
113
|
+
Color Bulb returns brightness/color/colorTemperature, etc.
|
|
114
|
+
|
|
115
|
+
To see exactly which status fields a given type returns BEFORE calling the
|
|
116
|
+
API, use the offline catalog:
|
|
117
|
+
|
|
118
|
+
switchbot devices commands <type> (prints the "Status fields" section)
|
|
119
|
+
|
|
120
|
+
IR remote devices cannot be queried — the SwitchBot API returns no status
|
|
121
|
+
channel for them. Use 'devices list' to confirm a deviceId is a physical
|
|
122
|
+
device (not in the 'infraredRemoteList').
|
|
123
|
+
|
|
124
|
+
Examples:
|
|
125
|
+
$ switchbot devices status ABC123DEF456
|
|
126
|
+
$ switchbot devices status ABC123DEF456 --json
|
|
127
|
+
$ switchbot devices status ABC123DEF456 --json | jq '.battery'
|
|
128
128
|
`)
|
|
129
129
|
.action(async (deviceId) => {
|
|
130
130
|
try {
|
|
@@ -148,44 +148,44 @@ Examples:
|
|
|
148
148
|
.argument('<cmd>', 'Command name, e.g. turnOn, turnOff, setColor, setBrightness, setAll, startClean')
|
|
149
149
|
.argument('[parameter]', 'Command parameter. Omit for commands like turnOn/turnOff (defaults to "default"). Format depends on the command (see below).')
|
|
150
150
|
.option('--type <commandType>', 'Command type: "command" for built-in commands (default), "customize" for user-defined IR buttons', 'command')
|
|
151
|
-
.addHelpText('after', `
|
|
152
|
-
────────────────────────────────────────────────────────────────────────
|
|
153
|
-
For the full list of commands a specific device supports — and their
|
|
154
|
-
exact parameter formats — run:
|
|
155
|
-
|
|
156
|
-
switchbot devices commands <type> (e.g. Bot, Curtain, "Smart Lock")
|
|
157
|
-
|
|
158
|
-
The catalog is the authoritative per-device reference. This page only
|
|
159
|
-
covers the generic mechanics that apply to every device.
|
|
160
|
-
────────────────────────────────────────────────────────────────────────
|
|
161
|
-
|
|
162
|
-
Rules:
|
|
163
|
-
• Command names are CASE-SENSITIVE (e.g. SetChannel, FastForward, volumeAdd).
|
|
164
|
-
• Quote any parameter containing ':' ',' ';' or '{ }' to protect it from the shell.
|
|
165
|
-
• The parameter is parsed as JSON when possible; otherwise passed through as a string.
|
|
166
|
-
• Omit the parameter for no-arg commands — it auto-defaults to "default".
|
|
167
|
-
• Use --type customize to trigger a user-defined IR button by name.
|
|
168
|
-
|
|
169
|
-
Generic parameter shapes (see 'devices commands <type>' for which one applies):
|
|
170
|
-
|
|
171
|
-
(none) turnOn, turnOff, toggle, press, play, pause, …
|
|
172
|
-
<integer> setBrightness 75, setColorTemperature 4000, SetChannel 15
|
|
173
|
-
<R:G:B> setColor "255:0:0"
|
|
174
|
-
<direction;angle> setPosition "up;60" (Blind Tilt)
|
|
175
|
-
<a,b,c,…> setAll "26,1,3,on" (IR AC)
|
|
176
|
-
<json object> startClean '{"action":"sweep","param":{"fanLevel":2,"times":1}}'
|
|
177
|
-
|
|
178
|
-
Common errors:
|
|
179
|
-
160 command not supported by this device
|
|
180
|
-
161 device offline (BLE devices need a Hub bridge)
|
|
181
|
-
171 hub offline
|
|
182
|
-
|
|
183
|
-
Examples:
|
|
184
|
-
$ switchbot devices command ABC123 turnOn
|
|
185
|
-
$ switchbot devices command ABC123 setColor "255:0:0"
|
|
186
|
-
$ switchbot devices command ABC123 setAll "26,1,3,on"
|
|
187
|
-
$ switchbot devices command ABC123 startClean '{"action":"sweep","param":{"fanLevel":2,"times":1}}'
|
|
188
|
-
$ switchbot devices command ABC123 "MyButton" --type customize
|
|
151
|
+
.addHelpText('after', `
|
|
152
|
+
────────────────────────────────────────────────────────────────────────
|
|
153
|
+
For the full list of commands a specific device supports — and their
|
|
154
|
+
exact parameter formats — run:
|
|
155
|
+
|
|
156
|
+
switchbot devices commands <type> (e.g. Bot, Curtain, "Smart Lock")
|
|
157
|
+
|
|
158
|
+
The catalog is the authoritative per-device reference. This page only
|
|
159
|
+
covers the generic mechanics that apply to every device.
|
|
160
|
+
────────────────────────────────────────────────────────────────────────
|
|
161
|
+
|
|
162
|
+
Rules:
|
|
163
|
+
• Command names are CASE-SENSITIVE (e.g. SetChannel, FastForward, volumeAdd).
|
|
164
|
+
• Quote any parameter containing ':' ',' ';' or '{ }' to protect it from the shell.
|
|
165
|
+
• The parameter is parsed as JSON when possible; otherwise passed through as a string.
|
|
166
|
+
• Omit the parameter for no-arg commands — it auto-defaults to "default".
|
|
167
|
+
• Use --type customize to trigger a user-defined IR button by name.
|
|
168
|
+
|
|
169
|
+
Generic parameter shapes (see 'devices commands <type>' for which one applies):
|
|
170
|
+
|
|
171
|
+
(none) turnOn, turnOff, toggle, press, play, pause, …
|
|
172
|
+
<integer> setBrightness 75, setColorTemperature 4000, SetChannel 15
|
|
173
|
+
<R:G:B> setColor "255:0:0"
|
|
174
|
+
<direction;angle> setPosition "up;60" (Blind Tilt)
|
|
175
|
+
<a,b,c,…> setAll "26,1,3,on" (IR AC)
|
|
176
|
+
<json object> startClean '{"action":"sweep","param":{"fanLevel":2,"times":1}}'
|
|
177
|
+
|
|
178
|
+
Common errors:
|
|
179
|
+
160 command not supported by this device
|
|
180
|
+
161 device offline (BLE devices need a Hub bridge)
|
|
181
|
+
171 hub offline
|
|
182
|
+
|
|
183
|
+
Examples:
|
|
184
|
+
$ switchbot devices command ABC123 turnOn
|
|
185
|
+
$ switchbot devices command ABC123 setColor "255:0:0"
|
|
186
|
+
$ switchbot devices command ABC123 setAll "26,1,3,on"
|
|
187
|
+
$ switchbot devices command ABC123 startClean '{"action":"sweep","param":{"fanLevel":2,"times":1}}'
|
|
188
|
+
$ switchbot devices command ABC123 "MyButton" --type customize
|
|
189
189
|
`)
|
|
190
190
|
.action(async (deviceId, cmd, parameter, options) => {
|
|
191
191
|
try {
|
|
@@ -223,13 +223,13 @@ Examples:
|
|
|
223
223
|
devices
|
|
224
224
|
.command('types')
|
|
225
225
|
.description('List all device types known to this CLI (offline reference, no API call)')
|
|
226
|
-
.addHelpText('after', `
|
|
227
|
-
Output columns: type, category (physical | ir), commands, aliases
|
|
228
|
-
Use 'switchbot devices commands <type>' to see what a given type supports.
|
|
229
|
-
|
|
230
|
-
Examples:
|
|
231
|
-
$ switchbot devices types
|
|
232
|
-
$ switchbot devices types --json
|
|
226
|
+
.addHelpText('after', `
|
|
227
|
+
Output columns: type, category (physical | ir), commands, aliases
|
|
228
|
+
Use 'switchbot devices commands <type>' to see what a given type supports.
|
|
229
|
+
|
|
230
|
+
Examples:
|
|
231
|
+
$ switchbot devices types
|
|
232
|
+
$ switchbot devices types --json
|
|
233
233
|
`)
|
|
234
234
|
.action(() => {
|
|
235
235
|
if (isJsonMode()) {
|
|
@@ -250,20 +250,20 @@ Examples:
|
|
|
250
250
|
.command('commands')
|
|
251
251
|
.description('Show supported commands, parameter formats, and status fields for a device type')
|
|
252
252
|
.argument('<type...>', 'Device type name or alias (case-insensitive, partial matches supported; multi-word types do not need quoting)')
|
|
253
|
-
.addHelpText('after', `
|
|
254
|
-
This is the authoritative per-device reference — every command the CLI
|
|
255
|
-
can send to a given type, its parameter format, and the status fields
|
|
256
|
-
'devices status' will return. Runs fully offline (no API call).
|
|
257
|
-
|
|
258
|
-
Multi-word types can be passed either quoted or unquoted — both work:
|
|
259
|
-
$ switchbot devices commands "Air Conditioner"
|
|
260
|
-
$ switchbot devices commands Air Conditioner
|
|
261
|
-
$ switchbot devices commands "Smart Lock"
|
|
262
|
-
|
|
263
|
-
Examples:
|
|
264
|
-
$ switchbot devices commands Bot
|
|
265
|
-
$ switchbot devices commands curtain
|
|
266
|
-
$ switchbot devices commands Robot --json
|
|
253
|
+
.addHelpText('after', `
|
|
254
|
+
This is the authoritative per-device reference — every command the CLI
|
|
255
|
+
can send to a given type, its parameter format, and the status fields
|
|
256
|
+
'devices status' will return. Runs fully offline (no API call).
|
|
257
|
+
|
|
258
|
+
Multi-word types can be passed either quoted or unquoted — both work:
|
|
259
|
+
$ switchbot devices commands "Air Conditioner"
|
|
260
|
+
$ switchbot devices commands Air Conditioner
|
|
261
|
+
$ switchbot devices commands "Smart Lock"
|
|
262
|
+
|
|
263
|
+
Examples:
|
|
264
|
+
$ switchbot devices commands Bot
|
|
265
|
+
$ switchbot devices commands curtain
|
|
266
|
+
$ switchbot devices commands Robot --json
|
|
267
267
|
`)
|
|
268
268
|
.action((typeParts) => {
|
|
269
269
|
const type = typeParts.join(' ');
|
|
@@ -290,16 +290,16 @@ Examples:
|
|
|
290
290
|
.command('describe')
|
|
291
291
|
.description('Describe a device by ID: metadata + supported commands + status fields (1 API call)')
|
|
292
292
|
.argument('<deviceId>', 'Target device ID from "devices list"')
|
|
293
|
-
.addHelpText('after', `
|
|
294
|
-
Makes a single GET /v1.1/devices call to look up the device's type, then
|
|
295
|
-
prints its metadata alongside the matching catalog entry (supported
|
|
296
|
-
commands + parameter formats + status field names).
|
|
297
|
-
|
|
298
|
-
Does NOT fetch live status values. Use 'switchbot devices status <id>' for that.
|
|
299
|
-
|
|
300
|
-
Examples:
|
|
301
|
-
$ switchbot devices describe ABC123DEF456
|
|
302
|
-
$ switchbot devices describe ABC123DEF456 --json
|
|
293
|
+
.addHelpText('after', `
|
|
294
|
+
Makes a single GET /v1.1/devices call to look up the device's type, then
|
|
295
|
+
prints its metadata alongside the matching catalog entry (supported
|
|
296
|
+
commands + parameter formats + status field names).
|
|
297
|
+
|
|
298
|
+
Does NOT fetch live status values. Use 'switchbot devices status <id>' for that.
|
|
299
|
+
|
|
300
|
+
Examples:
|
|
301
|
+
$ switchbot devices describe ABC123DEF456
|
|
302
|
+
$ switchbot devices describe ABC123DEF456 --json
|
|
303
303
|
`)
|
|
304
304
|
.action(async (deviceId) => {
|
|
305
305
|
try {
|
package/dist/commands/webhook.js
CHANGED
|
@@ -17,18 +17,18 @@ export function registerWebhookCommand(program) {
|
|
|
17
17
|
const webhook = program
|
|
18
18
|
.command('webhook')
|
|
19
19
|
.description('Manage SwitchBot Webhook configuration')
|
|
20
|
-
.addHelpText('after', `
|
|
21
|
-
A webhook lets SwitchBot POST device state-change events to a URL you host.
|
|
22
|
-
Only one webhook URL can be active per account; "setup" registers it for ALL devices.
|
|
20
|
+
.addHelpText('after', `
|
|
21
|
+
A webhook lets SwitchBot POST device state-change events to a URL you host.
|
|
22
|
+
Only one webhook URL can be active per account; "setup" registers it for ALL devices.
|
|
23
23
|
`);
|
|
24
24
|
// switchbot webhook setup <url>
|
|
25
25
|
const setup = webhook
|
|
26
26
|
.command('setup')
|
|
27
27
|
.description('Configure the webhook receiver URL (receives events from all devices)')
|
|
28
28
|
.argument('<url>', 'Absolute http(s):// URL where SwitchBot will POST events')
|
|
29
|
-
.addHelpText('after', `
|
|
30
|
-
Example:
|
|
31
|
-
$ switchbot webhook setup https://example.com/switchbot/events
|
|
29
|
+
.addHelpText('after', `
|
|
30
|
+
Example:
|
|
31
|
+
$ switchbot webhook setup https://example.com/switchbot/events
|
|
32
32
|
`);
|
|
33
33
|
setup.action(async (url) => {
|
|
34
34
|
assertValidUrl(setup, url);
|
|
@@ -50,14 +50,14 @@ Example:
|
|
|
50
50
|
.command('query')
|
|
51
51
|
.description('Query webhook configuration')
|
|
52
52
|
.option('--details <url>', 'Query detailed configuration (enable/deviceList/timestamps) for a specific URL')
|
|
53
|
-
.addHelpText('after', `
|
|
54
|
-
Without --details, lists all configured webhook URLs.
|
|
55
|
-
With --details, prints enable/deviceList/createTime/lastUpdateTime for the given URL.
|
|
56
|
-
|
|
57
|
-
Examples:
|
|
58
|
-
$ switchbot webhook query
|
|
59
|
-
$ switchbot webhook query --details https://example.com/hook
|
|
60
|
-
$ switchbot webhook query --json
|
|
53
|
+
.addHelpText('after', `
|
|
54
|
+
Without --details, lists all configured webhook URLs.
|
|
55
|
+
With --details, prints enable/deviceList/createTime/lastUpdateTime for the given URL.
|
|
56
|
+
|
|
57
|
+
Examples:
|
|
58
|
+
$ switchbot webhook query
|
|
59
|
+
$ switchbot webhook query --details https://example.com/hook
|
|
60
|
+
$ switchbot webhook query --json
|
|
61
61
|
`)
|
|
62
62
|
.action(async (options) => {
|
|
63
63
|
try {
|
|
@@ -109,13 +109,13 @@ Examples:
|
|
|
109
109
|
.argument('<url>', 'URL of the webhook to update (must already be configured)')
|
|
110
110
|
.option('--enable', 'Enable the webhook')
|
|
111
111
|
.option('--disable', 'Disable the webhook')
|
|
112
|
-
.addHelpText('after', `
|
|
113
|
-
--enable and --disable are mutually exclusive. If neither is provided, the
|
|
114
|
-
webhook is re-submitted with no change to its enabled state.
|
|
115
|
-
|
|
116
|
-
Examples:
|
|
117
|
-
$ switchbot webhook update https://example.com/hook --enable
|
|
118
|
-
$ switchbot webhook update https://example.com/hook --disable
|
|
112
|
+
.addHelpText('after', `
|
|
113
|
+
--enable and --disable are mutually exclusive. If neither is provided, the
|
|
114
|
+
webhook is re-submitted with no change to its enabled state.
|
|
115
|
+
|
|
116
|
+
Examples:
|
|
117
|
+
$ switchbot webhook update https://example.com/hook --enable
|
|
118
|
+
$ switchbot webhook update https://example.com/hook --disable
|
|
119
119
|
`);
|
|
120
120
|
update.action(async (url, options) => {
|
|
121
121
|
if (options.enable && options.disable) {
|
|
@@ -145,9 +145,9 @@ Examples:
|
|
|
145
145
|
.command('delete')
|
|
146
146
|
.description('Delete webhook configuration')
|
|
147
147
|
.argument('<url>', 'URL of the webhook to remove')
|
|
148
|
-
.addHelpText('after', `
|
|
149
|
-
Example:
|
|
150
|
-
$ switchbot webhook delete https://example.com/hook
|
|
148
|
+
.addHelpText('after', `
|
|
149
|
+
Example:
|
|
150
|
+
$ switchbot webhook delete https://example.com/hook
|
|
151
151
|
`);
|
|
152
152
|
del.action(async (url) => {
|
|
153
153
|
assertValidUrl(del, url);
|
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.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/
|
|
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.0.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/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
|
+
}
|