鸿蒙HarmonyOS SDK
设备管理
编辑设备

编辑设备

修改别名和备注

使用统一设备对象:

await device.updateDeviceInfo('客厅灯', '一楼');

或使用用户管理器与 Device ID:

await userManager.updateDeviceInfo(deviceId, '客厅灯', '一楼');

读取设备资料和状态

const name: string = device.getName();
const remark: string = device.getRemark();
const deviceId = device.subscribeDeviceId().getValue();
const isBound: boolean = device.subscribeBoundState().getValue();
const snapshot = device.toJsonObject();

修改成功后,统一设备对象和绑定设备列表会同步更新。需要响应后续变化时,应订阅对应 GizState,而不是只保存一次快照。