import type { IotasLogger } from '../logger.js'; import type { FeatureCacheOptions, Rooms } from '../types.js'; export type FeatureChangeCallback = (changed: Map) => void; export type SnapshotFilter = (rooms: Rooms) => Rooms; /** Internal interface for sending feature updates to the API. */ export interface FeatureUpdater { updateFeature(featureId: string, value: number): void; } /** * FeatureCache provides cached feature values with background polling. * * - Seeded from discovery snapshot (no cold-start defaults) * - Single getRooms() call per poll cycle * - Per-device write barriers prevent stale poll data overwriting recent writes * - Smart pending-value matching: confirming snapshots are accepted early * - Subscription model for pushing updates via updateValue */ export declare class FeatureCache { private readonly log; private readonly client; private readonly values; private readonly writeBarriers; private readonly subscriptions; private pollTimer; private consecutiveFailures; private stopped; private readonly pollIntervalMs; private readonly pollBackoffBaseMs; private readonly pollBackoffMaxMs; private readonly snapshotFilter?; constructor(log: IotasLogger, client: FeatureUpdater & { getRooms(): Promise; }, options?: FeatureCacheOptions); seed(rooms: Rooms): void; get(featureId: string): number | undefined; set(featureId: string, value: number): void; /** * Write-through: sets cache value with write barrier AND sends the update * to the IOTAS API in one call. */ writeThrough(featureId: string, value: number): void; /** * Subscribe to feature changes. Callback is invoked when any of the * specified features are updated by the poller. * Returns a dispose function to unsubscribe. */ subscribe(featureIds: string[], callback: FeatureChangeCallback): () => void; start(): void; stop(): void; /** * Reset for a fresh start (used when re-discovering devices). * * This clears all cached values, write barriers, and subscriptions. * Callers must re-register subscriptions after calling reset(). * * Expected call order: * 1) reset() * 2) seed(rooms) * 3) recreate accessory runtimes (which re-subscribe) * 4) start() */ reset(): void; private schedulePoll; private poll; private updateFromSnapshot; private notifySubscribers; }