Class Service

Service represents a set of grouped values necessary to provide a logical function. For instance, a "Door Lock Mechanism" service might contain two values, one for the "desired lock state" and one for the "current lock state". A particular Service is distinguished from others by its "type", which is a UUID. HomeKit provides a set of known Service UUIDs defined in HomeKit.ts along with a corresponding concrete subclass that you can instantiate directly to set up the necessary values. These natively-supported Services are expected to contain a particular set of Characteristics.

Unlike Characteristics, where you cannot have two Characteristics with the same UUID in the same Service, you can actually have multiple Services with the same UUID in a single Accessory. For instance, imagine a Garage Door Opener with both a "security light" and a "backlight" for the display. Each light could be a "Lightbulb" Service with the same UUID. To account for this situation, we define an extra "subtype" property on Service, that can be a string or other string-convertible object that uniquely identifies the Service among its peers in an Accessory. For instance, you might have service1.subtype = 'security_light' for one and service2.subtype = 'backlight' for the other.

You can also define custom Services by providing your own UUID for the type that you generate yourself. Custom Services can contain an arbitrary set of Characteristics, but Siri will likely not be able to work with these.

Hierarchy (view full)

Constructors

  • Parameters

    • displayName: string = ""
    • UUID: string
    • Optionalsubtype: string

    Returns Service

Properties

characteristics: Characteristic[] = []
displayName: string
iid: Nullable<number> = null
name: Nullable<string> = null
optionalCharacteristics: Characteristic[] = []
subtype?: string
UUID: string

Methods

  • Adds a new link to the specified service. The service MUST be already added to the SAME accessory.

    Parameters

    • service: Service

      The service this service should link to

    Returns void

  • Returns an id which uniquely identifies a service on the associated accessory. The serviceId is a concatenation of the UUID for the service (defined by HAP) and the subtype (could be empty) which is programmatically defined by the programmer.

    Returns string

    the serviceId

  • Removes a link to the specified service which was previously added with addLinkedService

    Parameters

    • service: Service

      Previously linked service

    Returns void

  • Marks the service as hidden

    Parameters

    • isHidden: boolean = true

      optional boolean (default true) if the service should be marked hidden

    Returns void

  • Sets this service as the new primary service. Any currently active primary service will be reset to be not primary. This will happen immediately, if the service was already added to an accessory, or later when the service gets added to an accessory.

    Parameters

    • isPrimary: boolean = true

      optional boolean (default true) if the service should be the primary service

    Returns void

Service Definitions

AccessCode: typeof AccessCode
AccessControl: typeof AccessControl
AccessoryInformation: typeof AccessoryInformation
AccessoryMetrics: typeof AccessoryMetrics
AccessoryRuntimeInformation: typeof AccessoryRuntimeInformation
AirPurifier: typeof AirPurifier
AirQualitySensor: typeof AirQualitySensor
AssetUpdate: typeof AssetUpdate
Assistant: typeof Assistant
AudioStreamManagement: typeof AudioStreamManagement
Battery: typeof Battery
CameraOperatingMode: typeof CameraOperatingMode
CameraRecordingManagement: typeof CameraRecordingManagement
CameraRTPStreamManagement: typeof CameraRTPStreamManagement
CarbonDioxideSensor: typeof CarbonDioxideSensor
CarbonMonoxideSensor: typeof CarbonMonoxideSensor
CloudRelay: typeof CloudRelay
ContactSensor: typeof ContactSensor
DataStreamTransportManagement: typeof DataStreamTransportManagement
Diagnostics: typeof Diagnostics
Door: typeof Door
Doorbell: typeof Doorbell
Fan: typeof Fan
Fanv2: typeof Fanv2
Faucet: typeof Faucet
FilterMaintenance: typeof FilterMaintenance
FirmwareUpdate: typeof FirmwareUpdate
GarageDoorOpener: typeof GarageDoorOpener
HeaterCooler: typeof HeaterCooler
HumidifierDehumidifier: typeof HumidifierDehumidifier
HumiditySensor: typeof HumiditySensor
InputSource: typeof InputSource
IrrigationSystem: typeof IrrigationSystem
LeakSensor: typeof LeakSensor
Lightbulb: typeof Lightbulb
LightSensor: typeof LightSensor
LockManagement: typeof LockManagement
LockMechanism: typeof LockMechanism
Microphone: typeof Microphone
MotionSensor: typeof MotionSensor
NFCAccess: typeof NFCAccess
OccupancySensor: typeof OccupancySensor
Outlet: typeof Outlet
Pairing: typeof Pairing
PowerManagement: typeof PowerManagement
ProtocolInformation: typeof ProtocolInformation
SecuritySystem: typeof SecuritySystem
ServiceLabel: typeof ServiceLabel
Siri: typeof Siri
SiriEndpoint: typeof SiriEndpoint
Slats: typeof Slats
SmartSpeaker: typeof SmartSpeaker
SmokeSensor: typeof SmokeSensor
Speaker: typeof Speaker
StatefulProgrammableSwitch: typeof StatefulProgrammableSwitch
StatelessProgrammableSwitch: typeof StatelessProgrammableSwitch
Switch: typeof Switch
TapManagement: typeof TapManagement
TargetControl: typeof TargetControl
TargetControlManagement: typeof TargetControlManagement
Television: typeof Television
TelevisionSpeaker: typeof TelevisionSpeaker
TemperatureSensor: typeof TemperatureSensor
Thermostat: typeof Thermostat
ThreadTransport: typeof ThreadTransport
TransferTransportManagement: typeof TransferTransportManagement
Tunnel: typeof Tunnel
Valve: typeof Valve
WiFiRouter: typeof WiFiRouter
WiFiSatellite: typeof WiFiSatellite
WiFiTransport: typeof WiFiTransport
Window: typeof Window
WindowCovering: typeof WindowCovering