import { ConnectionOptions, MessageBase } from "./types.js"; import { HaWebSocket } from "./socket.js"; export declare type ConnectionEventListener = (conn: Connection, eventData?: any) => void; declare type Events = "ready" | "disconnected" | "reconnect-error"; declare type SubscriptionUnsubscribe = () => Promise; interface SubscribeEventCommmandInFlight { resolve: (result?: any) => void; reject: (err: any) => void; callback: (ev: T) => void; subscribe: () => Promise; unsubscribe: SubscriptionUnsubscribe; } declare type CommandWithAnswerInFlight = { resolve: (result?: any) => void; reject: (err: any) => void; }; declare type CommandInFlight = SubscribeEventCommmandInFlight | CommandWithAnswerInFlight; export declare class Connection { options: ConnectionOptions; commandId: number; commands: Map; eventListeners: Map; closeRequested: boolean; socket: HaWebSocket; constructor(socket: HaWebSocket, options: ConnectionOptions); get haVersion(): string; setSocket(socket: HaWebSocket): void; addEventListener(eventType: Events, callback: ConnectionEventListener): void; removeEventListener(eventType: Events, callback: ConnectionEventListener): void; fireEvent(eventType: Events, eventData?: any): void; close(): void; /** * Subscribe to a specific or all events. * * @param callback Callback to be called when a new event fires * @param eventType * @returns promise that resolves to an unsubscribe function */ subscribeEvents(callback: (ev: EventType) => void, eventType?: string): Promise; ping(): Promise; sendMessage(message: MessageBase, commandId?: number): void; sendMessagePromise(message: MessageBase): Promise; /** * Call a websocket command that starts a subscription on the backend. * * @param message the message to start the subscription * @param callback the callback to be called when a new item arrives * @returns promise that resolves to an unsubscribe function */ subscribeMessage(callback: (result: Result) => void, subscribeMessage: MessageBase): Promise; private _handleMessage; private _handleClose; private _genCmdId; } export {};