UNPKG

homebridge

Version:
97 lines 3.64 kB
/** * Matter Utility Functions * * Shared utility functions used across the Matter implementation to avoid code duplication. */ import type { MacAddress } from '@homebridge/hap-nodejs'; export interface NodeError extends Error { code?: string; errno?: number; syscall?: string; path?: string; } /** * Type guard to check if an error has a code property * * @param error - The error to check * @returns True if error has a code property */ export declare function isNodeError(error: unknown): error is NodeError; /** * Extract error code from an error object * * @param error - The error object * @returns Error code string if present, undefined otherwise */ export declare function getErrorCode(error: unknown): string | undefined; /** * Normalize bind configuration to array format * * Converts a single bind address or array of addresses to a consistent array format. * Returns undefined if no bind config provided. * * @param bind - Single bind address, array of addresses, or undefined * @returns Array of bind addresses or undefined * * @example * ```typescript * normalizeBindConfig('192.168.1.1') // ['192.168.1.1'] * normalizeBindConfig(['192.168.1.1', '10.0.0.1']) // ['192.168.1.1', '10.0.0.1'] * normalizeBindConfig(undefined) // undefined * ``` */ export declare function normalizeBindConfig(bind: string | string[] | undefined): string[] | undefined; /** * Create a Matter username from a unique identifier * * Formats a unique ID (like a serial number) into a MAC address format * suitable for use as a Matter bridge username. * * @param uniqueId - Unique identifier (typically without colons) * @returns MAC address formatted username * * @example * ```typescript * createMatterUsername('ABCDEF123456') // 'AB:CD:EF:12:34:56' * ``` */ export declare function createMatterUsername(uniqueId: string): MacAddress; /** * Append suffix to a MAC address for Matter port allocation * * @param baseUsername - Base MAC address * @param suffix - Suffix to append (e.g., 'MATTER') * @returns MAC address with suffix */ export declare function appendUsernameSuffix(baseUsername: string, suffix: string): MacAddress; /** * Sanitise a Matter `productLabel` (or similar) so it does not contain the * vendor name. The Matter spec requires that `productLabel` SHALL NOT include * the `vendorName`, and matter.js logs a warning when it does. Many users * name accessories with the manufacturer prefix (e.g. "Eufy Front Door"), * which trips the check unless we strip the vendor first. * * Removes the first case-insensitive occurrence of `vendor` from `label`, * collapses whitespace, and trims leading/trailing separators. Returns an * empty string if stripping consumes the entire label — callers should * provide a non-vendor fallback in that case. * * @param label - The candidate label (e.g. an accessory display name) * @param vendor - The vendor name to strip * @returns A label safe to send as `productLabel`, or `''` if fully consumed * * @example * ```typescript * stripVendorFromLabel('Eufy Front Door', 'Eufy') // 'Front Door' * stripVendorFromLabel('Govee Light', 'govee') // 'Light' * stripVendorFromLabel('Homebridge', 'Homebridge') // '' (caller supplies fallback) * ``` */ export declare function stripVendorFromLabel(label: string | undefined, vendor: string | undefined): string; /** * Get the version of @matter/main from package.json dependencies. * * @returns The version string of @matter/main, or '0.0.0' if not found. */ export declare function getMatterJsVersion(): Promise<string>; //# sourceMappingURL=utils.d.ts.map