/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { DeviceClassification } from "@matter/model"; import { DeviceTypeId } from "@matter/types"; import { SupportedBehaviors } from "../properties/SupportedBehaviors.js"; import { SupportedClientClusters } from "../properties/SupportedClientClusters.js"; /** * An EndpointType defines functionality for an endpoint. */ export interface EndpointType { name: string; deviceType: DeviceTypeId; deviceRevision: number; deviceClass: DeviceClassification; behaviors: SupportedBehaviors; clientClusters: SupportedClientClusters; requirements: EndpointType.Requirements; } /** * Define a new type of endpoint. */ export function EndpointType(options: T) { return { ...options, deviceClass: options.deviceClass ?? DeviceClassification.Simple, behaviors: options.behaviors ?? {}, clientClusters: options.clientClusters ?? {}, requirements: options.requirements ?? {}, } as unknown as EndpointType.For; } const DEVICE_CLASSIFICATIONS: ReadonlySet = new Set( Object.values(DeviceClassification).filter(value => typeof value === "string"), ); export namespace EndpointType { export const UNKNOWN_DEVICE_TYPE = DeviceTypeId(-1, false); export const UNKNOWN_DEVICE_REVISION = -1; /** * Is {@link value} shaped like an {@link EndpointType}? */ export function is(value: unknown): value is EndpointType { return ( typeof value === "object" && value !== null && "name" in value && typeof value.name === "string" && "deviceType" in value && typeof value.deviceType === "number" && "deviceRevision" in value && typeof value.deviceRevision === "number" && "deviceClass" in value && typeof value.deviceClass === "string" && DEVICE_CLASSIFICATIONS.has(value.deviceClass) && "behaviors" in value && typeof value.behaviors === "object" && value.behaviors !== null && "clientClusters" in value && typeof value.clientClusters === "object" && value.clientClusters !== null && "requirements" in value && typeof value.requirements === "object" && value.requirements !== null ); } /** * An endpoint type with no behaviors, client clusters, or requirements. */ export interface Empty extends Omit { behaviors: {}; clientClusters: {}; requirements: {}; } /** * A fully typed {@link EndpointType} defined by {@link EndpointType.Options}. */ export type For = { name: T["name"]; deviceType: DeviceTypeId; deviceRevision: number; deviceClass: DeviceClassification; behaviors: T["behaviors"] extends SupportedBehaviors ? T["behaviors"] : {}; clientClusters: T["clientClusters"] extends SupportedClientClusters ? T["clientClusters"] : {}; requirements: T["requirements"] extends Requirements ? T["requirements"] : {}; }; /** * Endpoint configuration. */ export interface Options { name: string; deviceType: number; deviceRevision: number; deviceClass?: DeviceClassification; behaviors?: SupportedBehaviors; clientClusters?: SupportedClientClusters; requirements?: Requirements; } /** * Standard dependencies for an endpoint per the Matter specification. */ export interface Requirements { server?: { mandatory?: SupportedBehaviors; optional?: SupportedBehaviors; }; client?: { mandatory?: SupportedBehaviors; optional?: SupportedBehaviors; }; } }