UNPKG

homebridge-eightsleepthermostat

Version:

Homebridge thermostat accessory for the Eight Sleep Pod smart bed.

90 lines 3.1 kB
import { EightSleepThermostatPlatform } from './platform'; interface Session { expirationDate: string; userId: string; token: string; } export declare class EightSleepConnection { readonly platform: EightSleepThermostatPlatform; private readonly userCreds; private readonly cacheDir; private readonly sessionCachePath; private readonly primaryUserCachePath; private readonly log; session: Promise<Session | null>; primaryUserDevice: Promise<{ id: string; side: string; } | null>; constructor(platform: EightSleepThermostatPlatform, email: string, password: string); /** * This method will initiate a chain of events to either load the session * containing a userId & token info from cache, or send a new login request * to the 8slp API to fetch this information. * * The result of this method is stored by {@linkcode session} in the * form of `Promise<Session | null>` * * Associated methods: * {@linkcode loadCachedSession()} // loads cache & verifies token * {@linkcode login()} // if no cached session, will re-login * * @returns a Promise containing the loaded/fetched session * * @category Session */ prepareSession(): Promise<Session | null>; private loadCachedSession; private login; private isValid; private verifyFields; private updateClientSessionHeaders; /** * Session validation & reauthentication methods. Can be initiated externally * at any time to ensure session information (i.e. token) is up to date. */ validateActiveSession: () => Promise<void>; private reauthenticate; private preserveConnection; /** * This method will initiate a chain of events to either load the primary user data * containing the device `id` & `side` properties from cache, or will send a `GET` * request to `/users/me/` of 8slp API to fetch the user object * * The result of this method is stored by {@linkcode primaryUserDevice} in the * form of `Promise<PrimaryUser | null>` * * Associated methods: * {@linkcode loadCachedUser()} * {@linkcode fetchPrimaryUser()} * * @returns a Promise containing the loaded/fetched device * * @category CurrentDeviceType */ preparePrimaryUser(): Promise<{ id: string; side: string; } | null>; private loadCachedUser; private fetchPrimaryUser; private verifyDeviceFor; /** * Caching functionality for both session data (token, userId, tokenExp) and the * primary user's full profile (we only care about 'currentDevice') * * Associated methods: * {@linkcode readCache()} * {@linkcode writeToCache()} * {@linkcode eraseCache()} * {@linkcode makeCacheDirectory()} * * @category Caching {@linkcode Session} & {@linkcode PrimaryUser} */ private readCache; private writeToCache; private eraseCache; private makeCacheDirectory; } export {}; //# sourceMappingURL=eightSleepConnection.d.ts.map