// 处理来自集中供液系统的数据
|
const deviceId = "central_liquid_supply";
|
const topic = msg.topic;
|
const value = msg.payload;
|
|
// 根据 topic 确定实体类型和 ID
|
let entityType = "sensor";
|
let entityId = "";
|
let stateTopic = "";
|
|
if (topic.includes("温度")) {
|
entityId = "temperature";
|
stateTopic = `${deviceId}/sensor/${entityId}/state`;
|
} else if (topic.includes("PH")) {
|
entityId = "ph_value";
|
stateTopic = `${deviceId}/sensor/${entityId}/state`;
|
} else if (topic.includes("电导率")) {
|
entityId = "conductivity";
|
stateTopic = `${deviceId}/sensor/${entityId}/state`;
|
} else if (topic.includes("配液当前液位")) {
|
entityId = "mixing_level";
|
stateTopic = `${deviceId}/sensor/${entityId}/state`;
|
} else if (topic.includes("储液当前液位")) {
|
entityId = "storage_level";
|
stateTopic = `${deviceId}/sensor/${entityId}/state`;
|
} else if (topic.includes("供液一压力")) {
|
entityId = "supply_pressure_1";
|
stateTopic = `${deviceId}/sensor/${entityId}/state`;
|
} else if (topic.includes("供液二压力")) {
|
entityId = "supply_pressure_2";
|
stateTopic = `${deviceId}/sensor/${entityId}/state`;
|
} else if (topic.includes("工作状态")) {
|
entityType = "binary_sensor";
|
entityId = "work_status";
|
stateTopic = `${deviceId}/binary_sensor/${entityId}/state`;
|
} else if (topic.includes("报警状态")) {
|
entityType = "binary_sensor";
|
entityId = "alarm_status";
|
stateTopic = `${deviceId}/binary_sensor/${entityId}/state`;
|
} else {
|
node.warn(`未知的数据类型: ${topic}`);
|
return null;
|
}
|
|
// 记录数据处理信息
|
node.warn(`处理数据: ${topic} = ${value} -> ${stateTopic}`);
|
|
// 创建输出消息
|
const outputMsg = {
|
topic: stateTopic,
|
payload: String(value),
|
retain: false
|
};
|
|
return outputMsg;
|