ESPCDFDevice
ESPCDFDevice is one logical device on a node (for example Light, Fan, Switch). Use it when you render a device card or refresh params for a single device slice of the node tree.
Devices are nested under ESPCDFNode.devices. They are created by adaptors during node transformation — not instantiated in UI code.
getParams is the main operation; param read/write usually goes through ESPCDFDeviceParam.
Properties
| Property | Type | Description |
|---|---|---|
name | string | Device name in node config |
type | optional | e.g. esp.device.lightbulb |
displayName | optional | UI label |
params | ESPCDFDeviceParam[] | Observable param entities |
attributes | optional | Static device attributes |
operations | ESPCDFDeviceOperation | SDK delegates |
_raw | any | Original SDK device |
events | ESPCDFOperationEventEmitter | Operation bus |
Common Workflows
Walk the device tree on a node
import { initCDF } from "@espressif/rainmaker-base-cdf";
const espCDF = await initCDF({ sdkAdaptorRegistry });
const node = espCDF.nodeStore.getNodeById("node-id");
for (const device of node?.devices ?? []) {
console.log(device.name, device.type, device.displayName);
for (const param of device.params) {
console.log(" ", param.name, param.value);
}
}
Refresh params
const device = node!.devices!.find((d) => d.name === "Light")!;
const params = await device.getParams();
Toggle a param
Prefer ESPCDFDeviceParam.setValue for single-param updates:
const power = device.params.find((p) => p.name === "Power");
await power?.setValue(true);
Or set multiple params on the parent node:
await node!.setMultipleParams({ Light: { Power: true, Brightness: 80 } });
Error Handling
try {
await device.getParams();
} catch (e) {
showErrorBanner("Failed to refresh device state");
}