Skip to content

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

ParameterTypeDescription
...servicesInstanceType<ServiceForInterface<T[number]>>[]HAP Service instances to wrap. Order is preserved.

Returns

ServicesObject<T>

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.services directly, e.g., in a configureAccessory() restore path.

Avoid When

  • You are initializing an accessory from scratch with initial state — use initializeAccessory which combines createServicesObject and applyInitialState in a single call.

Example

typescript
import { createServicesObject } from 'hap-fluent';

const services = createServicesObject(...accessory.services);
services.lightbulb.onGet('on', async () => getState());

Released under the Apache-2.0 License.