/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Behavior } from "#behavior/Behavior.js"; import { ClusterBehavior } from "#behavior/cluster/ClusterBehavior.js"; import { BehaviorBacking } from "#behavior/internal/BehaviorBacking.js"; import { Datasource } from "#behavior/state/managed/Datasource.js"; import { Diagnostic, Immutable, Lifecycle, MaybePromise } from "@matter/general"; import { ClusterTypeProtocol, Val } from "@matter/protocol"; import type { ClusterId } from "@matter/types"; import type { Agent } from "../Agent.js"; import type { Endpoint } from "../Endpoint.js"; import type { SupportedBehaviors } from "./SupportedBehaviors.js"; export interface SupportedElements { features: Set; attributes: Set; commands: Set; events: Set; } /** * This class manages {@link Behavior} instances owned by a {@link Endpoint}. */ export declare class Behaviors { #private; [Diagnostic.value]: Diagnostic[]; /** * The {@link SupportedBehaviors} of the {@link Endpoint}. */ get supported(): SupportedBehaviors; /** * Obtain the specific {@link Behavior.Type} used by the endpoint for implementation if the endpoint supports * {@link type}. */ typeFor(type: T): T | undefined; /** * Obtain the {@link ClusterBehavior.Type} the endpoint uses to implement a given cluster, if supported. */ forCluster(clusterId: ClusterId): ClusterBehavior.Type | undefined; /** * The list of active behaviors. */ get active(): Behavior.Type[]; get status(): Record; get detailedDiagnostic(): Diagnostic[][]; constructor(endpoint: Endpoint, options: Record); /** * Activate any behaviors designated for immediate activation. Returns a promise iff any behaviors have ongoing * initialization. * * Throws an error if any behavior crashes, but we allow all behaviors to settle before throwing. The goal is to * surface multiple configuration errors and prevent inconsistent state caused by partial initialization. */ initialize(): MaybePromise; /** * Does the {@link Endpoint} support a specified behavior? */ has(type: T): boolean; /** * Does the {@link Endpoint} support a specified behavior by its behavior Id? */ has(typeId: string): boolean; /** * Add behavior support dynamically at runtime. Typically called via {@link Agent.require}. */ require(type: T, options?: Behavior.Options): void; /** * Create a behavior synchronously. Fails if the behavior is not fully initialized. */ createSync(type: Behavior.Type, agent: Agent): Behavior; /** * Create a behavior asynchronously. Waits for the behavior to complete initialization. */ createAsync(type: Behavior.Type, agent: Agent): Promise; /** * Create a behavior, possibly asynchronously. * * This method returns a {@link Promise} only if await is necessary so the behavior can be used immediately if * possible. */ createMaybeAsync(type: Behavior.Type, agent: Agent): MaybePromise; /** * Activate a behavior. * * Semantically identical to createAsync() but does not return a {@link Promise} or throw an error. * * Behaviors that fail initialization will be marked with crashed {@link status}. */ activate(type: Behavior.Type, agent: Agent): void; /** * Determine if a specified behavior is supported and active. */ isActive(type: Behavior.Type | string): boolean; /** * Destroy all behaviors that are initialized (have backings present). The object may be reused after close. */ close(): Promise; /** * Add support for an additional behavior. * * This should generally only be used prior to initialization. It may cause subtle errors if incompatible types are * injected once the endpoint is initialized. */ inject(type: Behavior.Type, options?: Behavior.Options, notify?: boolean): void; /** * Drop support for a behavior. * * This is intended for synchronization with peers and should not be used for servers as Matter does not allow an * endpoint to change its set of supported clusters. */ drop(id: string): MaybePromise; /** * Obtain default values for a behavior. This is state values as present when the behavior is first initialized for * a new endpoint. */ defaultsFor(type: Behavior.Type): Val.Struct | undefined; /** * Retrieve the options for a behavior type provided to the endpoint. */ optionsFor(type: Behavior.Type): object | undefined; /** * Access internal state for a {@link Behavior}. * * Internal state is not a stable API and not intended for consumption outside the behavior. However, it is not * truly private and may be accessed by tightly coupled implementation. * * As this API is intended for use by "friendly" code, it does not perform the same initialization assertions as * does access to {@link Behavior.State} and {@link Behavior.Events}. */ internalsOf(type: T): InstanceType; /** * Obtain current data version of behavior. */ versionOf(type: Behavior.Type): number; /** * Obtain current data version of behavior by its behavior Id, if existing */ versionOf(typeId: string): number | undefined; /** * @throws ImplementationError if the behavior is not supported. */ backingFor(type: Behavior.Type): BehaviorBacking; /** * Access elements supported by a behavior. */ elementsOf(type: Behavior.Type): SupportedElements; /** * Access the state view of a behavior if loaded. */ maybeStateOf(behaviorId: string): Immutable | undefined; [Symbol.iterator](): ArrayIterator; /** * Create a read-only online view of a behavior. */ createOnlineView(type: Behavior.Type): Datasource; } export declare namespace Behaviors { interface ProtocolContext { descriptor: ClusterTypeProtocol; datasource: Datasource; } } //# sourceMappingURL=Behaviors.d.ts.map