@switchbot/openapi-cli 2.6.1 → 2.6.2
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/dist/commands/mcp.js +23 -1
- package/dist/commands/scenes.js +11 -0
- package/package.json +1 -1
package/dist/commands/mcp.js
CHANGED
|
@@ -305,6 +305,13 @@ API docs: https://github.com/OpenWonderLabs/SwitchBotAPI`,
|
|
|
305
305
|
effectiveParameter = pv.normalized;
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
|
+
const cmdVal = validateCommand(deviceId, command, stringifiedParam, effectiveType);
|
|
309
|
+
if (!cmdVal.ok) {
|
|
310
|
+
return mcpError('usage', 2, cmdVal.error.message, {
|
|
311
|
+
hint: cmdVal.error.hint,
|
|
312
|
+
context: { validationKind: cmdVal.error.kind },
|
|
313
|
+
});
|
|
314
|
+
}
|
|
308
315
|
const wouldSend = {
|
|
309
316
|
deviceId,
|
|
310
317
|
command,
|
|
@@ -426,7 +433,22 @@ API docs: https://github.com/OpenWonderLabs/SwitchBotAPI`,
|
|
|
426
433
|
},
|
|
427
434
|
}, async ({ sceneId, dryRun }) => {
|
|
428
435
|
if (dryRun) {
|
|
429
|
-
|
|
436
|
+
let scenes = [];
|
|
437
|
+
try {
|
|
438
|
+
scenes = await fetchScenes();
|
|
439
|
+
}
|
|
440
|
+
catch {
|
|
441
|
+
// network failure — degrade gracefully, skip validation
|
|
442
|
+
}
|
|
443
|
+
const found = scenes.find((s) => s.sceneId === sceneId);
|
|
444
|
+
if (scenes.length > 0 && !found) {
|
|
445
|
+
return mcpError('usage', 2, `Scene not found: ${sceneId}`, {
|
|
446
|
+
subKind: 'scene-not-found',
|
|
447
|
+
hint: "Check the sceneId with 'list_scenes' (IDs are case-sensitive).",
|
|
448
|
+
context: { sceneId, candidates: scenes.map((s) => ({ sceneId: s.sceneId, sceneName: s.sceneName })).slice(0, 5) },
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
const wouldSend = { sceneId, sceneName: found?.sceneName ?? null };
|
|
430
452
|
const structured = { ok: true, dryRun: true, wouldSend };
|
|
431
453
|
return {
|
|
432
454
|
content: [{ type: 'text', text: JSON.stringify(structured, null, 2) }],
|
package/dist/commands/scenes.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { printJson, isJsonMode, handleError, StructuredUsageError } from '../utils/output.js';
|
|
2
2
|
import { resolveFormat, resolveFields, renderRows } from '../utils/format.js';
|
|
3
3
|
import { fetchScenes, executeScene } from '../lib/scenes.js';
|
|
4
|
+
import { isDryRun } from '../utils/flags.js';
|
|
4
5
|
export function registerScenesCommand(program) {
|
|
5
6
|
const scenes = program
|
|
6
7
|
.command('scenes')
|
|
@@ -56,6 +57,16 @@ Example:
|
|
|
56
57
|
candidates: sceneList.map((s) => ({ sceneId: s.sceneId, sceneName: s.sceneName })),
|
|
57
58
|
});
|
|
58
59
|
}
|
|
60
|
+
if (isDryRun()) {
|
|
61
|
+
const wouldSend = { method: 'POST', url: `/v1.1/scenes/${sceneId}/execute`, sceneId, sceneName: found.sceneName };
|
|
62
|
+
if (isJsonMode()) {
|
|
63
|
+
printJson({ dryRun: true, wouldSend });
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.log(`[dry-run] Would POST /v1.1/scenes/${sceneId}/execute (${found.sceneName})`);
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
59
70
|
await executeScene(sceneId);
|
|
60
71
|
if (isJsonMode()) {
|
|
61
72
|
printJson({ ok: true, sceneId });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@switchbot/openapi-cli",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "SwitchBot smart home CLI — control devices, run scenes, stream real-time events, and integrate AI agents via MCP. Full API v1.1 coverage.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"switchbot",
|