SmartDeviceModel(options?: SmartDeviceModelOptions)

Requires:
@ray-js/panel-sdk≥1.0.0
Additional notesRead the full notes
All DP-related API types are inferred at compile time by the generic S (ReadonlyDpSchemaList).
S comes from the Schema constant declared with as const in the business project's devices/schema.ts. Mapping from Schema property.type to TypeScript types:
- bool → boolean (true/false)
- value → number (runtime-constrained by property.min/max/step; the type is number only)
- enum → props are string; publishDps parameters are a literal union of property.range (e.g., 'white' | 'colour')
- bitmap → number (bitwise value; use actions on(idx)/off(idx) to specify bit positions)
- string → string
- raw (outer type='raw') → string
Schema must use the as const assertion; otherwise literal type inference degrades.

Description

Smart device model that provides DP state management, event listening, and command publishing

Parameters

ParameterTypeRequiredDescription
NoDevice model initialization config, including abilities (advanced capabilities) and interceptors (event interceptors)

Return Value

Type: SmartDeviceModel
SmartDeviceModel instance

Referenced Types

typeInitDpStateInterceptor
export type InitDpStateInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = InitDpStateInterceptorParams
> = Interceptor<S, P, InitDpStateInterceptorParams>;
typeInitDevInfoInterceptor
export type InitDevInfoInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = {
    devInfo: GetSmartDeviceModelDevInfo<any>;
    action: InitDevInfoInterceptorAction;
  }
> = Interceptor<
  S,
  P,
  {
    devInfo: GetSmartDeviceModelDevInfo<any>;
    action: InitDevInfoInterceptorAction;
  }
>;
typeOnDpDataChangeInterceptor
export type OnDpDataChangeInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = DpDataChangeParams
> = Interceptor<S, P, DpDataChangeParams>;
typeOnDeviceOnlineStatusUpdateInterceptor
export type OnDeviceOnlineStatusUpdateInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = DeviceOnlineStatusUpdateParams
> = Interceptor<S, P, DeviceOnlineStatusUpdateParams>;
typeOnDeviceInfoUpdatedInterceptor
export type OnDeviceInfoUpdatedInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = DeviceInfoUpdatedParams
> = Interceptor<S, P, DeviceInfoUpdatedParams>;
typeOnNetworkStatusChangeInterceptor
export type OnNetworkStatusChangeInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = NetworkStatusChangeParams
> = Interceptor<S, P, NetworkStatusChangeParams>;
typeOnBluetoothAdapterStateChangeInterceptor
export type OnBluetoothAdapterStateChangeInterceptor<
  S extends ReadonlyDpSchemaList = any,
  P = BluetoothAdapterStatusChangeParams
> = Interceptor<S, P, BluetoothAdapterStatusChangeParams>;
typeInitDpStateInterceptorParams
PropertyTypeRequiredDescription
YesCurrent device DP state
YesNew device DP state
action"init" | "onDpDataChange" | "onDeviceInfoUpdated" | "dp-kit"YesInterceptor action
typeGetSmartDeviceModelDevInfo
PropertyTypeRequiredDescription
dpCodesobjectYes
dpsobjectYes
idCodesobjectYes
codeIdsobjectYes
schemaSYes
typeSmartDeviceModelAbilityContainer type for SmartDeviceModel abilities, used only for generic constraints and internal composition.
export type SmartDeviceModelAbility<A extends SmartDeviceAbility = SmartDeviceAbility> = {
  [abilityName: string]: A;
};
typePublishDpsOptionsUnderlying option type of publishDps, reused by the SDK’s internal request chain.
PropertyTypeRequiredDescription
No
typeDpValueDatapoint value type, which can be boolean, number, or string.
export type DpValue = boolean | number | string;
typeSendDpOptionDP send options. Can be used as the global default configuration for createDpKit, and can also be overridden in a single publishDps/action call. The global `sendDpOption` suits product-level defaults; options passed for a single send are suitable for temporarily overriding throttling, debouncing, protocol parsing, or optimistic update strategies. Note: requires the dp-kit interceptor.
PropertyTypeRequiredDescriptionSince
immediatebooleanNoWhether to trigger a state update immediately; requires the dp-kit interceptor-
NoWhether to ignore DP reports; default falsev1.11.0
NoWhether to sync dpData with cloud device properties; default falsev1.11.0
orderedbooleanNoWhether to send multiple DPs in the order of the object’s keys; requires the dp-kit interceptor; default false-
checkRepeatbooleanNoWhether to check for duplicate values and skip sending; requires the dp-kit interceptor; default false
Compared with the current `dpState`; duplicates are detected and not sent
-
delaynumberNoDelayed send; requires the dp-kit interceptor; default 0, in ms-
throttlenumberNoSend throttling (conflicts with debounce); requires the dp-kit interceptor; default 0, in ms-
debouncenumberNoSend debounce (conflicts with throttle); requires the dp-kit interceptor; default 0, in ms-
NoA per-call DP protocol converter; requires the dp-kit interceptor.
The key is the dpCode and the value is a `{ parser, formatter }` object:
- parser(dpValue: string) => any — parses the raw DP string into a structured object
- formatter(parsedValue: any) => string — serializes the structured object into a DP string
Affects only this invocation and does not override the global protocols configuration in createDpKit
-
typeCapability
export type Capability = number;
typeDevAttribute
export type DevAttribute = number;

Valid Values

LogConfig.level
ValueDescriptionSince
VERBOSE--
SUCCESS--
INFO--
WARN--
FATAL--
DevInfo.schema.mode
ValueDescriptionSince
rw--
ro--
wr--
DevInfo.schema.property.type
ValueDescriptionSince
string--
bool--
value--
enum--
bitmap--
raw--
DevInfo.schema.type
ValueDescriptionSince
raw--
obj--
FunConfig.tyabirysr4_app
ValueDescriptionSince
follow--
--app-B1--
FunConfig.tyabis5d9w_app
ValueDescriptionSince
follow--
--app-M1--

Methods

MethodDescription
initReturn the instance after asynchronously initializing the smart device
onInitializedRegister a callback for the smart device model initialization-completed event
offInitializedCancel the smart device model initialization-completed event listener
getDevInfoGet smart device information, implemented based on ty.device.getDeviceInfo
getDpSchemaGet the smart device DP schema (function point) mapping
getDpStateGet smart device DP status
getNetworkGet the network status of the smart device’s environment
getBluetoothGet the Bluetooth status of the smart device’s environment
onDpDataChangeListen for smart device DP change events
onDeviceOnlineStatusUpdateListen for smart device online/offline status changes
onDeviceInfoUpdatedListen for smart device info change events (including changes to device name, DP names, etc.)
onNetworkStatusChangeListen for network status change events
onBluetoothAdapterStateChangeListen for Bluetooth adapter state change events
offDpDataChangeUnsubscribe from smart device DP change events
offDeviceOnlineStatusUpdateUnsubscribe from smart device online/offline status changes
offDeviceInfoUpdatedUnsubscribe from smart device info change events
offNetworkStatusChangeUnsubscribe from network status change events
offBluetoothAdapterStateChangeUnsubscribe from Bluetooth adapter state change events
publishDpsControl multiple smart device DPs in batch, built on top of ty.device.publishDps
queryDpsActively query device DP status (not supported for groups)
destroyDestroy the current smart device instance and all event listeners

Examples

Basic initialization.

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

type Schema = typeof defaultSchema;
const device = new SmartDeviceModel<Schema>();
await device.init();

// You can access device state after initialization
const props = device.getDpState();   // { switch_led: boolean, work_mode: string, ... }
const devInfo = device.getDevInfo(); // Device info