UNPKG

@oddbit/unifi

Version:
158 lines (157 loc) 5.3 kB
import * as unifiTypes from "./types"; export declare class UnifiController { private _cookieJar; private _isLoggedIn; private _host; private _port; private _isSelfSigned; private _siteName; constructor(config: unifiTypes.ControllerConfig); /** * Login to the UniFi controller * * @param username Admin username (provided user needs administrator rights) * @param password Password */ login(username: string, password: string): Promise<void>; /** * Logout from the UniFi controller. */ logout(): Promise<void>; /** * Reconnect a client device * * @param mac MAC address of the client device to reconnect */ reconnectClient(mac: string): Promise<void>; /** * Block a client device * * @param mac MAC of client device to block */ blockClient(mac: string): Promise<unifiTypes.ClientBlockedResponse>; /** * Unblock a client device * * @param mac MAC of client device to block */ unblockClient(mac: string): Promise<unifiTypes.ClientBlockedResponse>; /** * Create an alias for a client. * * @param id Id of the client * @param alias Alias name */ setClientAlias(id: string, alias: string): Promise<unifiTypes.ClientBase>; /** * Remove a client alias. * * @param id Id of the client */ removeClientAlias(id: string): Promise<unifiTypes.ClientBase>; /** * Set a client note. * * @param id Id of the client * @param note Note */ setClientNote(id: string, note: string): Promise<unifiTypes.ClientBase>; /** * Remove a client note. * * @param id Id of the client * @param note Note */ removeClientNote(id: string): Promise<unifiTypes.ClientBase>; /** * List connected clients */ listClients(): Promise<unifiTypes.Client[]>; /** * Get a single client's info * * @param mac MAC address of the client */ getClient(mac: string): Promise<unifiTypes.Client>; /** * Authorize a client device to connect through the hotspot. * * @param mac MAC address of the client device * @param ap The access point MAC to which the client device connected * @param [opts] Auth/connection options (see `AuthClientOpts`) * @returns Authorized client data */ authorizeGuest(mac: string, ap: string, opts?: unifiTypes.AuthClientOpts): Promise<unifiTypes.ClientAuthResponse>; /** * Unauthorize a client device * * @param mac MAC address of the client device */ unauthorizeGuest(mac: string): Promise<void>; /** * Create multi or single use voucher access tokens. * * @param quantity The number of vouchers to create * @param minutes How many minutes of uptime that will be included * @param [opts] Additional options */ createVouchers(quantity: number, minutes: number, opts?: unifiTypes.CreateVoucherOpts): Promise<number>; /** * Get all vouchers. The result set can be limited by a timestamp. The provided timestamp must match the * exact same timestamp on which the vouchers were created. * * @param timestamp The **exact** timestamp on which the desired vouchers were created on */ listVouchers(timestamp?: number): Promise<unifiTypes.Voucher[]>; /** * Delete a voucher. * * @param voucherId The `_id` of the created `Voucher` */ deleteVoucher(voucherId: string): Promise<void>; /** * List known sessions during a certain period of time. Default is to show the last month's sessions. * * @param [timeframe] The window of time (in seconds) to limit results by (default is 30 days) * @param [from] Alternative start time from where to list devices (default is "now") */ listSessions(timeframe?: number, from?: number): Promise<unifiTypes.Session[]>; /** * List sites that are configured on the controller */ listSites(): Promise<unifiTypes.Site[]>; /** * Get the name of the site that is targeted in API calls. */ getSite(): string; /** * Change the active site to target in API calls. This can be useful if site information was not known before * retreiving site information in a call to `listSites()`. * * @param siteName Name of the site */ setSite(siteName: string): void; /** * Get device info for one or all access points. Specifying an access point's MAC will limit * the result to only that AP. * * @param [ap] Access point MAC */ listDevices(ap?: string): Promise<unifiTypes.Device[]>; /** * Get controller system info */ getSystemInfo(): Promise<unifiTypes.SystemInfo>; private get(uri); private post(uri, body?); /** * Make a request to the UniFi controller API. * Successful requests always return an array, regardless of the context and amount of data. * So requests that expect a single value response comes in an array with 1 element and requests * that does not have a response are returned as an empty array. * * @param uri The API endpoint * @param body JSON body */ private request(method, uri, body?); }