/** * Matter Accessory Cache * * Handles persistence of Matter accessories across Homebridge restarts. * Similar to HAP's cached accessories, but designed for Matter's simpler API. */ import type { InternalMatterAccessory } from './types.js'; /** * Serializable Matter accessory part (excludes functions and runtime state) */ export interface SerializedMatterAccessoryPart { id: string; displayName?: string; deviceType: { name?: string; code?: number; /** The features the plugin composed each cluster with, see declaredClusterFeatures */ clusterFeatures?: Record; }; features?: InternalMatterAccessory['features']; clusters: { [clusterName: string]: { [attributeName: string]: unknown; }; }; } /** * Serializable Matter accessory (excludes functions and runtime state) * Plugin developers should work with MatterAccessory instead. */ export interface SerializedMatterAccessory { plugin: string; platform: string; uuid: string; displayName: string; deviceType: { name?: string; code?: number; /** The features the plugin composed each cluster with, see declaredClusterFeatures */ clusterFeatures?: Record; }; features?: InternalMatterAccessory['features']; serialNumber: string; manufacturer: string; model: string; firmwareRevision?: string; hardwareRevision?: string; softwareVersion?: string; context: Record; clusters?: { [clusterName: string]: { [attributeName: string]: unknown; }; }; parts?: SerializedMatterAccessoryPart[]; } /** * Matter Accessory Cache Manager */ export declare class MatterAccessoryCache { private readonly cacheFilePath; private cachedAccessories; private cacheLoaded; private cacheReadFailed; private saveQueue; private directoryEnsured; private saveDebounceTimer; private readonly SAVE_DEBOUNCE_MS; constructor(storagePath: string, bridgeId: string); /** * Load cached accessories from disk * Returns a map of cached accessories keyed by UUID. * I/O failures preserve the file and suspend saves until a later load succeeds. */ load(): Promise>; /** * Request a debounced save to cache * Multiple rapid calls within the debounce window will only result in one disk write * Use this for normal operations to reduce disk I/O */ requestSave(accessories: Map): void; /** * Cancel any pending debounced save without writing. * * A debounced save captures the live accessories map by reference. If a * timer is still armed when the owning server tears down and clears that * map, the timer would later fire and persist an empty map — wiping the * cache. Callers that are about to clear the map (e.g. ServerLifecycle.stop) * must cancel first. * * @returns true if a pending save was cancelled, false if none was armed */ cancelPendingSave(): boolean; /** * Save accessories to cache immediately (serialized to prevent concurrent write conflicts) * Uses a queue pattern to ensure saves are truly serialized even when called concurrently * Use this for shutdown/critical operations that need immediate persistence. * Rejects on failure; subsequent queued saves can still proceed. */ save(accessories: Map): Promise; /** * Internal save implementation * Performs atomic write to prevent cache corruption on system crashes */ private performSave; /** * Get cached accessory by UUID */ getCached(uuid: string): SerializedMatterAccessory | undefined; /** * Check if an accessory is cached */ hasCached(uuid: string): boolean; /** * Remove an accessory from cache */ removeCached(uuid: string): void; /** * Get all cached accessories as an array. * * Returns a fresh array each call (callers may mutate it freely) but does * not clone the per-entry SerializedMatterAccessory objects. If you only * need a single accessory, use getCached(uuid) — it's O(1). */ getAllCached(): SerializedMatterAccessory[]; /** * Serialize a Matter accessory for storage */ private serializeAccessory; } //# sourceMappingURL=accessoryCache.d.ts.map