@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.
@@ -1,62 +1,64 @@
1
1
  import { createClient } from '../api/client.js';
2
2
  import { printTable, printKeyValue, printJson, isJsonMode, handleError } from '../utils/output.js';
3
3
  import { DEVICE_CATALOG, findCatalogEntry } from '../devices/catalog.js';
4
+ import { getCachedDevice, updateCacheFromDeviceList } from '../devices/cache.js';
4
5
  export function registerDevicesCommand(program) {
5
6
  const devices = program
6
7
  .command('devices')
7
8
  .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.
9
+ .addHelpText('after', `
10
+ Typical workflow:
11
+ 1. Discover your devices → switchbot devices list
12
+ 2. Describe a specific device → switchbot devices describe <id>
13
+ 3. Or look up a type offline → switchbot devices types
14
+ switchbot devices commands <type>
15
+ 4. Send a command → switchbot devices command <id> <cmd> [param]
16
+
17
+ Online subcommands (hit the SwitchBot API):
18
+ list List all physical + IR remote devices on your account
19
+ status Query a device's real-time status values
20
+ command Send a control command (turnOn, setColor, setAll, startClean, …)
21
+ describe Show one device's metadata + its supported commands + status fields
22
+
23
+ Offline subcommands (built-in catalog, no API call):
24
+ types List every device type this CLI knows about
25
+ commands Show commands + parameter formats + status fields for a type
26
+
27
+ Run any subcommand with --help for its own flags and examples.
27
28
  `);
28
29
  // switchbot devices list
29
30
  devices
30
31
  .command('list')
31
32
  .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)'
33
+ .addHelpText('after', `
34
+ Output columns: deviceId, deviceName, type, controlType, family, roomID, room, hub, cloud
35
+
36
+ type - physical deviceType (e.g. "Bot", "Curtain") or "[IR] <remoteType>"
37
+ controlType - functional classification from the API (e.g. "Bot", "Switch",
38
+ "TV") — may differ from 'type' and groups devices by behavior
39
+ family - home/family name (IR remotes inherit this from their bound Hub)
40
+ roomID - internal room identifier (IR remotes inherit from their
41
+ bound Hub; — when unassigned/unknown)
42
+ room - room name this device is assigned to (IR remotes inherit from
43
+ Hub; — when unassigned/unknown)
44
+ hub - "—" when the device is its own hub or hubDeviceId is empty
45
+ cloud - ✓/✗: whether cloud service is enabled (— for IR remotes)
46
+
47
+ controlType, family/room, and roomID require the 'src: OpenClaw' header, which
48
+ this CLI always sends. (IR family/room inheritance is computed client-side for
49
+ the table; --json returns the raw API body unchanged.)
50
+
51
+ Examples:
52
+ $ switchbot devices list
53
+ $ switchbot devices list --json | jq '.deviceList[] | select(.familyName == "家里")'
54
+ $ switchbot devices list --json | jq '[.deviceList[], .infraredRemoteList[]] | group_by(.familyName)'
54
55
  `)
