Back to Homebridge

Interface API

docs/interfaces/API.html

2.0.28.0 KB
Original Source
  • API

Interface API

Export types for basically everything but the actual API implementation

interface API {
hap: __module;
hapLegacyTypes: __module;
isMatterAvailable: () => boolean;
isMatterEnabled: () => boolean;
matter?: MatterAPI;
on: (event: "didFinishLaunching", listener: () => void) => this & (
event: "shutdown",
listener: () => void,
) => this;
platformAccessory: typeof PlatformAccessory;
publishExternalAccessories: (
pluginIdentifier: string,
accessories: PlatformAccessory<UnknownContext>[],
) => void;
registerAccessory: (
accessoryName: string,
constructor: AccessoryPluginConstructor,
) => void & (
pluginIdentifier: string,
accessoryName: string,
constructor: AccessoryPluginConstructor,
) => void;
registerPlatform: <Config extends PlatformConfig>(
platformName: string,
constructor: PlatformPluginConstructor<Config>,
) => void & <Config extends PlatformConfig>(
pluginIdentifier: string,
platformName: string,
constructor: PlatformPluginConstructor<Config>,
) => void;
registerPlatformAccessories: (
pluginIdentifier: string,
platformName: string,
accessories: PlatformAccessory<UnknownContext>[],
) => void;
serverVersion: string;
unregisterPlatformAccessories: (
pluginIdentifier: string,
platformName: string,
accessories: PlatformAccessory<UnknownContext>[],
) => void;
updatePlatformAccessories: (
accessories: PlatformAccessory<UnknownContext>[],
) => void;
user: typeof User;
version: number;
versionGreaterOrEqual: (version: string) => boolean;
}

Index

Properties

haphapLegacyTypesisMatterAvailableisMatterEnabledmatter?onplatformAccessorypublishExternalAccessoriesregisterAccessoryregisterPlatformregisterPlatformAccessoriesserverVersionunregisterPlatformAccessoriesupdatePlatformAccessoriesuserversionversionGreaterOrEqual

Properties

Readonlyhap

hap: __module

ReadonlyhapLegacyTypes

hapLegacyTypes: __module

isMatterAvailable

isMatterAvailable: () => boolean

Check if Matter is available in this version of Homebridge

Type Declaration

    • (): boolean

Returns boolean

true if Homebridge version is >= 2.0.0-alpha.0

isMatterEnabled

isMatterEnabled: () => boolean

Check if Matter is enabled for this bridge For main bridge: returns true if Matter is enabled in bridge.matter config For child bridge: returns true if Matter is enabled in the _bridge.matter config

Type Declaration

    • (): boolean

Returns boolean

true if Matter is enabled

Optional Readonlymatter

matter?: MatterAPI

Matter Protocol API.

Remarks

Defined when Matter is configured for this bridge (i.e. when api.isMatterEnabled() returns true), undefined otherwise. Loaded automatically before plugins run on Matter-enabled bridges, so plugins can access it from their initializer, platform/accessory constructor, or didFinishLaunching handler.

Safe access patterns:

api.matter?.registerPlatformAccessories(...) // defensive, no-ops when disabledif (api.isMatterEnabled()) { api.matter!.registerPlatformAccessories(...) // explicit guard}Copy

Example

// Register a Matter accessoryapi.matter?.registerPlatformAccessories('homebridge-example', 'Example', [{ UUID: api.hap.uuid.generate('my-light'), displayName: 'Living Room Light', deviceType: api.matter!.deviceTypes.OnOffLight, manufacturer: 'Example', model: 'Example Light', serialNumber: 'EX-001', clusters: { onOff: { onOff: false } },}])// Update stateawait api.matter?.updateAccessoryState(uuid, 'onOff', { onOff: true })Copy

on

on: (event: "didFinishLaunching", listener: () => void) => this & (
event: "shutdown",
listener: () => void,
) => this

ReadonlyplatformAccessory

platformAccessory: typeof PlatformAccessory

publishExternalAccessories

publishExternalAccessories: (
pluginIdentifier: string,
accessories: PlatformAccessory<UnknownContext>[],
) => void

registerAccessory

registerAccessory: (
accessoryName: string,
constructor: AccessoryPluginConstructor,
) => void & (
pluginIdentifier: string,
accessoryName: string,
constructor: AccessoryPluginConstructor,
) => void

registerPlatform

registerPlatform: <Config extends PlatformConfig>(
platformName: string,
constructor: PlatformPluginConstructor<Config>,
) => void & <Config extends PlatformConfig>(
pluginIdentifier: string,
platformName: string,
constructor: PlatformPluginConstructor<Config>,
) => void

registerPlatformAccessories

registerPlatformAccessories: (
pluginIdentifier: string,
platformName: string,
accessories: PlatformAccessory<UnknownContext>[],
) => void

ReadonlyserverVersion

serverVersion: string

The current homebridge semver version.

unregisterPlatformAccessories

unregisterPlatformAccessories: (
pluginIdentifier: string,
platformName: string,
accessories: PlatformAccessory<UnknownContext>[],
) => void

updatePlatformAccessories

updatePlatformAccessories: (
accessories: PlatformAccessory<UnknownContext>[],
) => void

Readonlyuser

user: typeof User

Readonlyversion

version: number

The homebridge API version as a floating point number.

versionGreaterOrEqual

versionGreaterOrEqual: (version: string) => boolean

Returns true if the current running homebridge version is greater or equal to the passed version string.

Example:

We assume the homebridge version 1.3.0-beta.12 (serverVersion) and the following example calls below

versionGreaterOrEqual("1.2.0"); // will return true versionGreaterOrEqual("1.3.0"); // will return false (the RELEASE version 1.3.0 is bigger than the BETA version 1.3.0-beta.12) versionGreaterOrEqual("1.3.0-beta.8); // will return trueCopy

Settings

Member Visibility

  • Inherited

ThemeOSLightDark

On This Page

Properties haphapLegacyTypesisMatterAvailableisMatterEnabledmatteronplatformAccessorypublishExternalAccessoriesregisterAccessoryregisterPlatformregisterPlatformAccessoriesserverVersionunregisterPlatformAccessoriesupdatePlatformAccessoriesuserversionversionGreaterOrEqual