import { ImprovSerialCurrentState, ImprovSerialErrorState, Logger } from "./const.js"; export interface Ssid { name: string; rssi: number; secured: boolean; } export interface NetworkState { online: boolean; supportsWifi: boolean; supportsEthernet: boolean; supportsThread: boolean; supportsModem: boolean; urls: string[]; } export declare class ImprovSerial extends EventTarget { port: SerialPort; logger: Logger; info?: { name: string; firmware: string; version: string; chipFamily: string; osName: string | null; osVersion: string | null; }; improvVersion: number | undefined; nextUrl: string | undefined; state?: ImprovSerialCurrentState | undefined; private _error; /** Last device error (or local timeout). Assigning dispatches `error-changed`. */ get error(): ImprovSerialErrorState; set error(error: ImprovSerialErrorState); private _networkState; /** * Last known network state: `undefined` until a request succeeds, `null` once * the device reports the command unsupported. Changes dispatch `network-state-changed`. */ get networkState(): NetworkState | null | undefined; private _stopNetworkStatePolling?; private _reader?; private _rpcFeedback?; private _rpcLock; constructor(port: SerialPort, logger: Logger); /** * Detect Improv Serial, fetch the state and return the next URL if provisioned. * @param timeout Timeout in ms to wait for the device to respond. Default to 1000ms. */ initialize(timeout?: number): Promise; close(): Promise; /** * This command will trigger at least one packet, * the Current State and if already provisioned, * the same response you would get if device provisioning * was successful (see below). * * A caller polling an intermittently-unresponsive device (e.g. one rebooting * to switch network interfaces) can pass a timeout shorter than the default * so each poll settles quickly. */ requestCurrentState(timeout?: number): Promise; requestInfo(timeout?: number): Promise; provision(ssid: string, password: string, timeout?: number): Promise; scan(timeout?: number): Promise; /** * Continuously scan for Wi-Fi networks, calling `onChange` whenever the list * of networks changes. * * Results are merged with previous scans (networks are keyed by name and kept * sorted alphabetically), so a network missing from a single scan won't * immediately disappear. `onChange` is only called when a value in the list * actually changes. * * Scanning stops on the first error or when the returned function is called. * If the first scan fails (e.g. the device doesn't support scanning, or stops * responding), `onChange` is called once with `null` to signal that networks * are unavailable. * * The returned function resolves once the in-flight scan has settled, so it * can be awaited before sending another RPC command (such as provisioning). */ subscribeSSIDs(onChange: (ssids: Ssid[] | null) => void): () => Promise; /** * Get the current hostname of the device. */ getHostname(timeout?: number): Promise; /** * Set the hostname of the device. Returns the hostname as set by the device. * * Hostnames need to conform to RFC 1123: letters, numbers and hyphens, up to * 255 characters. The device rejects other hostnames with a BAD_HOSTNAME error. */ setHostname(hostname: string, timeout?: number): Promise; /** * Get the current device name. This is the same value as `info.name`. */ getDeviceName(timeout?: number): Promise; /** * Set the device name. Returns the device name as set by the device. * * When setting both the device name and the hostname, set the device name * first, as it can change the default hostname. */ setDeviceName(deviceName: string, timeout?: number): Promise; /** * Request the device's network connectivity and supported interfaces. * * This is independent of the Wi-Fi provisioning state: a device already * online over Ethernet reports that here without Wi-Fi provisioning. The * first response string is the network flags as a decimal-encoded byte, and * when online the reachable device URL(s) follow. * * This command is optional. Devices that do not implement it respond with * UNKNOWN_RPC_COMMAND, so this rejects with that error for such devices. */ requestNetworkState(timeout?: number): Promise; /** * Poll the device's network state, keeping `networkState` fresh. Idempotent; * stopped by `stopNetworkStatePolling()`, `close()`, a disconnect, or the * device reporting the command unsupported. A failed poll keeps the last * known state, leaves `error` untouched and retries on the next tick. */ startNetworkStatePolling(interval?: number, timeout?: number): void; stopNetworkStatePolling(): void; private _requestNetworkState; private _setNetworkState; private _sendRPC; /** * Run an RPC command once the previous one has settled, so devices that * handle a single command at a time never see two at once. The chain is kept * alive regardless of each command's outcome. */ private _enqueueRPC; private _sendRPCWithResponse; private _sendRPCWithMultipleResponses; private _awaitRPCResultWithTimeout; private _processInput; private _handleIncomingPacket; /** * Add header + checksum and write packet to stream */ writePacketToStream(type: number, data: number[]): Promise; private _setError; }