-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusb-switch.js
71 lines (65 loc) · 2.12 KB
/
usb-switch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const {
identify,
onOff,
} = require("zigbee-herdsman-converters/lib/modernExtend");
const exposes = require("zigbee-herdsman-converters/lib/exposes");
const reporting = require("zigbee-herdsman-converters/lib/reporting");
const utils = require("zigbee-herdsman-converters/lib/utils");
const e = exposes.presets;
const ea = exposes.access;
const channelValues = ["ch_1", "ch_2"];
const switchLocalInput = {
cluster: "genMultistateValue",
type: ["readResponse", "attributeReport"],
convert: (model, msg, publish, options, meta) => {
const presentValue = msg.data["presentValue"];
const action = channelValues[presentValue];
const property = "channel";
return {
[property]: `${action}`,
};
},
};
const switchLocalOutput = {
key: ["channel"],
convertSet: async (entity, key, value, meta) => {
utils.assertString(value, key);
await entity.write(
"genMultistateValue",
{ presentValue: channelValues.indexOf(value) },
utils.getOptions(meta.mapped, entity)
);
return { state: { channel: value } };
},
convertGet: async (entity, key, meta) => {
await entity.read("genMultistateValue", ["presentValue"]);
},
};
const bind = async (endpoint, target, clusters) => {
for (const cluster of clusters) {
await endpoint.bind(cluster, target);
}
};
const definition = {
zigbeeModel: ["zigbee-usb-switch"],
model: "zigbee-usb-switch",
vendor: "KONQI",
description: "konqi's homebrew usb-switch extension",
fromZigbee: [switchLocalInput],
toZigbee: [switchLocalOutput],
exposes: [e.enum("channel", ea.ALL, channelValues)],
extend: [identify(), onOff({ powerOnBehavior: false })],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(10);
// await endpoint.read("genMultistateValue", ["presentValue"]);
await endpoint.bind("genMultistateValue", coordinatorEndpoint);
await endpoint.configureReporting("genMultistateValue", {
attribute: "presentValue",
minimumReportInterval: 0,
maximumReportInterval: 3600,
reportableChange: 1,
});
},
meta: {},
};
module.exports = definition;