hap-controller
Version:
Library to implement a HAP (HomeKit) controller
156 lines • 5.25 kB
TypeScript
/**
* BLE discovery wrappers for finding HAP devices.
*/
import { EventEmitter } from 'events';
import { Peripheral } from '@stoprocent/noble';
/**
* See Table 7-43
*/
declare const DiscoveryPairingStatusFlags: {
AccessoryNotPaired: number;
};
export { DiscoveryPairingStatusFlags };
export interface HapServiceBle {
name: string;
/**
* CoID: Company Identifier code, 0x004C (Apple,Inc.) ,in little endian format.
*/
CoID: number;
/**
* TY: 8 bits for Type,which shall be set to 0x11
*/
TY: number;
/**
* STL: 8 bits for Sub Type and Length
*
* From Specs:
* The 3 significant bits specify the HomeKit advertising
* format Sub Type and shall be set to 1, and the remaining 5 bits is the length of the remaining
* bytes in the manufacturer specific data which shall be set to the value 17.
*/
AIL: number;
/**
* SF: 8 bits for Status Flags
*
* From Specs:
* Bits 1-7 are reserved and shall be set to 0, Bit 0 shall reflect the value of the HAP Pairing
* Status Flag.
* see DiscoveryPairingStatusFlags
*/
SF: number;
/**
* Device-ID: 48-bit Device ID (”5.4 DeviceID” (page31)) of the accessory.
*/
DeviceID: string;
/**
* ACID: Accessory Category Identifier
*
* From Specs:
* 16-bit little endian unsigned Accessory Category Identifier,which indicates the category that
* best describes the primary function of the accessory. This must have a range of 1-65535. This
* must take one of the values defined in the ”13-1 Accessory Categories” (page 252).
* The Category Identifier must not change except during a firmware update.
*/
ACID: number;
/**
* GSN: 16-bit little endian unsigned Global State Number.
*
* From Specs:
* The Global State Number represents the state at which a required change on the accessory was
* last notified to the HomeKit controller. Accessories shall maintain a 16 bit monotonically
* increasing GSN value. This value must have a range of 1-65535 and wrap to 1 when it overflows.
* This value must persist across reboots, power cycles, etc. This value must be reset back to 1
* when factory reset or a firmware update occurs on the accessory. For more details see
* ”7.4.6 HAP Notifications” (page 127)
*/
GSN: number;
/**
* CN: Configuration Number
*
* From Specs:
* 8 bits for Configuration Number, with a default starting value of 1. Accessories must
* increment the config number after a firmware update. This value must have a range of 1-255
* and wrap to 1 when it overflows. This value must persist across reboots, power cycles and
* firmware updates.
*/
CN: number;
/**
* CV: 8bit little endian Compatible Version
*
* From Specs:
* This value shall be set to 0x02 for this version of the HAP BLE.
*/
CV: number;
/**
* Added in v2 of the HAP specifications but no details known
* SH: 4byte little endian Setup Hash to support enhanced setup payload information
* (see”????”(page??))
*/
/**
* Peripheral object used for all communication to this device
*/
peripheral: Peripheral;
/**
* c#: the configuration number, same value as CN for convenient reasons with IP
*/
'c#': number;
/**
* id: the deviceId, same value as deviceId for convenient reasons with IP
*/
id: string;
/**
* ci: the category identifier, same value as ACID for convenient reasons with IP
*/
ci: number;
/**
* availableToPair: is the device available for pairing?
*/
availableToPair: boolean;
}
/**
* Handle discovery of IP devices
*
* @fires BLEDiscovery#serviceUp
* @fires BLEDiscovery#serviceChanged
*/
export default class BLEDiscovery extends EventEmitter {
private scanEnabled;
private allowDuplicates;
private services;
private handleStateChange;
private handleDiscover;
private handleScanStart;
private handleScanStop;
constructor();
/**
* Start searching for BLE HAP devices.
*
* @param {boolean} allowDuplicates - Deprecated, use new serviceChanged event instead.
* Allow duplicate serviceUp events. This
* is needed for disconnected events, where the GSN is
* updated in the advertisement.
*/
start(allowDuplicates?: boolean): void;
/**
* Get PairMethod to use for pairing from the data received during discovery
*
* @param {HapServiceBle} service Discovered service object to check
* @returns {Promise<number>} Promise which resolves with the PairMethod to use
*/
getPairMethod(service: HapServiceBle): Promise<number>;
/**
* List the currently known services.
*
* @returns {Object[]} Array of services
*/
list(): HapServiceBle[];
/**
* Stop an ongoing discovery process.
*/
stop(): void;
private _handleStateChange;
private _handleScanStart;
private _handleScanStop;
private _handleDiscover;
}
//# sourceMappingURL=ble-discovery.d.ts.map