hap-fluent / createServicesObject
Function: createServicesObject()
ts
function createServicesObject<T>(...services): ServicesObject<T>;Defined in: packages/hap-fluent/src/AccessoryHandler.ts:184
Build a strongly-typed service map by wrapping an array of service instances.
Type Parameters
| Type Parameter |
|---|
T extends Interfaces[] |
Parameters
| Parameter | Type | Description |
|---|---|---|
...services | InstanceType<ServiceForInterface<T[number]>>[] | HAP Service instances to wrap. Order is preserved. |
Returns
An object keyed by camelCase service names, typed as ServicesObject<T>.
Remarks
Each service is wrapped with wrapService and stored under both its camelCase name (primary, enumerable) and PascalCase name (non-enumerable alias for backward compatibility). When a service has a subtype, the entry becomes a { primary, [subTypeName] } object rather than a flat FluentService.
Use When
- You want to build a services map from
platformAccessory.servicesdirectly, e.g., in aconfigureAccessory()restore path.
Avoid When
- You are initializing an accessory from scratch with initial state — use initializeAccessory which combines
createServicesObjectandapplyInitialStatein a single call.
Example
typescript
import { createServicesObject } from 'hap-fluent';
const services = createServicesObject(...accessory.services);
services.lightbulb.onGet('on', async () => getState());