SDM interceptors
Custom interceptors and their type contracts are still experimental. You can use logger, dp-kit, and matter-kit directly, but if you implement your own interceptors, expect possible API adjustments in future versions.
interceptors let you insert shared logic into SDM initialization, DP sending, and event callback chains. They are useful for logging, protocol conversion, structured state mapping, and conditional short-circuiting.
When do you need interceptors?
✅ Good fit:
- You need shared logic, logging, or analytics before or after
publishDps - You need to convert raw device reports into business-friendly data
- You want to reuse
logger,dp-kit, ormatter-kit - Multiple pages depend on the same initialization or protocol processing logic
❌ Probably unnecessary:
- The logic is only for one page and does not need to be reused
- You only read simple DP features and
useProps / useActionsis enough - You do not need to change the SDM init, send, or event chains
How do you choose a built-in interceptor?
SDM mounts logger on built-in chains by default. But once you manually configure an interceptor array for a specific chain, that chain is replaced by your new array. If you still want logs, add logger back explicitly.
Integration guide
Step 1: Choose the interception point
Step 2: Mount interceptors on SmartDeviceModel
src/devices/index.ts
If you only use one built-in kit, you can also pass interceptors: dpKit.interceptors or interceptors: matterKit.interceptors directly.
Step 3: Order multiple interceptors correctly
- Interceptors in the same chain wrap in array order; earlier items receive the input first
- If an interceptor does not call
next(...), later interceptors and the underlying method will not run - When combining
dp-kitandmatter-kitforpublishDps,dp-kitusually goes first andmatter-kitsecond
Custom interceptors
Common types
For group scenarios, there are also
OnGroupDpDataChangeInterceptorandOnGroupInfoChangeInterceptor. This guide focuses on the most common single-device SDM chains.
Execution model
Interceptors use a three-layer curried shape: ctx => next => data.
Common patterns
1. Append or rewrite data before sending
2. Convert raw reports into business data
3. Short-circuit the rest of the chain
Further reading
logger
Integration details and the type definition of the default logging interceptor
dp-kit
Full guide to complex DP parsing,
sendOptions, and structured hooks
matter-kit
Matter lighting DP mapping and composition with other interceptors
SmartDeviceModel
interceptorsare ultimately mounted on SmartDeviceModel; see the API doc for the full initialization options