import type { ESPRMNode } from "@espressif/rainmaker-base-sdk"; import type { ESPNodeUpdateData, ESPSubscriptionChannelInterface } from "../../types/subscription"; /** * Interface for Matter local control adapter. * Platform implementations must provide this adapter to enable Matter local control. * * The adapter handles the platform-specific Matter communication layer * (e.g., using @matter/main, react-native-matter, or platform-specific Matter SDKs). */ export interface ESPMatterAdapter { /** * Subscribe to attribute updates from a Matter device. * * @param nodeId - The Rainmaker node ID * @param fabricId - The Matter fabric ID * @param callback - Function to call when attribute updates are received * @returns Promise that resolves when subscription is active * * @example * ```typescript * await adapter.subscribeToDevice( * "node-123", * "fabric-456", * (update) => { * console.log("Matter update:", update); * } * ); * ``` */ subscribeToDevice(nodeId: string, fabricId: string, callback: (update: MatterDeviceUpdate) => void): Promise; /** * Unsubscribe from attribute updates for a specific device. * * @param nodeId - The Rainmaker node ID * @param fabricId - The Matter fabric ID * @returns Promise that resolves when unsubscription is complete */ unsubscribeFromDevice(nodeId: string, fabricId: string): Promise; /** * Check if a device is currently reachable on the local network. * * @param nodeId - The Rainmaker node ID * @param fabricId - The Matter fabric ID * @returns Promise that resolves to true if device is reachable */ isDeviceReachable(nodeId: string, fabricId: string): Promise; /** * Initialize the Matter adapter. * This should set up the Matter controller and any necessary connections. * * @returns Promise that resolves when initialization is complete */ initialize(): Promise; /** * Cleanup and dispose of Matter adapter resources. * * @returns Promise that resolves when disposal is complete */ dispose(): Promise; } /** * Matter device update data from the platform-specific Matter SDK. * This represents raw Matter attribute updates that will be transformed * to the standard ESPNodeUpdateData format. */ export interface MatterDeviceUpdate { /** * Matter endpoint ID (e.g., 1 for the main device endpoint) */ endpointId: number; /** * Matter cluster ID (e.g., 6 for OnOff cluster, 8 for LevelControl) */ clusterId: number; /** * Matter attribute ID (e.g., 0 for OnOff attribute) */ attributeId: number; /** * The attribute value */ value: any; /** * Optional timestamp of the update */ timestamp?: number; /** * Optional metadata from the Matter layer */ metadata?: Record; } /** * Function type for resolving fabric ID from node ID. * This allows the channel to look up fabric information from the ESPRMMatterBase instance. */ export type FabricIdResolver = (nodeId: string) => Promise; /** * Subscription channel for Matter local control. * Provides device parameter updates via Matter protocol for local network communication. * * This channel: * - Supports nodes whose type is `pure_matter` / `rainmaker_matter` or that carry Matter metadata * - Delegates to a platform-specific {@link ESPMatterAdapter} for the native Matter layer * - Transforms raw Matter attribute updates into the standard {@link ESPNodeUpdateData} format * * @example * ```typescript * const matterChannel = new MatterSubscriptionChannel(matterAdapter, fabricIdResolver); * await ESPRMBase.subscriptionManager.registerChannel(matterChannel); * ESPRMBase.subscriptionManager.setGlobalChannelOrder(["matter", "notification"]); * ``` */ export declare class MatterSubscriptionChannel implements ESPSubscriptionChannelInterface { readonly channelId: "matter"; /** * Platform-specific Matter adapter */ private adapter; /** * Function to resolve fabric ID from node ID */ private fabricIdResolver?; /** * Map of callbacks for specific nodes (nodeId -> Set of callbacks) */ private callbacks; /** * Map to track subscribed nodes (nodeId -> fabricId) */ private subscribedNodes; /** * Set to track nodes currently being subscribed (prevents race conditions) */ private subscribingNodes; /** * Whether the channel has been initialized */ private isInitialized; /** * Create a new Matter subscription channel. * * @param adapter - Platform-specific Matter adapter implementation * @param fabricIdResolver - Optional function to resolve fabric ID from node ID */ constructor(adapter: ESPMatterAdapter, fabricIdResolver?: FabricIdResolver); /** * Set the fabric ID resolver function. * This is typically called by ESPRMMatterBase after construction. * * @param resolver - Function to resolve fabric ID from node ID */ setFabricIdResolver(resolver: FabricIdResolver): void; /** * Initialize the Matter channel. * Sets up the Matter adapter and prepares for device subscriptions. */ initialize(): Promise; /** * Check if this channel supports a specific node. * * A node is treated as Matter-capable when it carries concrete evidence the * channel can actually target — i.e. it is constructed as an * {@link ESPRMMatterNode} (canonical `isMatter` marker), or it has a * RainMaker API `metadata.Matter` payload, or it has an explicit Matter * Node ID in metadata. * * The cloud `node_type` field is not consulted on its own because non-Matter * RainMaker nodes can carry stale `node_type` values that incorrectly claim * a Matter channel and produce spurious `no matterNodeId for rmNodeId=…` * warnings on every `subscribeToAllNodes` pass. * * @param node - The node to check support for * @returns true if the node has actionable Matter capability */ supportsNode(node: ESPRMNode): boolean; /** * Subscribe to Matter attribute updates for a specific node. * * Registers the callback immediately and initiates the underlying Matter * adapter subscription asynchronously. This non-blocking design allows * {@link ESPSubscriptionManager.subscribeToAllNodes} to process multiple * nodes without waiting for each adapter handshake to complete. * * Callbacks registered before the adapter subscription is ready will begin * receiving updates as soon as the subscription is established. * * @param callback - Function to call when updates are received * @param nodeId - Node ID to subscribe to (required for Matter) * @throws Error if nodeId is not provided */ subscribe(callback: (update: ESPNodeUpdateData) => void, nodeId?: string): Promise; /** * Unsubscribe from Matter updates for a specific node. * * @param nodeId - Node ID to unsubscribe from */ unsubscribe(nodeId?: string): Promise; /** * Cleanup and dispose of Matter channel resources. */ dispose(): Promise; /** * Get the fabric ID for a node. * This extracts the fabric ID from the node's group metadata. * * @param nodeId - The node ID * @returns Promise that resolves to the fabric ID * @throws Error if fabric ID cannot be determined */ private getFabricIdForNode; /** * Handle raw Matter attribute updates, transform them to the standard * {@link ESPNodeUpdateData} format, and dispatch to registered callbacks. */ private handleMatterUpdate; /** * Transform Matter attribute updates to Rainmaker parameter format. * * Mapping: * - OnOff cluster (6), attr 0 -> Power (boolean) * - LevelControl cluster (8), attr 0 -> Brightness (0-100 %) * - ColorControl cluster (768) -> Hue / Saturation / CCT * - TemperatureMeasurement (1026) -> Temperature (degrees C) */ private transformMatterToRainmaker; }