---
name: "SmartDevicesManager"
mode: "api"
versionRequirements:
  - { name: "@ray-js/panel-sdk", version: "1.16.0" }
title: "constructor"
---

## SmartDevicesManager

> [VERSION] @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

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `options` | `{ logConfig?: LogConfig }` | No | Configuration options |

### Return Value

Type: `SmartDevicesManager`

SmartDevicesManager instance

#### Methods

| Method | Description |
| --- | --- |
| `init` | Start listening to global events (Ray global DP, online/offline, etc.); idempotent. |
| `on` | Subscribe 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). |
| `off` | Unsubscribe from multi-device manager change events. Pass the same event name and callback reference used with on. |
| `add` | Add 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. |
| `batchAdd` | Add 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. |
| `delete` | Delete a device instance. Removes the instance identified by key from the multi-device manager, automatically calls its destroy() and cleans up internal mappings. |
| `batchDelete` | Delete 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. |
| `getDevices` | Get 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. |
| `isAllInitialized` | Check whether all added devices have finished initialization |
| `destroy` | Destroy the multi-device manager: unregister all global event listeners, remove all change subscriptions, and destroy/clean up all device instances and internal mappings. |

### Referenced Types

##### `type` LogConfig

Logging configuration

| Property | Type | Description |
| --- | --- | --- |
| `level` | `"VERBOSE" \| "SUCCESS" \| "INFO" \| "WARN" \| "FATAL"` | Log output level, default INFO. To suppress the default printing of each DP send/report, set it to WARN or higher |


### Examples

#### Create a multi-device manager

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