@homebridge-plugins/homebridge-august
Version:
The August plugin allows you to access your August & Yale device(s) from HomeKit.
96 lines • 3.92 kB
TypeScript
import type { Logging } from 'homebridge';
import type { credentials } from './settings.js';
import August from 'august-yale';
export type ConnectivityState = 'healthy' | 'degraded' | 'offline' | 'recovering';
interface ExecuteOptions {
/**
* When true, OfflineError is thrown instead of returning undefined when
* the manager is offline. Used for user-initiated calls (lock/unlock)
* where HomeKit needs to see a real failure rather than a silent no-op.
*/
throwOnOffline?: boolean;
}
export declare class OfflineError extends Error {
constructor(label: string);
}
export declare class ConnectivityManager {
private readonly log;
private readonly credentialsFactory;
/**
* Called whenever the manager builds or rebuilds the August client.
* The platform uses this to keep its public `augustConfig` field in
* sync, so existing call sites that read `platform.augustConfig`
* continue to see the current client without going through the
* manager's accessor.
*/
private readonly onClientChanged;
private state;
private client?;
private probeTimer?;
private heartbeatTimer?;
private backoffIndex;
private rebuildInFlight?;
private listeners;
private offlineSinceMs?;
private probeAttempts;
private lastFailureMessage?;
constructor(log: Logging, credentialsFactory: () => Promise<credentials>,
/**
* Called whenever the manager builds or rebuilds the August client.
* The platform uses this to keep its public `augustConfig` field in
* sync, so existing call sites that read `platform.augustConfig`
* continue to see the current client without going through the
* manager's accessor.
*/
onClientChanged?: (client: August | undefined) => void);
init(): Promise<void>;
/**
* Single entry point for every August API call. Wraps the call,
* classifies any error, and updates connectivity state.
*
* Default behavior: returns undefined when state is 'offline' or when
* the call fails with a network/auth error. The platform-level poller
* treats undefined as 'skip this cycle'. Set throwOnOffline:true for
* user-initiated calls (lock/unlock) where HomeKit needs to see a
* real failure.
*
* Transient errors (4xx other than 401) are always rethrown — they're
* not connectivity issues and the caller needs to handle them.
*/
execute<T>(label: string, fn: (client: August) => Promise<T>, opts?: ExecuteOptions): Promise<T | undefined>;
/**
* External signal: PubNub WebSocket reported a (re)connection. PubNub
* recovers from a network blip seconds before HTTP polling would notice,
* so this is the fastest path back to healthy. Triggers an immediate
* probe that bypasses the current backoff delay.
*/
onPubNubReconnect(): void;
getState(): ConnectivityState;
/**
* Returns the current August client. Used by code paths that need
* direct access (e.g. addSimpleProps, which is a pure utility) and
* during the transition period while not all callers are routed
* through execute(). New code should prefer execute().
*/
getClient(): August | undefined;
/**
* Subscribe to connectivity state changes. Used by the platform-level
* poller to pause polling when offline and resume when healthy.
* Returns an unsubscribe function.
*/
onStateChange(l: (next: ConnectivityState, prev: ConnectivityState) => void): () => void;
shutdown(): void;
private reportSuccess;
private reportFailure;
private scheduleProbe;
private runProbe;
private rebuildClient;
private classify;
private transitionTo;
private startHeartbeat;
private stopHeartbeat;
private emitHeartbeat;
private clearProbeTimer;
}
export {};
//# sourceMappingURL=connectivity-manager.d.ts.map