SmartDevicesManager(options?: { logConfig?: LogConfig })

Requires:
@ray-js/panel-sdk≥1.16.0

Description

Multi-device manager: centrally manages multiple device instances, responsible for batch initialization, global event routing, global state caching, and standardized operations such as add / batchAdd / delete. The constructor itself is side-effect free and registers no global listeners.

Parameters

ParameterTypeRequiredDescription
options{ logConfig?: LogConfig }NoConfiguration options

Return Value

Type: SmartDevicesManager
SmartDevicesManager instance

Referenced Types

typeLogConfigLogging configuration
PropertyTypeRequiredDescription
level"VERBOSE" | "SUCCESS" | "INFO" | "WARN" | "FATAL"NoLog output level, default INFO. To suppress the default printing of each DP send/report, set it to WARN or higher

Methods

MethodDescription
initStart listening to global events (Ray global DP, online/offline, etc.); idempotent.
onSubscribe to multi-device manager change events. Inside SdmProvider, multi-device Hooks are already refreshed via the change event, so manual listeners are usually unnecessary. Use only to observe device state changes outside the Provider (e.g., global logging, non-React components).
offUnsubscribe from multi-device manager change events. Pass the same event name and callback reference used with on.
addAdd a single device instance and complete initialization. If init() has not been called, it will auto-init first for backward compatibility. Typically used to dynamically add one associated device; throws an error if the deviceId already exists.
batchAddAdd device instances to the multi-device manager in bulk. It first fetches device info in batch (a single network request), then initializes concurrently according to concurrency; partial failures are supported and the result distinguishes success and failure lists. Each device can configure interceptors and logConfig independently.
deleteDelete a device instance. Removes the instance identified by key from the multi-device manager, automatically calls its destroy() and cleans up internal mappings.
batchDeleteDelete device instances for the specified list of keys in the multi-device manager. Internally calls delete({ key }) for each key, automatically destroying instances and cleaning up internal mappings.
getDevicesGet a shallow copy of all registered device instances, indexed by key. Commonly used when you need to operate on instances directly instead of via Hooks, e.g., iterating all devices inside an event callback.
isAllInitializedCheck whether all added devices have finished initialization
destroyDestroy the multi-device manager: unregister all global event listeners, remove all change subscriptions, and destroy/clean up all device instances and internal mappings.

Examples

Create a multi-device manager

const manager = new SmartDevicesManager();
manager.init();
manager.add({ key: 'lamp1', deviceId: '1234567890' });
manager.add({ key: 'lamp2', deviceId: '1234567891' });