zigbee-herdsman-zigate
Version:
An open source ZigBee gateway solution with node.js.
38 lines (30 loc) • 913 B
text/typescript
import {ZclFrame} from '../../zcl';
interface KeyValue {[s: string]: number | string}
function attributeKeyValue(frame: ZclFrame): KeyValue {
const payload: KeyValue = {};
for (const item of frame.Payload) {
try {
const attribute = frame.Cluster.getAttribute(item.attrId);
payload[attribute.name] = item.attrData;
} catch (error) {
payload[item.attrId] = item.attrData;
}
}
return payload;
}
function attributeList(frame: ZclFrame): Array<string | number> {
const payload: Array<string | number> = [];
for (const item of frame.Payload) {
try {
const attribute = frame.Cluster.getAttribute(item.attrId);
payload.push(attribute.name);
} catch (error) {
payload.push(item.attrId);
}
}
return payload;
}
export {
attributeKeyValue,
attributeList,
};