55
56
  .action(async () => {
56
57
  try {
57
58
  const client = createClient();
58
59
  const res = await client.get('/v1.1/devices');
59
60
  const { deviceList, infraredRemoteList } = res.data.body;
61
+ updateCacheFromDeviceList(res.data.body);
60
62
  if (isJsonMode()) {
61
63
  printJson(res.data.body);
62
64
  return;
@@ -107,24 +109,24 @@ Examples:
107
109
  .command('status')
108
110
  .description('Query the real-time status of a specific device')
109
111
  .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'
112
+ .addHelpText('after', `
113
+ Returned fields vary by device type — e.g. Bot returns power/battery, Meter
114
+ returns temperature/humidity/battery, Curtain returns slidePosition/moving,
115
+ Color Bulb returns brightness/color/colorTemperature, etc.
116
+
117
+ To see exactly which status fields a given type returns BEFORE calling the
118
+ API, use the offline catalog:
119
+
120
+ switchbot devices commands <type> (prints the "Status fields" section)
121
+
122
+ IR remote devices cannot be queried — the SwitchBot API returns no status
123
+ channel for them. Use 'devices list' to confirm a deviceId is a physical
124
+ device (not in the 'infraredRemoteList').
125
+
126
+ Examples:
127
+ $ switchbot devices status ABC123DEF456
128
+ $ switchbot devices status ABC123DEF456 --json
129
+ $ switchbot devices status ABC123DEF456 --json | jq '.battery'
128
130
  `)
129
131
  .action(async (deviceId) => {
130
132
  try {
@@ -148,46 +150,47 @@ Examples:
148
150
  .argument('<cmd>', 'Command name, e.g. turnOn, turnOff, setColor, setBrightness, setAll, startClean')
149
151
  .argument('[parameter]', 'Command parameter. Omit for commands like turnOn/turnOff (defaults to "default"). Format depends on the command (see below).')
150
152
  .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
153
+ .addHelpText('after', `
154
+ ────────────────────────────────────────────────────────────────────────
155
+ For the full list of commands a specific device supports — and their
156
+ exact parameter formats — run:
157
+
158
+ switchbot devices commands <type> (e.g. Bot, Curtain, "Smart Lock")
159
+
160
+ The catalog is the authoritative per-device reference. This page only
161
+ covers the generic mechanics that apply to every device.
162
+ ────────────────────────────────────────────────────────────────────────
163
+
164
+ Rules:
165
+ • Command names are CASE-SENSITIVE (e.g. SetChannel, FastForward, volumeAdd).
166
+ • Quote any parameter containing ':' ',' ';' or '{ }' to protect it from the shell.
167
+ • The parameter is parsed as JSON when possible; otherwise passed through as a string.
168
+ • Omit the parameter for no-arg commands — it auto-defaults to "default".
169
+ • Use --type customize to trigger a user-defined IR button by name.
170
+
171
+ Generic parameter shapes (see 'devices commands <type>' for which one applies):
172
+
173
+ (none) turnOn, turnOff, toggle, press, play, pause, …
174
+ <integer> setBrightness 75, setColorTemperature 4000, SetChannel 15
175
+ <R:G:B> setColor "255:0:0"
176
+ <direction;angle> setPosition "up;60" (Blind Tilt)
177
+ <a,b,c,…> setAll "26,1,3,on" (IR AC)
178
+ <json object> startClean '{"action":"sweep","param":{"fanLevel":2,"times":1}}'
179
+
180
+ Common errors:
181
+ 160 command not supported by this device
182
+ 161 device offline (BLE devices need a Hub bridge)
183
+ 171 hub offline
184
+
185
+ Examples:
186
+ $ switchbot devices command ABC123 turnOn
187
+ $ switchbot devices command ABC123 setColor "255:0:0"
188
+ $ switchbot devices command ABC123 setAll "26,1,3,on"
189
+ $ switchbot devices command ABC123 startClean '{"action":"sweep","param":{"fanLevel":2,"times":1}}'
190
+ $ switchbot devices command ABC123 "MyButton" --type customize
189
191
  `)
190
192
  .action(async (deviceId, cmd, parameter, options) => {
193
+ validateCommandAgainstCache(deviceId, cmd, parameter, options.type);
191
194
  try {
192
195
  const client = createClient();
193
196
  // parameter may be a JSON object string (e.g. S10 startClean) or a plain string
@@ -223,13 +226,13 @@ Examples:
223
226
  devices
224
227
  .command('types')
225
228
  .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
229
+ .addHelpText('after', `
230
+ Output columns: type, category (physical | ir), commands, aliases
231
+ Use 'switchbot devices commands <type>' to see what a given type supports.
232
+
233
+ Examples:
234
+ $ switchbot devices types
235
+ $ switchbot devices types --json
233
236
  `)
234
237
  .action(() => {
235
238
  if (isJsonMode()) {
@@ -250,20 +253,20 @@ Examples:
250
253
  .command('commands')
251
254
  .description('Show supported commands, parameter formats, and status fields for a device type')
252
255
  .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
256
+ .addHelpText('after', `
257
+ This is the authoritative per-device reference — every command the CLI
258
+ can send to a given type, its parameter format, and the status fields
259
+ 'devices status' will return. Runs fully offline (no API call).
260
+
261
+ Multi-word types can be passed either quoted or unquoted — both work:
262
+ $ switchbot devices commands "Air Conditioner"
263
+ $ switchbot devices commands Air Conditioner
264
+ $ switchbot devices commands "Smart Lock"
265
+
266
+ Examples:
267
+ $ switchbot devices commands Bot
268
+ $ switchbot devices commands curtain
269
+ $ switchbot devices commands Robot --json
267
270
  `)
268
271
  .action((typeParts) => {
269
272
  const type = typeParts.join(' ');
@@ -290,22 +293,23 @@ Examples:
290
293
  .command('describe')
291
294
  .description('Describe a device by ID: metadata + supported commands + status fields (1 API call)')
292
295
  .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
296
+ .addHelpText('after', `
297
+ Makes a single GET /v1.1/devices call to look up the device's type, then
298
+ prints its metadata alongside the matching catalog entry (supported
299
+ commands + parameter formats + status field names).
300
+
301
+ Does NOT fetch live status values. Use 'switchbot devices status <id>' for that.
302
+
303
+ Examples:
304
+ $ switchbot devices describe ABC123DEF456
305
+ $ switchbot devices describe ABC123DEF456 --json
303
306
  `)
304
307
  .action(async (deviceId) => {
305
308
  try {
306
309
  const client = createClient();
307
310
  const res = await client.get('/v1.1/devices');
308
311
  const { deviceList, infraredRemoteList } = res.data.body;
312
+ updateCacheFromDeviceList(res.data.body);
309
313
  const physical = deviceList.find((d) => d.deviceId === deviceId);
310
314
  const ir = infraredRemoteList.find((d) => d.deviceId === deviceId);
311
315
  if (!physical && !ir) {
@@ -376,6 +380,37 @@ function buildHubLocationMap(deviceList) {
376
380
  }
377
381
  return map;
378
382
  }
383
+ function validateCommandAgainstCache(deviceId, cmd, parameter, commandType) {
384
+ // Custom IR buttons have arbitrary names — skip validation.
385
+ if (commandType === 'customize')
386
+ return;
387
+ const cached = getCachedDevice(deviceId);
388
+ if (!cached)
389
+ return;
390
+ const match = findCatalogEntry(cached.type);
391
+ if (!match || Array.isArray(match))
392
+ return;
393
+ const entry = match;
394
+ const builtinCommands = entry.commands.filter((c) => c.commandType !== 'customize');
395
+ if (builtinCommands.length === 0)
396
+ return;
397
+ const spec = builtinCommands.find((c) => c.command === cmd);
398
+ if (!spec) {
399
+ const unique = [...new Set(builtinCommands.map((c) => c.command))];
400
+ console.error(`Error: "${cmd}" is not a supported command for ${cached.name} (${cached.type}).`);
401
+ console.error(`Supported commands: ${unique.join(', ')}`);
402
+ console.error(`Run 'switchbot devices commands ${JSON.stringify(cached.type)}' for parameter formats and descriptions.`);
403
+ console.error(`(If the catalog is out of date, run 'switchbot devices list' to refresh the local cache, or pass --type customize for custom IR buttons.)`);
404
+ process.exit(2);
405
+ }
406
+ const noParamExpected = spec.parameter === '—';
407
+ const userProvidedParam = parameter !== undefined && parameter !== 'default';
408
+ if (noParamExpected && userProvidedParam) {
409
+ console.error(`Error: "${cmd}" takes no parameter, but one was provided: "${parameter}".`);
410
+ console.error(`Try: switchbot devices command ${deviceId} ${cmd}`);
411
+ process.exit(2);
412
+ }
413
+ }
379
414
  function renderCatalogEntry(entry) {
380
415
  console.log(`Type: ${entry.type}`);
381
416
  console.log(`Category: ${entry.category === 'ir' ? 'IR remote' : 'Physical device'}`);
@@ -1 +1 @@
1
- {"version":3,"file":"devices.js","sourceRoot":"","sources":["../../src/commands/devices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAsB,MAAM,uBAAuB,CAAC;AA6B7F,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,MAAM,OAAO,GAAG,OAAO;SACpB,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,sCAAsC,CAAC;SACnD,WAAW,CAAC,OAAO,EAAE;;;;;;;;;;;;;;;;;;;CAmBzB,CAAC,CAAC;IAED,yBAAyB;IACzB,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,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CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACzD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;YACrC,CAAC,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;YACvE,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,WAAW;SACd,CAAC,CAAC;QACH,UAAU,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxD,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;QACxD,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
@@ -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);
@@ -0,0 +1,25 @@
1
+ export interface CachedDevice {
2
+ type: string;
3
+ name: string;
4
+ category: 'physical' | 'ir';
5
+ }
6
+ export interface DeviceCache {
7
+ lastUpdated: string;
8
+ devices: Record<string, CachedDevice>;
9
+ }
10
+ export interface DeviceListBodyShape {
11
+ deviceList: Array<{
12
+ deviceId: string;
13
+ deviceName: string;
14
+ deviceType?: string;
15
+ }>;
16
+ infraredRemoteList: Array<{
17
+ deviceId: string;
18
+ deviceName: string;
19
+ remoteType: string;
20
+ }>;
21
+ }
22
+ export declare function loadCache(): DeviceCache | null;
23
+ export declare function getCachedDevice(deviceId: string): CachedDevice | null;
24
+ export declare function updateCacheFromDeviceList(body: DeviceListBodyShape): void;
25
+ export declare function clearCache(): void;
@@ -0,0 +1,74 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import os from 'node:os';
4
+ import { getConfigPath } from '../utils/flags.js';
5
+ function cacheFilePath() {
6
+ const override = getConfigPath();
7
+ const dir = override
8
+ ? path.dirname(path.resolve(override))
9
+ : path.join(os.homedir(), '.switchbot');
10
+ return path.join(dir, 'devices.json');
11
+ }
12
+ export function loadCache() {
13
+ const file = cacheFilePath();
14
+ if (!fs.existsSync(file))
15
+ return null;
16
+ try {
17
+ const raw = fs.readFileSync(file, 'utf-8');
18
+ const cache = JSON.parse(raw);
19
+ if (!cache || typeof cache.devices !== 'object' || cache.devices === null) {
20
+ return null;
21
+ }
22
+ return cache;
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ export function getCachedDevice(deviceId) {
29
+ const cache = loadCache();
30
+ if (!cache)
31
+ return null;
32
+ return cache.devices[deviceId] ?? null;
33
+ }
34
+ export function updateCacheFromDeviceList(body) {
35
+ const devices = {};
36
+ for (const d of body.deviceList) {
37
+ if (!d.deviceId || !d.deviceType)
38
+ continue;
39
+ devices[d.deviceId] = {
40
+ type: d.deviceType,
41
+ name: d.deviceName,
42
+ category: 'physical',
43
+ };
44
+ }
45
+ for (const d of body.infraredRemoteList) {
46
+ if (!d.deviceId)
47
+ continue;
48
+ devices[d.deviceId] = {
49
+ type: d.remoteType,
50
+ name: d.deviceName,
51
+ category: 'ir',
52
+ };
53
+ }
54
+ const cache = {
55
+ lastUpdated: new Date().toISOString(),
56
+ devices,
57
+ };
58
+ try {
59
+ const file = cacheFilePath();
60
+ const dir = path.dirname(file);
61
+ if (!fs.existsSync(dir))
62
+ fs.mkdirSync(dir, { recursive: true });
63
+ fs.writeFileSync(file, JSON.stringify(cache, null, 2), { mode: 0o600 });
64
+ }
65
+ catch {
66
+ // Cache write failures must not break the command that triggered them.
67
+ }
68
+ }
69
+ export function clearCache() {
70
+ const file = cacheFilePath();
71
+ if (fs.existsSync(file))
72
+ fs.unlinkSync(file);
73
+ }
74
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/devices/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AA0BlD,SAAS,aAAa;IACpB,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAC;IACjC,MAAM,GAAG,GAAG,QAAQ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