Add core API routes, Home Assistant interfaces, and device management tools
- Implemented comprehensive API routes for MCP schema, device execution, and control - Created Home Assistant entity and event interfaces with detailed type definitions - Added tools for listing and controlling Home Assistant devices - Introduced SSE (Server-Sent Events) subscription and management endpoints - Implemented flexible device control with support for multiple domains and parameters
This commit is contained in:
83
src/interfaces/hass.ts
Normal file
83
src/interfaces/hass.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/// <reference lib="dom" />
|
||||
|
||||
// Home Assistant entity types
|
||||
export interface HassEntity {
|
||||
entity_id: string;
|
||||
state: string;
|
||||
attributes: Record<string, any>;
|
||||
last_changed?: string;
|
||||
last_updated?: string;
|
||||
context?: {
|
||||
id: string;
|
||||
parent_id?: string;
|
||||
user_id?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface HassState {
|
||||
entity_id: string;
|
||||
state: string;
|
||||
attributes: {
|
||||
friendly_name?: string;
|
||||
description?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
// Home Assistant instance types
|
||||
export interface HassInstance {
|
||||
states: HassStates;
|
||||
services: HassServices;
|
||||
connection: HassConnection;
|
||||
subscribeEvents: (callback: (event: HassEvent) => void, eventType?: string) => Promise<number>;
|
||||
unsubscribeEvents: (subscription: number) => void;
|
||||
}
|
||||
|
||||
export interface HassStates {
|
||||
get: () => Promise<HassEntity[]>;
|
||||
subscribe: (callback: (states: HassEntity[]) => void) => Promise<number>;
|
||||
unsubscribe: (subscription: number) => void;
|
||||
}
|
||||
|
||||
export interface HassServices {
|
||||
get: () => Promise<Record<string, Record<string, HassService>>>;
|
||||
call: (domain: string, service: string, serviceData?: Record<string, any>) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface HassConnection {
|
||||
socket: WebSocket;
|
||||
subscribeEvents: (callback: (event: HassEvent) => void, eventType?: string) => Promise<number>;
|
||||
unsubscribeEvents: (subscription: number) => void;
|
||||
}
|
||||
|
||||
export interface HassService {
|
||||
name: string;
|
||||
description: string;
|
||||
target?: {
|
||||
entity?: {
|
||||
domain: string[];
|
||||
};
|
||||
};
|
||||
fields: Record<string, {
|
||||
name: string;
|
||||
description: string;
|
||||
required?: boolean;
|
||||
example?: any;
|
||||
selector?: any;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface HassEvent {
|
||||
event_type: string;
|
||||
data: Record<string, any>;
|
||||
origin: string;
|
||||
time_fired: string;
|
||||
context: {
|
||||
id: string;
|
||||
parent_id?: string;
|
||||
user_id?: string;
|
||||
};
|
||||
}
|
||||
|
||||
// Re-export entity types from index.ts
|
||||
export { HassEntity, HassState } from './index.js';
|
||||
Reference in New Issue
Block a user