@coffeerunhobby/mcp-ha-connect 2.2.1 → 2.3.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/.env.example +1 -1
- package/README.md +11 -2
- package/dist/omadaClient/client.d.ts +6 -1
- package/dist/omadaClient/client.js +12 -1
- package/dist/omadaClient/client.js.map +1 -1
- package/dist/omadaClient/diagnose.d.ts +68 -0
- package/dist/omadaClient/diagnose.js +164 -0
- package/dist/omadaClient/diagnose.js.map +1 -0
- package/dist/omadaClient/index.d.ts +6 -0
- package/dist/omadaClient/index.js +15 -0
- package/dist/omadaClient/index.js.map +1 -1
- package/dist/omadaClient/macGroups.d.ts +58 -0
- package/dist/omadaClient/macGroups.js +124 -0
- package/dist/omadaClient/macGroups.js.map +1 -0
- package/dist/tools/infra/actions.d.ts +1 -1
- package/dist/tools/infra/actions.js +1 -1
- package/dist/tools/omada/index.js +6 -0
- package/dist/tools/omada/index.js.map +1 -1
- package/dist/tools/omada/macGroups.d.ts +19 -0
- package/dist/tools/omada/macGroups.js +77 -0
- package/dist/tools/omada/macGroups.js.map +1 -0
- package/dist/tools/omada/namespace.js +8 -0
- package/dist/tools/omada/namespace.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -1
- package/.codex/review-rules.md +0 -16
- package/.dockerignore +0 -8
- package/.gitattributes +0 -30
- package/.github/workflows/ci.yml +0 -193
- package/AGENTS.md +0 -389
- package/Dockerfile +0 -50
- package/docker-compose.yml +0 -23
- package/docs/CHANGELOG.md +0 -341
- package/docs/COVERAGE.md +0 -219
- package/docs/QUICK_START.md +0 -240
- package/eslint.config.js +0 -33
- package/n8n/ai-agent-safety-monitor.json +0 -355
- package/openapi.json +0 -1259
- package/scripts/check-version-sync.mjs +0 -69
- package/scripts/generate-jwt.ts +0 -121
- package/src/config.ts +0 -440
- package/src/haClient/automations.ts +0 -261
- package/src/haClient/calendars.ts +0 -94
- package/src/haClient/config.ts +0 -52
- package/src/haClient/devices.ts +0 -653
- package/src/haClient/entities.ts +0 -128
- package/src/haClient/events.ts +0 -689
- package/src/haClient/history.ts +0 -73
- package/src/haClient/index.ts +0 -336
- package/src/haClient/request.ts +0 -142
- package/src/haClient/services.ts +0 -45
- package/src/haClient/states.ts +0 -60
- package/src/haClient/updates.ts +0 -58
- package/src/haClient/wsCommand.ts +0 -44
- package/src/index.ts +0 -164
- package/src/localAI/index.ts +0 -88
- package/src/localAI/prompts.ts +0 -50
- package/src/localAI/providers/base.ts +0 -120
- package/src/localAI/providers/ollama.ts +0 -78
- package/src/localAI/providers/openai.ts +0 -86
- package/src/localAI/types.ts +0 -67
- package/src/omadaClient/auth.ts +0 -178
- package/src/omadaClient/client.ts +0 -337
- package/src/omadaClient/device.ts +0 -118
- package/src/omadaClient/index.ts +0 -310
- package/src/omadaClient/network.ts +0 -284
- package/src/omadaClient/request.ts +0 -365
- package/src/omadaClient/security.ts +0 -51
- package/src/omadaClient/site.ts +0 -344
- package/src/ownerQuestions/service.ts +0 -536
- package/src/permissions/index.ts +0 -143
- package/src/resources/index.ts +0 -213
- package/src/server/auth.ts +0 -175
- package/src/server/chatFace.ts +0 -789
- package/src/server/chatSlice.ts +0 -57
- package/src/server/common.ts +0 -170
- package/src/server/eventSubscription.ts +0 -343
- package/src/server/http.ts +0 -626
- package/src/server/instructions.ts +0 -97
- package/src/server/rateLimiter.ts +0 -227
- package/src/server/stdio.ts +0 -41
- package/src/server/stream.ts +0 -205
- package/src/tools/ai/analyzeSensors.ts +0 -33
- package/src/tools/ai/index.ts +0 -20
- package/src/tools/common.ts +0 -442
- package/src/tools/homeassistant/askOwner.ts +0 -133
- package/src/tools/homeassistant/automationControls.ts +0 -66
- package/src/tools/homeassistant/calendar.ts +0 -97
- package/src/tools/homeassistant/callService.ts +0 -25
- package/src/tools/homeassistant/controlClimate.ts +0 -68
- package/src/tools/homeassistant/controlCover.ts +0 -48
- package/src/tools/homeassistant/controlFan.ts +0 -44
- package/src/tools/homeassistant/controlLight.ts +0 -38
- package/src/tools/homeassistant/controlMediaPlayer.ts +0 -50
- package/src/tools/homeassistant/createAutomation.ts +0 -35
- package/src/tools/homeassistant/deleteAutomation.ts +0 -24
- package/src/tools/homeassistant/entityAction.ts +0 -35
- package/src/tools/homeassistant/entityGuard.ts +0 -28
- package/src/tools/homeassistant/getAllSensors.ts +0 -46
- package/src/tools/homeassistant/getAutomationTrace.ts +0 -30
- package/src/tools/homeassistant/getDomainSummary.ts +0 -29
- package/src/tools/homeassistant/getEntitiesByDomain.ts +0 -56
- package/src/tools/homeassistant/getHistory.ts +0 -24
- package/src/tools/homeassistant/getState.ts +0 -24
- package/src/tools/homeassistant/getStates.ts +0 -46
- package/src/tools/homeassistant/getVersion.ts +0 -21
- package/src/tools/homeassistant/index.ts +0 -121
- package/src/tools/homeassistant/listAutomations.ts +0 -35
- package/src/tools/homeassistant/listEntities.ts +0 -44
- package/src/tools/homeassistant/listPersons.ts +0 -46
- package/src/tools/homeassistant/sceneAndScript.ts +0 -53
- package/src/tools/homeassistant/searchEntities.ts +0 -58
- package/src/tools/homeassistant/sendNotification.ts +0 -179
- package/src/tools/homeassistant/systemTools.ts +0 -52
- package/src/tools/homeassistant/triggerAutomation.ts +0 -24
- package/src/tools/index.ts +0 -78
- package/src/tools/infra/actions.ts +0 -95
- package/src/tools/infra/index.ts +0 -138
- package/src/tools/omada/blockClient.ts +0 -28
- package/src/tools/omada/cyclePoePort.ts +0 -32
- package/src/tools/omada/deleteClient.ts +0 -27
- package/src/tools/omada/disableClientRateLimit.ts +0 -23
- package/src/tools/omada/getClient.ts +0 -14
- package/src/tools/omada/getDevice.ts +0 -14
- package/src/tools/omada/getFirewallSetting.ts +0 -14
- package/src/tools/omada/getInternetInfo.ts +0 -14
- package/src/tools/omada/getLanNetworkList.ts +0 -14
- package/src/tools/omada/getLanProfileList.ts +0 -14
- package/src/tools/omada/getPortForwardingStatus.ts +0 -26
- package/src/tools/omada/getRateLimitProfiles.ts +0 -14
- package/src/tools/omada/getSiteNtpStatus.ts +0 -14
- package/src/tools/omada/getSsidDetail.ts +0 -22
- package/src/tools/omada/getSsidList.ts +0 -21
- package/src/tools/omada/getSwitchStackDetail.ts +0 -14
- package/src/tools/omada/getThreatList.ts +0 -42
- package/src/tools/omada/getWlanGroupList.ts +0 -14
- package/src/tools/omada/graph.ts +0 -187
- package/src/tools/omada/index.ts +0 -153
- package/src/tools/omada/listBlockedClients.ts +0 -17
- package/src/tools/omada/listClients.ts +0 -14
- package/src/tools/omada/listClientsActivity.ts +0 -25
- package/src/tools/omada/listClientsPastConnections.ts +0 -44
- package/src/tools/omada/listDevices.ts +0 -14
- package/src/tools/omada/listDevicesStats.ts +0 -41
- package/src/tools/omada/listMostActiveClients.ts +0 -14
- package/src/tools/omada/listSites.ts +0 -18
- package/src/tools/omada/namespace.ts +0 -1164
- package/src/tools/omada/searchDevices.ts +0 -20
- package/src/tools/omada/setClientRateLimit.ts +0 -26
- package/src/tools/omada/setClientRateLimitProfile.ts +0 -25
- package/src/tools/omada/setSiteNtpServers.ts +0 -36
- package/src/tools/omada/setSsidEnabled.ts +0 -38
- package/src/tools/omada/unblockClient.ts +0 -26
- package/src/tools/types.ts +0 -11
- package/src/tools/utils/pagination-schema.ts +0 -27
- package/src/types/ai/index.ts +0 -11
- package/src/types/ai/types.ts +0 -67
- package/src/types/homeassistant/automations.ts +0 -43
- package/src/types/homeassistant/calendars.ts +0 -26
- package/src/types/homeassistant/config.ts +0 -14
- package/src/types/homeassistant/entities.ts +0 -14
- package/src/types/homeassistant/errors.ts +0 -33
- package/src/types/homeassistant/haConfig.ts +0 -7
- package/src/types/homeassistant/history.ts +0 -13
- package/src/types/homeassistant/index.ts +0 -46
- package/src/types/homeassistant/request.ts +0 -6
- package/src/types/homeassistant/serviceCall.ts +0 -18
- package/src/types/homeassistant/states.ts +0 -58
- package/src/types/homeassistant/updates.ts +0 -28
- package/src/types/index.ts +0 -12
- package/src/types/omada/activeClientInfo.ts +0 -17
- package/src/types/omada/clientActivity.ts +0 -32
- package/src/types/omada/clientBlockStatus.ts +0 -11
- package/src/types/omada/clientPastConnection.ts +0 -82
- package/src/types/omada/index.ts +0 -14
- package/src/types/omada/omadaApiResponse.ts +0 -5
- package/src/types/omada/omadaClientInfo.ts +0 -11
- package/src/types/omada/omadaDeviceInfo.ts +0 -11
- package/src/types/omada/omadaDeviceStats.ts +0 -31
- package/src/types/omada/omadaSiteSummary.ts +0 -5
- package/src/types/omada/oswStackDetail.ts +0 -11
- package/src/types/omada/paginatedResult.ts +0 -6
- package/src/types/omada/rateLimitProfile.ts +0 -58
- package/src/types/omada/threatInfo.ts +0 -38
- package/src/types/omada/tokenResult.ts +0 -6
- package/src/types.ts +0 -2
- package/src/utils/config-validations.ts +0 -68
- package/src/utils/jwt.ts +0 -112
- package/src/utils/logger.ts +0 -121
- package/src/utils/plainText.ts +0 -48
- package/src/utils/redact.ts +0 -59
- package/src/utils/sanitizeError.ts +0 -18
- package/src/utils/tlsDispatcher.ts +0 -69
- package/src/version.ts +0 -5
- package/tests/bdd/automation-creation.spec.ts +0 -214
- package/tests/bdd/automation-management.spec.ts +0 -267
- package/tests/bdd/calendar.spec.ts +0 -190
- package/tests/bdd/configuration.spec.ts +0 -283
- package/tests/bdd/device-control.spec.ts +0 -344
- package/tests/bdd/entity-listing.spec.ts +0 -208
- package/tests/bdd/entity-search.spec.ts +0 -183
- package/tests/bdd/history-retrieval.spec.ts +0 -195
- package/tests/bdd/notifications.spec.ts +0 -238
- package/tests/bdd/service-calls.spec.ts +0 -144
- package/tests/bdd/state-retrieval.spec.ts +0 -204
- package/tests/bench/hotpaths.bench.ts +0 -68
- package/tests/config.test.ts +0 -355
- package/tests/features/automation-creation.feature +0 -36
- package/tests/features/automation-management.feature +0 -54
- package/tests/features/calendar.feature +0 -37
- package/tests/features/configuration.feature +0 -70
- package/tests/features/device-control.feature +0 -100
- package/tests/features/entity-listing.feature +0 -51
- package/tests/features/entity-search.feature +0 -44
- package/tests/features/history-retrieval.feature +0 -38
- package/tests/features/notifications.feature +0 -37
- package/tests/features/service-calls.feature +0 -35
- package/tests/features/state-retrieval.feature +0 -37
- package/tests/fixtures/openapi-default-slice.json +0 -290
- package/tests/haClient/automationTrace.test.ts +0 -59
- package/tests/haClient/automations.test.ts +0 -149
- package/tests/haClient/config.test.ts +0 -117
- package/tests/haClient/entities.test.ts +0 -188
- package/tests/haClient/events.test.ts +0 -455
- package/tests/haClient/eventsTls.test.ts +0 -52
- package/tests/haClient/history.test.ts +0 -228
- package/tests/haClient/index.test.ts +0 -243
- package/tests/haClient/request.test.ts +0 -217
- package/tests/haClient/services.test.ts +0 -120
- package/tests/haClient/states.test.ts +0 -119
- package/tests/haClient/updates.test.ts +0 -193
- package/tests/index.test.ts +0 -160
- package/tests/integration/homeassistant.test.ts +0 -144
- package/tests/integration/omada.test.ts +0 -167
- package/tests/integration/server.test.ts +0 -151
- package/tests/localAI/index.test.ts +0 -177
- package/tests/localAI/ollama.test.ts +0 -187
- package/tests/localAI/openai.test.ts +0 -257
- package/tests/omadaClient/actions.test.ts +0 -161
- package/tests/omadaClient/clientBlocks.test.ts +0 -170
- package/tests/omadaClient/ntp.test.ts +0 -381
- package/tests/omadaClient/site.test.ts +0 -37
- package/tests/ownerQuestions/service.test.ts +0 -499
- package/tests/ownerQuestions/tools.test.ts +0 -186
- package/tests/permissions/index.test.ts +0 -217
- package/tests/resources/index.test.ts +0 -288
- package/tests/scripts/generateJwt.test.ts +0 -44
- package/tests/security/accessControl.test.ts +0 -223
- package/tests/security/authentication.test.ts +0 -117
- package/tests/security/configuration.test.ts +0 -170
- package/tests/security/cryptoTransport.test.ts +0 -172
- package/tests/security/dependencies.test.ts +0 -152
- package/tests/security/injection.test.ts +0 -117
- package/tests/security/insecureDesign.test.ts +0 -121
- package/tests/security/logging.test.ts +0 -131
- package/tests/security/resourceConsumption.test.ts +0 -142
- package/tests/server/auth.test.ts +0 -249
- package/tests/server/chatFace.test.ts +0 -320
- package/tests/server/common.test.ts +0 -84
- package/tests/server/http.test.ts +0 -561
- package/tests/server/instructions.test.ts +0 -152
- package/tests/server/memoizeJsonSchema.test.ts +0 -71
- package/tests/server/stdio.test.ts +0 -99
- package/tests/server/stream.test.ts +0 -285
- package/tests/server/toolVisibility.http.test.ts +0 -111
- package/tests/server/toolVisibility.test.ts +0 -129
- package/tests/tools/ai/analyzeSensors.test.ts +0 -227
- package/tests/tools/common.test.ts +0 -123
- package/tests/tools/homeassistant/handlers.test.ts +0 -872
- package/tests/tools/infra/invokeAction.test.ts +0 -280
- package/tests/tools/omada/graph.test.ts +0 -385
- package/tests/tools/omada/handlers.test.ts +0 -897
- package/tests/tools/omada/namespace.test.ts +0 -483
- package/tests/tools/registry.test.ts +0 -168
- package/tests/utils/config-validations.test.ts +0 -352
- package/tests/utils/jwt.test.ts +0 -115
- package/tests/utils/logger.test.ts +0 -327
- package/tests/utils/redact.test.ts +0 -105
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -38
|
@@ -1,872 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for HomeAssistant tool handlers
|
|
3
|
-
* Tests the handler logic by invoking registered handlers with mocked clients
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
-
|
|
8
|
-
// Import registration functions
|
|
9
|
-
import { registerGetStatesTool } from '../../../src/tools/homeassistant/getStates.js';
|
|
10
|
-
import { registerGetStateTool } from '../../../src/tools/homeassistant/getState.js';
|
|
11
|
-
import { registerControlLightTool } from '../../../src/tools/homeassistant/controlLight.js';
|
|
12
|
-
import { registerControlClimateTool } from '../../../src/tools/homeassistant/controlClimate.js';
|
|
13
|
-
import { registerControlFanTool } from '../../../src/tools/homeassistant/controlFan.js';
|
|
14
|
-
import { registerControlCoverTool } from '../../../src/tools/homeassistant/controlCover.js';
|
|
15
|
-
import { registerControlMediaPlayerTool } from '../../../src/tools/homeassistant/controlMediaPlayer.js';
|
|
16
|
-
import { registerGetEntitiesByDomainTool } from '../../../src/tools/homeassistant/getEntitiesByDomain.js';
|
|
17
|
-
import { registerSearchEntitiesTool } from '../../../src/tools/homeassistant/searchEntities.js';
|
|
18
|
-
import { registerGetAllSensorsTool } from '../../../src/tools/homeassistant/getAllSensors.js';
|
|
19
|
-
import { registerGetDomainSummaryTool } from '../../../src/tools/homeassistant/getDomainSummary.js';
|
|
20
|
-
import { registerListEntitiesTool } from '../../../src/tools/homeassistant/listEntities.js';
|
|
21
|
-
import { registerGetHistoryTool } from '../../../src/tools/homeassistant/getHistory.js';
|
|
22
|
-
import { registerGetVersionTool } from '../../../src/tools/homeassistant/getVersion.js';
|
|
23
|
-
import { registerCallServiceTool } from '../../../src/tools/homeassistant/callService.js';
|
|
24
|
-
import { registerEntityActionTool } from '../../../src/tools/homeassistant/entityAction.js';
|
|
25
|
-
import { registerListAutomationsTool } from '../../../src/tools/homeassistant/listAutomations.js';
|
|
26
|
-
import { registerTriggerAutomationTool } from '../../../src/tools/homeassistant/triggerAutomation.js';
|
|
27
|
-
import { registerCreateAutomationTool } from '../../../src/tools/homeassistant/createAutomation.js';
|
|
28
|
-
import { registerDeleteAutomationTool } from '../../../src/tools/homeassistant/deleteAutomation.js';
|
|
29
|
-
import { registerGetAutomationTraceTool } from '../../../src/tools/homeassistant/getAutomationTrace.js';
|
|
30
|
-
import {
|
|
31
|
-
registerEnableAutomationTool,
|
|
32
|
-
registerDisableAutomationTool,
|
|
33
|
-
registerToggleAutomationTool,
|
|
34
|
-
registerReloadAutomationsTool
|
|
35
|
-
} from '../../../src/tools/homeassistant/automationControls.js';
|
|
36
|
-
import { registerActivateSceneTool, registerRunScriptTool } from '../../../src/tools/homeassistant/sceneAndScript.js';
|
|
37
|
-
import { registerSendNotificationTool, registerListNotificationTargetsTool } from '../../../src/tools/homeassistant/sendNotification.js';
|
|
38
|
-
import { registerListCalendarsTool, registerGetCalendarEventsTool } from '../../../src/tools/homeassistant/calendar.js';
|
|
39
|
-
import {
|
|
40
|
-
registerRestartHomeAssistantTool,
|
|
41
|
-
registerGetSystemLogTool,
|
|
42
|
-
registerCheckUpdatesTool
|
|
43
|
-
} from '../../../src/tools/homeassistant/systemTools.js';
|
|
44
|
-
import { registerListPersonsTool } from '../../../src/tools/homeassistant/listPersons.js';
|
|
45
|
-
|
|
46
|
-
// Mock HaClient
|
|
47
|
-
function createMockClient() {
|
|
48
|
-
return {
|
|
49
|
-
getStates: vi.fn(),
|
|
50
|
-
getState: vi.fn(),
|
|
51
|
-
callService: vi.fn(),
|
|
52
|
-
getEntitiesByDomain: vi.fn(),
|
|
53
|
-
searchEntities: vi.fn(),
|
|
54
|
-
getAllSensors: vi.fn(),
|
|
55
|
-
getDomainSummary: vi.fn(),
|
|
56
|
-
listEntities: vi.fn(),
|
|
57
|
-
getHistory: vi.fn(),
|
|
58
|
-
getVersion: vi.fn(),
|
|
59
|
-
getAutomations: vi.fn(),
|
|
60
|
-
getAutomation: vi.fn(),
|
|
61
|
-
triggerAutomation: vi.fn(),
|
|
62
|
-
createAutomation: vi.fn(),
|
|
63
|
-
deleteAutomation: vi.fn(),
|
|
64
|
-
getAutomationTrace: vi.fn(),
|
|
65
|
-
enableAutomation: vi.fn(),
|
|
66
|
-
disableAutomation: vi.fn(),
|
|
67
|
-
toggleAutomation: vi.fn(),
|
|
68
|
-
reloadAutomations: vi.fn(),
|
|
69
|
-
getCalendars: vi.fn(),
|
|
70
|
-
getCalendarEvents: vi.fn(),
|
|
71
|
-
getAllCalendarEvents: vi.fn(),
|
|
72
|
-
restartServer: vi.fn(),
|
|
73
|
-
getSystemLog: vi.fn(),
|
|
74
|
-
getAvailableUpdates: vi.fn(),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Helper to parse JSON result
|
|
79
|
-
function parseResult(result: { content: { text: string }[] }): unknown {
|
|
80
|
-
return JSON.parse(result.content[0].text);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Mock server that captures registered handlers
|
|
84
|
-
function createMockServer() {
|
|
85
|
-
const handlers: Map<string, (...args: unknown[]) => unknown> = new Map();
|
|
86
|
-
return {
|
|
87
|
-
registerTool: vi.fn((name: string, _config: any, handler: (...args: unknown[]) => unknown) => {
|
|
88
|
-
handlers.set(name, handler);
|
|
89
|
-
}),
|
|
90
|
-
getHandler: (name: string) => handlers.get(name),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Mock extra object required by wrapToolHandler
|
|
95
|
-
const mockExtra = {
|
|
96
|
-
sessionId: 'test-session',
|
|
97
|
-
http: { authInfo: { extra: { permissions: 0xFF } } }, // All permissions
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
describe('HomeAssistant Tool Handlers', () => {
|
|
101
|
-
let server: ReturnType<typeof createMockServer>;
|
|
102
|
-
let mockClient: ReturnType<typeof createMockClient>;
|
|
103
|
-
|
|
104
|
-
beforeEach(() => {
|
|
105
|
-
vi.clearAllMocks();
|
|
106
|
-
server = createMockServer();
|
|
107
|
-
mockClient = createMockClient();
|
|
108
|
-
// Default: the targeted entity exists. Control tools now check existence first
|
|
109
|
-
// (entityGuard); tests that need "not found" override this explicitly.
|
|
110
|
-
mockClient.getState.mockImplementation(async (entityId: string) => ({ entity_id: entityId, state: 'on', attributes: {} }));
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('getStates', () => {
|
|
114
|
-
it('should return all entity states', async () => {
|
|
115
|
-
const states = [
|
|
116
|
-
{ entity_id: 'light.living_room', state: 'on', attributes: { friendly_name: 'Living Room Light' }, last_changed: '2026-01-01T00:00:00Z' },
|
|
117
|
-
{ entity_id: 'sensor.temperature', state: '22.5', attributes: { friendly_name: 'Temperature', unit_of_measurement: '°C' }, last_changed: '2026-01-01T00:00:00Z' },
|
|
118
|
-
];
|
|
119
|
-
mockClient.getStates.mockResolvedValue(states);
|
|
120
|
-
registerGetStatesTool(server as any, mockClient as any);
|
|
121
|
-
|
|
122
|
-
const handler = server.getHandler('getStates')!;
|
|
123
|
-
// Pass pagination defaults explicitly (MCP SDK applies Zod defaults in production)
|
|
124
|
-
const result = await handler({ page: 1, pageSize: 50, includeAttributes: false }, mockExtra);
|
|
125
|
-
|
|
126
|
-
expect(mockClient.getStates).toHaveBeenCalled();
|
|
127
|
-
const parsed = parseResult(result) as { totalCount: number; page: number; pageSize: number };
|
|
128
|
-
expect(parsed.totalCount).toBe(2);
|
|
129
|
-
expect(parsed.page).toBe(1);
|
|
130
|
-
expect(parsed.pageSize).toBe(50);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('getState', () => {
|
|
135
|
-
it('should return state for existing entity', async () => {
|
|
136
|
-
const state = { entity_id: 'light.living_room', state: 'on', attributes: { brightness: 255 } };
|
|
137
|
-
mockClient.getState.mockResolvedValue(state);
|
|
138
|
-
registerGetStateTool(server as any, mockClient as any);
|
|
139
|
-
|
|
140
|
-
const handler = server.getHandler('getState')!;
|
|
141
|
-
const result = await handler({ entity_id: 'light.living_room' }, mockExtra);
|
|
142
|
-
|
|
143
|
-
expect(mockClient.getState).toHaveBeenCalledWith('light.living_room');
|
|
144
|
-
expect(result.content[0].text).toContain('light.living_room');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('should return error for non-existent entity', async () => {
|
|
148
|
-
mockClient.getState.mockResolvedValue(null);
|
|
149
|
-
registerGetStateTool(server as any, mockClient as any);
|
|
150
|
-
|
|
151
|
-
const handler = server.getHandler('getState')!;
|
|
152
|
-
const result = await handler({ entity_id: 'light.nonexistent' }, mockExtra);
|
|
153
|
-
|
|
154
|
-
expect(result.isError).toBe(true);
|
|
155
|
-
expect(result.content[0].text).toContain('Entity not found');
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
describe('controlLight', () => {
|
|
160
|
-
it('should turn on light with brightness', async () => {
|
|
161
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
162
|
-
registerControlLightTool(server as any, mockClient as any);
|
|
163
|
-
|
|
164
|
-
const handler = server.getHandler('controlLight')!;
|
|
165
|
-
const result = await handler({
|
|
166
|
-
entity_id: 'light.living_room',
|
|
167
|
-
action: 'turn_on',
|
|
168
|
-
brightness_pct: 75,
|
|
169
|
-
}, mockExtra);
|
|
170
|
-
|
|
171
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
172
|
-
domain: 'light',
|
|
173
|
-
service: 'turn_on',
|
|
174
|
-
target: { entity_id: 'light.living_room' },
|
|
175
|
-
service_data: { brightness_pct: 75 },
|
|
176
|
-
});
|
|
177
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
178
|
-
expect(parsed.success).toBe(true);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should turn off light', async () => {
|
|
182
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
183
|
-
registerControlLightTool(server as any, mockClient as any);
|
|
184
|
-
|
|
185
|
-
const handler = server.getHandler('controlLight')!;
|
|
186
|
-
await handler({ entity_id: 'light.living_room', action: 'turn_off' }, mockExtra);
|
|
187
|
-
|
|
188
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
189
|
-
domain: 'light',
|
|
190
|
-
service: 'turn_off',
|
|
191
|
-
target: { entity_id: 'light.living_room' },
|
|
192
|
-
service_data: undefined,
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('should set RGB color', async () => {
|
|
197
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
198
|
-
registerControlLightTool(server as any, mockClient as any);
|
|
199
|
-
|
|
200
|
-
const handler = server.getHandler('controlLight')!;
|
|
201
|
-
await handler({
|
|
202
|
-
entity_id: 'light.living_room',
|
|
203
|
-
action: 'turn_on',
|
|
204
|
-
rgb_color: [255, 0, 0],
|
|
205
|
-
}, mockExtra);
|
|
206
|
-
|
|
207
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
208
|
-
domain: 'light',
|
|
209
|
-
service: 'turn_on',
|
|
210
|
-
target: { entity_id: 'light.living_room' },
|
|
211
|
-
service_data: { rgb_color: [255, 0, 0] },
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
describe('controlClimate', () => {
|
|
217
|
-
it('should set HVAC mode', async () => {
|
|
218
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
219
|
-
registerControlClimateTool(server as any, mockClient as any);
|
|
220
|
-
|
|
221
|
-
const handler = server.getHandler('controlClimate')!;
|
|
222
|
-
const result = await handler({ entity_id: 'climate.thermostat', hvac_mode: 'heat' }, mockExtra);
|
|
223
|
-
|
|
224
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
225
|
-
domain: 'climate',
|
|
226
|
-
service: 'set_hvac_mode',
|
|
227
|
-
target: { entity_id: 'climate.thermostat' },
|
|
228
|
-
service_data: { hvac_mode: 'heat' },
|
|
229
|
-
});
|
|
230
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
231
|
-
expect(parsed.success).toBe(true);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should set temperature', async () => {
|
|
235
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
236
|
-
registerControlClimateTool(server as any, mockClient as any);
|
|
237
|
-
|
|
238
|
-
const handler = server.getHandler('controlClimate')!;
|
|
239
|
-
await handler({ entity_id: 'climate.thermostat', temperature: 22 }, mockExtra);
|
|
240
|
-
|
|
241
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
242
|
-
domain: 'climate',
|
|
243
|
-
service: 'set_temperature',
|
|
244
|
-
target: { entity_id: 'climate.thermostat' },
|
|
245
|
-
service_data: { temperature: 22 },
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it('should set multiple climate settings', async () => {
|
|
250
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
251
|
-
registerControlClimateTool(server as any, mockClient as any);
|
|
252
|
-
|
|
253
|
-
const handler = server.getHandler('controlClimate')!;
|
|
254
|
-
const result = await handler({
|
|
255
|
-
entity_id: 'climate.thermostat',
|
|
256
|
-
hvac_mode: 'heat',
|
|
257
|
-
temperature: 22,
|
|
258
|
-
fan_mode: 'low',
|
|
259
|
-
preset_mode: 'away',
|
|
260
|
-
}, mockExtra);
|
|
261
|
-
|
|
262
|
-
expect(mockClient.callService).toHaveBeenCalledTimes(4);
|
|
263
|
-
const parsed = JSON.parse(result.content[0].text);
|
|
264
|
-
expect(parsed.actions.length).toBe(4);
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
describe('controlFan', () => {
|
|
269
|
-
it('should turn on fan', async () => {
|
|
270
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
271
|
-
registerControlFanTool(server as any, mockClient as any);
|
|
272
|
-
|
|
273
|
-
const handler = server.getHandler('controlFan')!;
|
|
274
|
-
const result = await handler({ entity_id: 'fan.bedroom', action: 'turn_on' }, mockExtra);
|
|
275
|
-
|
|
276
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
277
|
-
domain: 'fan',
|
|
278
|
-
service: 'turn_on',
|
|
279
|
-
target: { entity_id: 'fan.bedroom' },
|
|
280
|
-
service_data: undefined,
|
|
281
|
-
});
|
|
282
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
283
|
-
expect(parsed.success).toBe(true);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it('should set fan speed', async () => {
|
|
287
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
288
|
-
registerControlFanTool(server as any, mockClient as any);
|
|
289
|
-
|
|
290
|
-
const handler = server.getHandler('controlFan')!;
|
|
291
|
-
const result = await handler({ entity_id: 'fan.bedroom', action: 'set_speed', percentage: 50 }, mockExtra);
|
|
292
|
-
|
|
293
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
294
|
-
domain: 'fan',
|
|
295
|
-
service: 'set_percentage',
|
|
296
|
-
target: { entity_id: 'fan.bedroom' },
|
|
297
|
-
service_data: { percentage: 50 },
|
|
298
|
-
});
|
|
299
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
300
|
-
expect(parsed.success).toBe(true);
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
describe('controlCover', () => {
|
|
305
|
-
it('should open cover', async () => {
|
|
306
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
307
|
-
registerControlCoverTool(server as any, mockClient as any);
|
|
308
|
-
|
|
309
|
-
const handler = server.getHandler('controlCover')!;
|
|
310
|
-
const result = await handler({ entity_id: 'cover.garage', action: 'open_cover' }, mockExtra);
|
|
311
|
-
|
|
312
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
313
|
-
domain: 'cover',
|
|
314
|
-
service: 'open_cover',
|
|
315
|
-
target: { entity_id: 'cover.garage' },
|
|
316
|
-
service_data: undefined,
|
|
317
|
-
});
|
|
318
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
319
|
-
expect(parsed.success).toBe(true);
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it('should set cover position', async () => {
|
|
323
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
324
|
-
registerControlCoverTool(server as any, mockClient as any);
|
|
325
|
-
|
|
326
|
-
const handler = server.getHandler('controlCover')!;
|
|
327
|
-
const result = await handler({ entity_id: 'cover.blinds', action: 'set_position', position: 50 }, mockExtra);
|
|
328
|
-
|
|
329
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
330
|
-
domain: 'cover',
|
|
331
|
-
service: 'set_cover_position',
|
|
332
|
-
target: { entity_id: 'cover.blinds' },
|
|
333
|
-
service_data: { position: 50 },
|
|
334
|
-
});
|
|
335
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
336
|
-
expect(parsed.success).toBe(true);
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
describe('controlMediaPlayer', () => {
|
|
341
|
-
it('should play media', async () => {
|
|
342
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
343
|
-
registerControlMediaPlayerTool(server as any, mockClient as any);
|
|
344
|
-
|
|
345
|
-
const handler = server.getHandler('controlMediaPlayer')!;
|
|
346
|
-
await handler({ entity_id: 'media_player.tv', action: 'media_play' }, mockExtra);
|
|
347
|
-
|
|
348
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
349
|
-
domain: 'media_player',
|
|
350
|
-
service: 'media_play',
|
|
351
|
-
target: { entity_id: 'media_player.tv' },
|
|
352
|
-
service_data: undefined,
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
it('should set volume', async () => {
|
|
357
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
358
|
-
registerControlMediaPlayerTool(server as any, mockClient as any);
|
|
359
|
-
|
|
360
|
-
const handler = server.getHandler('controlMediaPlayer')!;
|
|
361
|
-
await handler({ entity_id: 'media_player.tv', action: 'volume_set', volume_level: 0.5 }, mockExtra);
|
|
362
|
-
|
|
363
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
364
|
-
domain: 'media_player',
|
|
365
|
-
service: 'volume_set',
|
|
366
|
-
target: { entity_id: 'media_player.tv' },
|
|
367
|
-
service_data: { volume_level: 0.5 },
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
describe('query tools', () => {
|
|
373
|
-
it('getEntitiesByDomain should return entities', async () => {
|
|
374
|
-
mockClient.getEntitiesByDomain.mockResolvedValue([{ entity_id: 'light.test', state: 'on', attributes: {}, last_changed: '2026-01-01' }]);
|
|
375
|
-
registerGetEntitiesByDomainTool(server as any, mockClient as any);
|
|
376
|
-
|
|
377
|
-
const handler = server.getHandler('getEntitiesByDomain')!;
|
|
378
|
-
// Pass pagination defaults explicitly (MCP SDK applies Zod defaults in production)
|
|
379
|
-
const result = await handler({ domain: 'light', page: 1, pageSize: 50, includeAttributes: false }, mockExtra);
|
|
380
|
-
|
|
381
|
-
expect(mockClient.getEntitiesByDomain).toHaveBeenCalledWith('light');
|
|
382
|
-
const parsed = parseResult(result) as { totalCount: number; page: number };
|
|
383
|
-
expect(parsed.totalCount).toBe(1);
|
|
384
|
-
expect(parsed.page).toBe(1);
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it('searchEntities should search entities', async () => {
|
|
388
|
-
mockClient.searchEntities.mockResolvedValue([{ entity_id: 'light.living_room', state: 'on', attributes: { friendly_name: 'Living Room' }, last_changed: '2026-01-01' }]);
|
|
389
|
-
registerSearchEntitiesTool(server as any, mockClient as any);
|
|
390
|
-
|
|
391
|
-
const handler = server.getHandler('searchEntities')!;
|
|
392
|
-
// Pass pagination defaults explicitly (MCP SDK applies Zod defaults in production)
|
|
393
|
-
const result = await handler({ query: 'living', page: 1, pageSize: 50, includeAttributes: false }, mockExtra);
|
|
394
|
-
|
|
395
|
-
expect(mockClient.searchEntities).toHaveBeenCalledWith('living');
|
|
396
|
-
const parsed = parseResult(result) as { totalCount: number; entities: Array<{ entity_id: string }> };
|
|
397
|
-
expect(parsed.totalCount).toBe(1);
|
|
398
|
-
expect(parsed.entities[0].entity_id).toBe('light.living_room');
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
it('getAllSensors should return sensors', async () => {
|
|
402
|
-
const sensors = [{ entity_id: 'sensor.temp', state: '22', attributes: {}, last_changed: '2026-01-01' }];
|
|
403
|
-
mockClient.getAllSensors.mockResolvedValue(sensors);
|
|
404
|
-
registerGetAllSensorsTool(server as any, mockClient as any);
|
|
405
|
-
|
|
406
|
-
const handler = server.getHandler('getAllSensors')!;
|
|
407
|
-
// Pass pagination defaults explicitly (MCP SDK applies Zod defaults in production)
|
|
408
|
-
const result = await handler({ page: 1, pageSize: 50, includeAttributes: false }, mockExtra);
|
|
409
|
-
|
|
410
|
-
expect(mockClient.getAllSensors).toHaveBeenCalled();
|
|
411
|
-
const parsed = parseResult(result) as { totalCount: number; page: number };
|
|
412
|
-
expect(parsed.totalCount).toBe(1);
|
|
413
|
-
expect(parsed.page).toBe(1);
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
it('getDomainSummary should return summary', async () => {
|
|
417
|
-
mockClient.getDomainSummary.mockResolvedValue({ total: 5, on: 3, off: 2 });
|
|
418
|
-
registerGetDomainSummaryTool(server as any, mockClient as any);
|
|
419
|
-
|
|
420
|
-
const handler = server.getHandler('getDomainSummary')!;
|
|
421
|
-
const result = await handler({ domain: 'light' }, mockExtra);
|
|
422
|
-
|
|
423
|
-
expect(mockClient.getDomainSummary).toHaveBeenCalledWith('light');
|
|
424
|
-
const parsed = parseResult(result) as { total: number };
|
|
425
|
-
expect(parsed.total).toBe(5);
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it('listEntities should list entities', async () => {
|
|
429
|
-
mockClient.listEntities.mockResolvedValue([{ entity_id: 'light.test', state: 'on', attributes: {}, last_changed: '2026-01-01' }]);
|
|
430
|
-
registerListEntitiesTool(server as any, mockClient as any);
|
|
431
|
-
|
|
432
|
-
const handler = server.getHandler('listEntities')!;
|
|
433
|
-
// Pass defaults explicitly (MCP SDK applies Zod defaults in production)
|
|
434
|
-
const result = await handler({ domain: 'light', state: 'on', limit: 50, includeAttributes: false }, mockExtra);
|
|
435
|
-
|
|
436
|
-
expect(mockClient.listEntities).toHaveBeenCalledWith({ domain: 'light', state: 'on', limit: 50 });
|
|
437
|
-
expect(result.content[0].text).toContain('light.test');
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
it('getHistory should return history', async () => {
|
|
441
|
-
const history = { entity_id: 'light.test', count: 1, history: [{ state: 'on', last_changed: '2026-01-17T10:00:00Z' }] };
|
|
442
|
-
mockClient.getHistory.mockResolvedValue(history);
|
|
443
|
-
registerGetHistoryTool(server as any, mockClient as any);
|
|
444
|
-
|
|
445
|
-
const handler = server.getHandler('getHistory')!;
|
|
446
|
-
const result = await handler({ entity_id: 'light.test', hours: 24 }, mockExtra);
|
|
447
|
-
|
|
448
|
-
expect(mockClient.getHistory).toHaveBeenCalledWith('light.test', 24);
|
|
449
|
-
const parsed = parseResult(result) as { count: number };
|
|
450
|
-
expect(parsed.count).toBe(1);
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
it('getVersion should return version', async () => {
|
|
454
|
-
mockClient.getVersion.mockResolvedValue({ version: '2026.1.0' });
|
|
455
|
-
registerGetVersionTool(server as any, mockClient as any);
|
|
456
|
-
|
|
457
|
-
const handler = server.getHandler('getVersion')!;
|
|
458
|
-
const result = await handler({}, mockExtra);
|
|
459
|
-
|
|
460
|
-
expect(mockClient.getVersion).toHaveBeenCalled();
|
|
461
|
-
expect(result.content[0].text).toContain('2026.1.0');
|
|
462
|
-
});
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
describe('service tools', () => {
|
|
466
|
-
it('callService should call service', async () => {
|
|
467
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
468
|
-
registerCallServiceTool(server as any, mockClient as any);
|
|
469
|
-
|
|
470
|
-
const handler = server.getHandler('callService')!;
|
|
471
|
-
const result = await handler({
|
|
472
|
-
domain: 'light',
|
|
473
|
-
service: 'turn_on',
|
|
474
|
-
target: { entity_id: 'light.test' },
|
|
475
|
-
service_data: { brightness: 255 },
|
|
476
|
-
}, mockExtra);
|
|
477
|
-
|
|
478
|
-
expect(mockClient.callService).toHaveBeenCalled();
|
|
479
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
480
|
-
expect(parsed.success).toBe(true);
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
it('entityAction should perform action', async () => {
|
|
484
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
485
|
-
registerEntityActionTool(server as any, mockClient as any);
|
|
486
|
-
|
|
487
|
-
const handler = server.getHandler('entityAction')!;
|
|
488
|
-
const result = await handler({ entity_id: 'switch.lamp', action: 'toggle' }, mockExtra);
|
|
489
|
-
|
|
490
|
-
expect(mockClient.callService).toHaveBeenCalled();
|
|
491
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
492
|
-
expect(parsed.success).toBe(true);
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
describe('automation tools', () => {
|
|
497
|
-
it('listAutomations should return automations', async () => {
|
|
498
|
-
mockClient.getAutomations.mockResolvedValue([{ id: '1', alias: 'Test', state: 'on' }]);
|
|
499
|
-
registerListAutomationsTool(server as any, mockClient as any);
|
|
500
|
-
|
|
501
|
-
const handler = server.getHandler('listAutomations')!;
|
|
502
|
-
const result = await handler({}, mockExtra);
|
|
503
|
-
|
|
504
|
-
expect(mockClient.getAutomations).toHaveBeenCalled();
|
|
505
|
-
expect(result.content[0].text).toContain('Test');
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
it('triggerAutomation should trigger', async () => {
|
|
509
|
-
mockClient.triggerAutomation.mockResolvedValue({ context: { id: '123' } });
|
|
510
|
-
registerTriggerAutomationTool(server as any, mockClient as any);
|
|
511
|
-
|
|
512
|
-
const handler = server.getHandler('triggerAutomation')!;
|
|
513
|
-
const result = await handler({ entity_id: 'automation.test' }, mockExtra);
|
|
514
|
-
|
|
515
|
-
expect(mockClient.triggerAutomation).toHaveBeenCalledWith('automation.test', undefined);
|
|
516
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
517
|
-
expect(parsed.success).toBe(true);
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
it('createAutomation should create', async () => {
|
|
521
|
-
mockClient.createAutomation.mockResolvedValue({ id: 'new-id' });
|
|
522
|
-
registerCreateAutomationTool(server as any, mockClient as any);
|
|
523
|
-
|
|
524
|
-
const handler = server.getHandler('createAutomation')!;
|
|
525
|
-
const result = await handler({
|
|
526
|
-
alias: 'Test',
|
|
527
|
-
trigger: [{ platform: 'state' }],
|
|
528
|
-
action: [{ service: 'light.turn_on' }],
|
|
529
|
-
}, mockExtra);
|
|
530
|
-
|
|
531
|
-
expect(mockClient.createAutomation).toHaveBeenCalled();
|
|
532
|
-
expect(result.content[0].text).toContain('new-id');
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
it('deleteAutomation should delete', async () => {
|
|
536
|
-
mockClient.deleteAutomation.mockResolvedValue({});
|
|
537
|
-
registerDeleteAutomationTool(server as any, mockClient as any);
|
|
538
|
-
|
|
539
|
-
const handler = server.getHandler('deleteAutomation')!;
|
|
540
|
-
const result = await handler({ automation_id: 'test-id' }, mockExtra);
|
|
541
|
-
|
|
542
|
-
expect(mockClient.deleteAutomation).toHaveBeenCalledWith('test-id');
|
|
543
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
544
|
-
expect(parsed.success).toBe(true);
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
it('getAutomationTrace should get trace', async () => {
|
|
548
|
-
mockClient.getAutomationTrace.mockResolvedValue([{ run_id: '123' }]);
|
|
549
|
-
registerGetAutomationTraceTool(server as any, mockClient as any);
|
|
550
|
-
|
|
551
|
-
const handler = server.getHandler('getAutomationTrace')!;
|
|
552
|
-
const result = await handler({ entity_id: 'automation.test' }, mockExtra);
|
|
553
|
-
|
|
554
|
-
expect(mockClient.getAutomationTrace).toHaveBeenCalledWith('automation.test', undefined);
|
|
555
|
-
expect(result.content[0].text).toContain('trace_count');
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
it('getAutomationTrace forwards limit', async () => {
|
|
559
|
-
mockClient.getAutomationTrace.mockResolvedValue([]);
|
|
560
|
-
registerGetAutomationTraceTool(server as any, mockClient as any);
|
|
561
|
-
|
|
562
|
-
await server.getHandler('getAutomationTrace')!({ entity_id: 'automation.test', limit: 3 }, mockExtra);
|
|
563
|
-
|
|
564
|
-
expect(mockClient.getAutomationTrace).toHaveBeenCalledWith('automation.test', 3);
|
|
565
|
-
});
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
describe('automation controls', () => {
|
|
569
|
-
it('enableAutomation should enable', async () => {
|
|
570
|
-
mockClient.enableAutomation.mockResolvedValue({ context: { id: '123' } });
|
|
571
|
-
registerEnableAutomationTool(server as any, mockClient as any);
|
|
572
|
-
|
|
573
|
-
const handler = server.getHandler('enableAutomation')!;
|
|
574
|
-
const result = await handler({ entity_id: 'automation.test' }, mockExtra);
|
|
575
|
-
|
|
576
|
-
expect(mockClient.enableAutomation).toHaveBeenCalledWith('automation.test');
|
|
577
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
578
|
-
expect(parsed.success).toBe(true);
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
it('disableAutomation should disable', async () => {
|
|
582
|
-
mockClient.disableAutomation.mockResolvedValue({ context: { id: '123' } });
|
|
583
|
-
registerDisableAutomationTool(server as any, mockClient as any);
|
|
584
|
-
|
|
585
|
-
const handler = server.getHandler('disableAutomation')!;
|
|
586
|
-
const result = await handler({ entity_id: 'automation.test' }, mockExtra);
|
|
587
|
-
|
|
588
|
-
expect(mockClient.disableAutomation).toHaveBeenCalledWith('automation.test');
|
|
589
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
590
|
-
expect(parsed.success).toBe(true);
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
it('toggleAutomation should toggle', async () => {
|
|
594
|
-
mockClient.toggleAutomation.mockResolvedValue({ context: { id: '123' } });
|
|
595
|
-
registerToggleAutomationTool(server as any, mockClient as any);
|
|
596
|
-
|
|
597
|
-
const handler = server.getHandler('toggleAutomation')!;
|
|
598
|
-
const result = await handler({ entity_id: 'automation.test' }, mockExtra);
|
|
599
|
-
|
|
600
|
-
expect(mockClient.toggleAutomation).toHaveBeenCalledWith('automation.test');
|
|
601
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
602
|
-
expect(parsed.success).toBe(true);
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
it('reloadAutomations should reload', async () => {
|
|
606
|
-
mockClient.reloadAutomations.mockResolvedValue({});
|
|
607
|
-
registerReloadAutomationsTool(server as any, mockClient as any);
|
|
608
|
-
|
|
609
|
-
const handler = server.getHandler('reloadAutomations')!;
|
|
610
|
-
const result = await handler({}, mockExtra);
|
|
611
|
-
|
|
612
|
-
expect(mockClient.reloadAutomations).toHaveBeenCalled();
|
|
613
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
614
|
-
expect(parsed.success).toBe(true);
|
|
615
|
-
});
|
|
616
|
-
});
|
|
617
|
-
|
|
618
|
-
describe('scene and script tools', () => {
|
|
619
|
-
it('activateScene should activate', async () => {
|
|
620
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
621
|
-
registerActivateSceneTool(server as any, mockClient as any);
|
|
622
|
-
|
|
623
|
-
const handler = server.getHandler('activateScene')!;
|
|
624
|
-
const result = await handler({ entity_id: 'scene.movie' }, mockExtra);
|
|
625
|
-
|
|
626
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
627
|
-
domain: 'scene',
|
|
628
|
-
service: 'turn_on',
|
|
629
|
-
target: { entity_id: 'scene.movie' },
|
|
630
|
-
});
|
|
631
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
632
|
-
expect(parsed.success).toBe(true);
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
it('runScript should run script', async () => {
|
|
636
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
637
|
-
registerRunScriptTool(server as any, mockClient as any);
|
|
638
|
-
|
|
639
|
-
const handler = server.getHandler('runScript')!;
|
|
640
|
-
const result = await handler({ entity_id: 'script.test' }, mockExtra);
|
|
641
|
-
|
|
642
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
643
|
-
domain: 'script',
|
|
644
|
-
service: 'turn_on',
|
|
645
|
-
target: { entity_id: 'script.test' },
|
|
646
|
-
service_data: undefined,
|
|
647
|
-
});
|
|
648
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
649
|
-
expect(parsed.success).toBe(true);
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
it('runScript should pass variables', async () => {
|
|
653
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
654
|
-
registerRunScriptTool(server as any, mockClient as any);
|
|
655
|
-
|
|
656
|
-
const handler = server.getHandler('runScript')!;
|
|
657
|
-
const result = await handler({ entity_id: 'script.test', variables: { brightness: 50 } }, mockExtra);
|
|
658
|
-
|
|
659
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
660
|
-
domain: 'script',
|
|
661
|
-
service: 'turn_on',
|
|
662
|
-
target: { entity_id: 'script.test' },
|
|
663
|
-
service_data: { brightness: 50 },
|
|
664
|
-
});
|
|
665
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
666
|
-
expect(parsed.success).toBe(true);
|
|
667
|
-
});
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
describe('notification tools', () => {
|
|
671
|
-
it('sendNotification should send', async () => {
|
|
672
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
673
|
-
registerSendNotificationTool(server as any, mockClient as any);
|
|
674
|
-
|
|
675
|
-
const handler = server.getHandler('sendNotification')!;
|
|
676
|
-
const result = await handler({
|
|
677
|
-
message: 'Test message',
|
|
678
|
-
title: 'Test Title',
|
|
679
|
-
target: 'mobile_app_phone',
|
|
680
|
-
}, mockExtra);
|
|
681
|
-
|
|
682
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
683
|
-
domain: 'notify',
|
|
684
|
-
service: 'mobile_app_phone',
|
|
685
|
-
service_data: { message: 'Test message', title: 'Test Title' },
|
|
686
|
-
});
|
|
687
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
688
|
-
expect(parsed.success).toBe(true);
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
it('sendNotification should include actions', async () => {
|
|
692
|
-
mockClient.callService.mockResolvedValue({ context: { id: '123' } });
|
|
693
|
-
registerSendNotificationTool(server as any, mockClient as any);
|
|
694
|
-
|
|
695
|
-
const handler = server.getHandler('sendNotification')!;
|
|
696
|
-
await handler({
|
|
697
|
-
message: 'Doorbell',
|
|
698
|
-
target: 'mobile_app_phone',
|
|
699
|
-
actions: [{ action: 'OPEN', title: 'Open Door' }],
|
|
700
|
-
}, mockExtra);
|
|
701
|
-
|
|
702
|
-
expect(mockClient.callService).toHaveBeenCalledWith({
|
|
703
|
-
domain: 'notify',
|
|
704
|
-
service: 'mobile_app_phone',
|
|
705
|
-
service_data: {
|
|
706
|
-
message: 'Doorbell',
|
|
707
|
-
data: {
|
|
708
|
-
actions: [{ action: 'OPEN', title: 'Open Door' }],
|
|
709
|
-
},
|
|
710
|
-
},
|
|
711
|
-
});
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
it('listNotificationTargets should list', async () => {
|
|
715
|
-
mockClient.getStates.mockResolvedValue([
|
|
716
|
-
{ entity_id: 'device_tracker.phone', state: 'home', attributes: { source_type: 'gps', friendly_name: 'Phone' } },
|
|
717
|
-
]);
|
|
718
|
-
registerListNotificationTargetsTool(server as any, mockClient as any);
|
|
719
|
-
|
|
720
|
-
const handler = server.getHandler('listNotificationTargets')!;
|
|
721
|
-
const result = await handler({}, mockExtra);
|
|
722
|
-
|
|
723
|
-
expect(mockClient.getStates).toHaveBeenCalled();
|
|
724
|
-
expect(result.content[0].text).toContain('persistent_notification');
|
|
725
|
-
});
|
|
726
|
-
});
|
|
727
|
-
|
|
728
|
-
describe('calendar tools', () => {
|
|
729
|
-
it('listCalendars should list', async () => {
|
|
730
|
-
mockClient.getCalendars.mockResolvedValue([{ entity_id: 'calendar.test', name: 'Test' }]);
|
|
731
|
-
registerListCalendarsTool(server as any, mockClient as any);
|
|
732
|
-
|
|
733
|
-
const handler = server.getHandler('listCalendars')!;
|
|
734
|
-
const result = await handler({}, mockExtra);
|
|
735
|
-
|
|
736
|
-
expect(mockClient.getCalendars).toHaveBeenCalled();
|
|
737
|
-
const parsed = parseResult(result) as { count: number };
|
|
738
|
-
expect(parsed.count).toBe(1);
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
it('getCalendarEvents should get events from calendar', async () => {
|
|
742
|
-
mockClient.getCalendarEvents.mockResolvedValue([
|
|
743
|
-
{ summary: 'Meeting', start: { dateTime: '2026-01-17T10:00:00Z' }, end: { dateTime: '2026-01-17T11:00:00Z' } },
|
|
744
|
-
]);
|
|
745
|
-
registerGetCalendarEventsTool(server as any, mockClient as any);
|
|
746
|
-
|
|
747
|
-
const handler = server.getHandler('getCalendarEvents')!;
|
|
748
|
-
const result = await handler({ entity_id: 'calendar.work', days: 7 }, mockExtra);
|
|
749
|
-
|
|
750
|
-
expect(mockClient.getCalendarEvents).toHaveBeenCalled();
|
|
751
|
-
expect(result.content[0].text).toContain('Meeting');
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
it('getCalendarEvents should get all events', async () => {
|
|
755
|
-
mockClient.getAllCalendarEvents.mockResolvedValue([
|
|
756
|
-
{ calendar: 'calendar.work', events: [{ summary: 'Meeting', start: { dateTime: '2026-01-17T10:00:00Z' }, end: { dateTime: '2026-01-17T11:00:00Z' } }] },
|
|
757
|
-
]);
|
|
758
|
-
registerGetCalendarEventsTool(server as any, mockClient as any);
|
|
759
|
-
|
|
760
|
-
const handler = server.getHandler('getCalendarEvents')!;
|
|
761
|
-
const result = await handler({}, mockExtra);
|
|
762
|
-
|
|
763
|
-
expect(mockClient.getAllCalendarEvents).toHaveBeenCalled();
|
|
764
|
-
expect(result.content[0].text).toContain('total_count');
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
describe('system tools', () => {
|
|
769
|
-
it('restartHomeAssistant should restart', async () => {
|
|
770
|
-
mockClient.restartServer.mockResolvedValue({});
|
|
771
|
-
registerRestartHomeAssistantTool(server as any, mockClient as any);
|
|
772
|
-
|
|
773
|
-
const handler = server.getHandler('restartHomeAssistant')!;
|
|
774
|
-
const result = await handler({}, mockExtra);
|
|
775
|
-
|
|
776
|
-
expect(mockClient.restartServer).toHaveBeenCalled();
|
|
777
|
-
const parsed = parseResult(result) as { success: boolean };
|
|
778
|
-
expect(parsed.success).toBe(true);
|
|
779
|
-
});
|
|
780
|
-
|
|
781
|
-
it('getSystemLog should get log', async () => {
|
|
782
|
-
mockClient.getSystemLog.mockResolvedValue([{ timestamp: '2026-01-17T10:00:00Z', level: 'ERROR', message: 'Test error' }]);
|
|
783
|
-
registerGetSystemLogTool(server as any, mockClient as any);
|
|
784
|
-
|
|
785
|
-
const handler = server.getHandler('getSystemLog')!;
|
|
786
|
-
const result = await handler({ hours: 24 }, mockExtra);
|
|
787
|
-
|
|
788
|
-
expect(mockClient.getSystemLog).toHaveBeenCalledWith({ hours: 24, entity_id: undefined, limit: 100 });
|
|
789
|
-
expect(result.content[0].text).toContain('Test error');
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
it('checkUpdates should check updates', async () => {
|
|
793
|
-
mockClient.getAvailableUpdates.mockResolvedValue({ available: [{ name: 'core', version: '2026.2.0' }] });
|
|
794
|
-
registerCheckUpdatesTool(server as any, mockClient as any);
|
|
795
|
-
|
|
796
|
-
const handler = server.getHandler('checkUpdates')!;
|
|
797
|
-
const result = await handler({}, mockExtra);
|
|
798
|
-
|
|
799
|
-
expect(mockClient.getAvailableUpdates).toHaveBeenCalled();
|
|
800
|
-
expect(result.content[0].text).toContain('2026.2.0');
|
|
801
|
-
});
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
describe('listPersons', () => {
|
|
805
|
-
it('should list persons', async () => {
|
|
806
|
-
mockClient.getEntitiesByDomain.mockResolvedValue([
|
|
807
|
-
{ entity_id: 'person.john', state: 'home', attributes: { friendly_name: 'John' } },
|
|
808
|
-
]);
|
|
809
|
-
registerListPersonsTool(server as any, mockClient as any);
|
|
810
|
-
|
|
811
|
-
const handler = server.getHandler('listPersons')!;
|
|
812
|
-
const result = await handler({}, mockExtra);
|
|
813
|
-
|
|
814
|
-
expect(mockClient.getEntitiesByDomain).toHaveBeenCalledWith('person');
|
|
815
|
-
expect(result.content[0].text).toContain('John');
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
it('should show persons count', async () => {
|
|
819
|
-
mockClient.getEntitiesByDomain.mockResolvedValue([
|
|
820
|
-
{ entity_id: 'person.john', state: 'home', attributes: { friendly_name: 'John' } },
|
|
821
|
-
{ entity_id: 'person.jane', state: 'not_home', attributes: { friendly_name: 'Jane' } },
|
|
822
|
-
]);
|
|
823
|
-
registerListPersonsTool(server as any, mockClient as any);
|
|
824
|
-
|
|
825
|
-
const handler = server.getHandler('listPersons')!;
|
|
826
|
-
const result = await handler({}, mockExtra);
|
|
827
|
-
|
|
828
|
-
const parsed = parseResult(result) as { count: number; onsite: number; away: number };
|
|
829
|
-
expect(parsed.count).toBe(2);
|
|
830
|
-
expect(parsed.onsite).toBe(1);
|
|
831
|
-
expect(parsed.away).toBe(1);
|
|
832
|
-
});
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
describe('entity existence guard (control tools must not report success for unknown entities)', () => {
|
|
836
|
-
const cases: Array<[string, (srv: any, c: any) => void, Record<string, unknown>]> = [
|
|
837
|
-
['entityAction', (srv, c) => registerEntityActionTool(srv, c), { entity_id: 'light.does_not_exist', action: 'turn_on' }],
|
|
838
|
-
['controlLight', (srv, c) => registerControlLightTool(srv, c), { entity_id: 'light.does_not_exist', action: 'turn_on' }],
|
|
839
|
-
['controlClimate', (srv, c) => registerControlClimateTool(srv, c), { entity_id: 'climate.does_not_exist', temperature: 21 }],
|
|
840
|
-
['controlFan', (srv, c) => registerControlFanTool(srv, c), { entity_id: 'fan.does_not_exist', action: 'turn_on' }],
|
|
841
|
-
['controlCover', (srv, c) => registerControlCoverTool(srv, c), { entity_id: 'cover.does_not_exist', action: 'open' }],
|
|
842
|
-
['controlMediaPlayer', (srv, c) => registerControlMediaPlayerTool(srv, c), { entity_id: 'media_player.does_not_exist', action: 'play' }],
|
|
843
|
-
['activateScene', (srv, c) => registerActivateSceneTool(srv, c), { entity_id: 'scene.does_not_exist' }],
|
|
844
|
-
['runScript', (srv, c) => registerRunScriptTool(srv, c), { entity_id: 'script.does_not_exist' }],
|
|
845
|
-
];
|
|
846
|
-
|
|
847
|
-
for (const [name, register, args] of cases) {
|
|
848
|
-
it(`${name} returns isError 'Entity not found' and never calls the service`, async () => {
|
|
849
|
-
mockClient.getState.mockResolvedValue(null);
|
|
850
|
-
register(server as any, mockClient as any);
|
|
851
|
-
|
|
852
|
-
const result = await server.getHandler(name)!(args, mockExtra);
|
|
853
|
-
|
|
854
|
-
expect(mockClient.getState).toHaveBeenCalledWith(args.entity_id);
|
|
855
|
-
expect(mockClient.callService).not.toHaveBeenCalled();
|
|
856
|
-
expect((result as { isError?: boolean }).isError).toBe(true);
|
|
857
|
-
const parsed = parseResult(result) as { error: string; entity_id: string; hint: string };
|
|
858
|
-
expect(parsed.error).toBe('Entity not found');
|
|
859
|
-
expect(parsed.entity_id).toBe(args.entity_id);
|
|
860
|
-
expect(parsed.hint).toMatch(/No action was performed/);
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
it('entityAction keeps its specific format error for a malformed id (no lookup)', async () => {
|
|
865
|
-
registerEntityActionTool(server as any, mockClient as any);
|
|
866
|
-
const result = await server.getHandler('entityAction')!({ entity_id: '', action: 'turn_on' }, mockExtra);
|
|
867
|
-
expect((parseResult(result) as { error: string }).error).toBe('Invalid entity_id format');
|
|
868
|
-
expect(mockClient.getState).not.toHaveBeenCalled();
|
|
869
|
-
});
|
|
870
|
-
});
|
|
871
|
-
});
|
|
872
|
-
|