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

## SmartGroupModel

> [VERSION] @ray-js/panel-sdk >= 1.5.0

> 💡 All DP-related API types are inferred at compile time from the generic S (ReadonlyDpSchemaList). S comes from the Schema constant declared with as const in devices/schema.ts of your project. Mapping from Schema property.type to TypeScript types: - bool → boolean (true/false); - value → number (constrained at runtime by property.min/max/step; type is number only); - enum → props are string; the publishDps parameter is the literal union of property.range (e.g., 'white' \| 'colour'); - bitmap → number (bitwise value; specify the bit position with actions on(idx)/off(idx)); - string → string; - raw (outer type='raw') → string. Similar to SmartDeviceModel, but dedicated for group-device scenarios. Group devices share the same DP Schema, and control commands are sent to all devices in the group. The Schema must use the as const assertion; otherwise, literal type inference degrades.

### Description

Smart group device model that provides core capabilities such as DP state management, event listening, and command dispatch for group devices

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `options` | `SmartGroupModelOptions` | No | Group model initialization options, including abilities (advanced capability list) and interceptors (event interceptors), among other options |

### Return Value

Type: `SmartGroupModel`

SmartGroupModel instance

#### Methods

| Method | Description |
| --- | --- |
| `init` | Asynchronously initialize the smart group and then return its instance |
| `onInitialized` | Register a callback for the smart group model initialized event |
| `offInitialized` | Remove the listener for the smart group model initialized event |
| `getDevInfo` | Get the first device information under the smart group and the data merged with the group |
| `getGroupInfo` | Get smart group information |
| `getDpSchema` | Get the DP Schema (DP capability descriptions) mapping table for the smart group |
| `getDpState` | Get smart group DP states |
| `getNetwork` | Get the network status of the environment the smart group is in |
| `getBluetooth` | Get the Bluetooth status of the environment the smart group is in |
| `onDpDataChange` | Listen for DP change events in group devices |
| `onDeviceOnlineStatusUpdate` | Listen for smart group online status changes |
| `onDeviceInfoUpdated` | Listen for smart group device info change events |
| `onGroupDpDataChangeEvent` | Listen for DP change events in group devices |
| `onGroupInfoChange` | Listen for smart group info change events |
| `onNetworkStatusChange` | Listen for network status change events |
| `onBluetoothAdapterStateChange` | Listen for Bluetooth adapter state change events |
| `offDpDataChange` | Stop listening for smart group DP change events |
| `offDeviceOnlineStatusUpdate` | Unsubscribe from smart group online status changes |
| `offDeviceInfoUpdated` | Unsubscribe from smart group device info change events |
| `offGroupDpDataChangeEvent` | Stop listening for group device DP change events |
| `offGroupInfoChange` | Stop listening for smart group info change events |
| `offNetworkStatusChange` | Stop listening for network status change events |
| `offBluetoothAdapterStateChange` | Stop listening for Bluetooth adapter state change events |
| `publishDps` | Batch control smart group DPs |
| `queryDps` | Actively query device DP state (not supported for groups) |
| `destroy` | Destroy the current smart group instance and all event listeners |

### Referenced Types

##### `type` SmartGroupModelOptions

| Property | Type | Description |
| --- | --- | --- |
| `groupId` | `string` | Group ID, optional; defaults to auto-fetching from the Mini Program launch parameters |


### Examples

#### Basic initialization.

```typescript
import { SmartGroupModel } from '@ray-js/panel-sdk';
import { defaultSchema } from './devices/schema';

type Schema = typeof defaultSchema;
const group = new SmartGroupModel<Schema>();
await group.init();

// After initialization, you can access the group state
const props = group.getDpState();      // { switch_led: boolean, work_mode: string, ... }
const groupInfo = group.getGroupInfo(); // Group info
```
