refactor: optimize configuration and tool implementations
- Standardized error handling across tool implementations - Improved return type consistency for tool execution results - Simplified configuration parsing and type definitions - Enhanced type safety for various configuration schemas - Cleaned up and normalized tool response structures - Updated SSE and event subscription tool implementations
This commit is contained in:
@@ -2,79 +2,92 @@
|
||||
|
||||
// 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;
|
||||
};
|
||||
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;
|
||||
};
|
||||
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;
|
||||
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;
|
||||
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>;
|
||||
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;
|
||||
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[];
|
||||
};
|
||||
name: string;
|
||||
description: string;
|
||||
target?: {
|
||||
entity?: {
|
||||
domain: string[];
|
||||
};
|
||||
fields: Record<string, {
|
||||
name: string;
|
||||
description: string;
|
||||
required?: boolean;
|
||||
example?: any;
|
||||
selector?: any;
|
||||
}>;
|
||||
};
|
||||
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;
|
||||
};
|
||||
}
|
||||
event_type: string;
|
||||
data: Record<string, any>;
|
||||
origin: string;
|
||||
time_fired: string;
|
||||
context: {
|
||||
id: string;
|
||||
parent_id?: string;
|
||||
user_id?: string;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user