dp-kit
dp-kit added since @ray-js/panel-sdk@1.7.0
A lightweight toolkit for handling device-panel DP features, with built-in parsing for complex DP features, send option enhancements (sendOptions), and optimistic UI updates for complex DP scenarios.
When do you need dp-kit?
✅ Good fit:
- Your product has complex DP features, such as raw/string payloads like
colour_datathat need to be parsed intohue / saturation / value - You need throttling, debouncing, or delayed DP sending
- You want to update the UI immediately after sending (
immediatemode) - You need to ignore device report responses and synchronize DP state from the cloud
- You need custom logic before or after sending (
onBeforeSendDp/onAfterSendDp)
❌ Probably unnecessary:
- Your product only uses simple DP feature types (
bool / enum / value), anduseProps + useActionsis enough - You do not need any send-time enhancements
Integration Guide
Step 1: Configure the product DP schema file
src/devices/schema.ts
See Creating SDM
Step 2: Configure the complex DP parsing file (Optional)
src/devices/protocols.ts
- This step maps to the
protocolsfield in createDpKit and defines how complex DP payloads are parsed and formatted. Skip it if your product does not use complex DP data.
Step 3: Create dp-kit for your scenario
src/devices/index.ts
Step 4: Initialize complex DP protocol data (Optional)
src/app.tsx
- Integrate
dpKit.initto initialize complex DP protocol data. You can skip this if you do not use structured DP data.
Step 5: Integrate global type definitions (Optional)
typings/sdm.d.ts
- Refer to the latest template file: PublicSdmTemplate/typings/sdm.d.ts
- Replace the template imports such as
@/devices/schemaand@/devices/protocolswith the actual paths in your project - Skip this step if you do not need TS IntelliSense
Step 6: Read and send complex DP protocol data
src/pages/home/index.tsx
- Use
useStructuredPropsto read structured DP data - Use
useStructuredActionsto send structured DP data
API
For the complete createDpKit API reference and full type definitions, see createDpKit API.
The sections below focus on how each option is used in practice.
Complex DP parsing (Optional)
This section maps to the protocols field in createDpKit. Use it to describe how complex DP features should be parsed and formatted, so your business code no longer needs to deal with raw payload conversions.
If the payload shape is completely fixed, you can still use a shorter mapping-style config, but parser / formatter is usually easier to understand in tutorials.
Send options (sendOptions) (Optional)
These are the options used when sending DP features. In createDpKit, they correspond to the sendDpOption field and become the default behavior for later send calls.
For the full type definition, see createDpKit API > SendDpOption
ignoreDpDataResponse object fields:
synchronizeDevProperty object fields:
For example, if every send in your application should use a 600 ms throttle:
Or, if you want a DP feature to update immediately without waiting for a device report:
With immediate, the DP feature data injected by dp-kit will carry an extra __from__: dp-kit marker in SDM's internal onDataChange flow. This helps distinguish optimistic updates from real device reports. The original onDpDataChange event is not triggered.
If you only want to override a single send without waiting for a report:
Using only immediate still triggers one more update when the device report arrives, which can cause UI flicker. If you want to ignore the device report response entirely:
If some DP features should still respond, use a whitelist:
You can also configure a timeout:
Or define a custom rule with the highest priority:
When device report responses are ignored, the previous state will not be available after exiting and re-entering the panel. Use synchronizeDevProperty to restore DP state from the cloud:
Every send writes the DP state into cloud device properties. When the panel opens again, dp-kit performs one initialization pass and restores the DP state from the cloud.
You can also exclude specific DP features from synchronization:
When cloud data is empty, you can define a default state:
onBeforeSendDp / onAfterSendDp (Optional)
Hooks that run before and after publishDps. Passing SmartDeviceSchema is recommended so the hook receives the correct type.
Further Reading
logger interceptor
dp-kit ships well with the built-in logger interceptor for inspecting DP sends and reports in the console.
matter-kit interceptor
If you also need to handle Matter devices, pair dp-kit with matter-kit.
SmartDeviceModel guide
dp-kit is built on top of the SmartDeviceModel interceptor mechanism.
Using SDM interceptors and custom DP protocol parsing
A tutorial showing custom interceptors and custom protocol parsing built on top of dp-kit.
Beacon panel template
A tutorial that builds a Beacon panel with dp-kit built-in capabilities.