import { TDeviceStateHandler, EConnectionErrorType } from '../../types/public.js'; import { IDeviceConnectionStateObject, IDeviceConnectionTrackerOptions, IDeviceConnectionTracker } from '../../types/internal.js'; /** * DeviceConnectionTracker tracks the connection state of individual Modbus slave devices. * Features: * - Debounced notifications for disconnection events (prevents spam during unstable connections) * - Thread-safe operations using `async-mutex` * - Optional validation of slaveId (1–255) * - Immutable returned state objects * - Ability to disable the handler completely */ export declare class DeviceConnectionTracker implements IDeviceConnectionTracker { private _handler?; private readonly _states; private readonly _debounceMs; private readonly _validateSlaveId; private readonly _mutex; private readonly _debounceTimeouts; /** * Creates a new DeviceConnectionTracker instance. * * @param options - Configuration options for the tracker * @param options.debounceMs - Debounce interval in milliseconds for disconnection notifications (default: 500) * @param options.validateSlaveId - Whether to validate slaveId range (1–255) (default: true) */ constructor(options?: IDeviceConnectionTrackerOptions); /** * Sets the handler that will be called when a device's connection state changes. * When a new handler is set, it is immediately invoked for all currently tracked devices * to ensure the consumer has the latest state. * @param handler - Callback function `(slaveId: number, connected: boolean, error?) => void` */ setHandler(handler: TDeviceStateHandler): Promise; /** * Removes the current state change handler. * After calling this method, no further notifications will be sent. */ removeHandler(): Promise; /** * Notifies the tracker that a device has become connected. * If the device is already marked as connected, the notification is ignored. * Any pending debounce timer for disconnection is cancelled. * @param slaveId - Slave identifier (1–255) */ notifyConnected(slaveId: number): Promise; /** * Notifies the tracker that a device has disconnected with trailing debounce. * The actual notification is delayed by `debounceMs`. If another `notifyDisconnected` * is called for the same slaveId before the timer fires, the previous timer is cancelled. * @param slaveId - Slave identifier (1–255) * @param errorType - Type of disconnection error (default: UnknownError) * @param errorMessage - Detailed error message (default: 'Device disconnected') */ notifyDisconnected(slaveId: number, errorType?: EConnectionErrorType, errorMessage?: string): void; /** * Completely removes a device's state from the tracker. * This is a synchronous method used when a device is forcibly removed from configuration. * Ensures that the next `notifyConnected` will trigger a fresh notification. * @param slaveId - Slave identifier (1–255) */ removeState(slaveId: number): Promise; /** * Performs the actual disconnection notification (internal method). */ private _doNotifyDisconnected; /** * Returns a shallow copy of the current state for a specific slave. * @param slaveId - Slave identifier * @returns Device state object or undefined if not tracked */ getState(slaveId: number): Promise; /** * Returns a deep copy of all currently tracked device states. */ getAllStates(): Promise; /** * Clears all tracked states and cancels any pending debounce timers. * Also removes the current handler. */ clear(): Promise; /** * Checks whether a specific slave is being tracked. */ hasState(slaveId: number): Promise; /** * Returns an array of all slaveIds that are currently marked as connected. */ getConnectedSlaveIds(): Promise; /** * Resets the debounce timer for a specific slave (intended for testing only). * @internal */ __resetDebounce(slaveId: number): void; }