Skip to content

Commit

Permalink
[Xiaomi wired switch] Parse operation mode response
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Feb 19, 2019
1 parent a81039a commit 37fb0cd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
38 changes: 38 additions & 0 deletions converters/fromZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,21 @@ const converters = {
}
},
},
QBKG04LM_operation_mode: {
cid: 'genBasic',
type: 'devChange',
convert: (model, msg, publish, options) => {
const mappingMode = {
0x12: 'control_relay',
0xFE: 'decoupled',
};
const key = '65314';
if (msg.data.data.hasOwnProperty(key)) {
let mode = mappingMode[msg.data.data[key]];
return {operation_mode: mode};
}
},
},
QBKG03LM_QBKG12LM_state: {
cid: 'genOnOff',
type: 'attReport',
Expand Down Expand Up @@ -837,6 +852,29 @@ const converters = {
}
},
},
QBKG03LM_operation_mode: {
cid: 'genBasic',
type: 'devChange',
convert: (model, msg, publish, options) => {
const mappingButton = {
'65314': 'left',
'65315': 'right',
};
const mappingMode = {
0x12: 'control_left_relay',
0x22: 'control_right_relay',
0xFE: 'decoupled',
};
for (let key in mappingButton) {
if (msg.data.data.hasOwnProperty(key)) {
const payload = {};
const mode = mappingMode[msg.data.data[key]];
payload[`operation_mode_${mappingButton[key]}`] = mode;
return payload;
}
}
},
},
xiaomi_lock_report: {
cid: 'genBasic',
type: 'attReport',
Expand Down
9 changes: 5 additions & 4 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,8 @@ const converters = {
}
},
},
xiaomi_decoupled_mode: {
key: ['decoupled_mode'],
xiaomi_switch_operation_mode: {
key: ['operation_mode'],
convert: (key, value, message, type, postfix) => {
const cid = 'genBasic';
const lookupAttrId = {
Expand All @@ -866,9 +866,10 @@ const converters = {
'right': 0xFF23,
};
const lookupState = {
'control_relay': 0x12,
'control_left_relay': 0x12,
'control_right_relay': 0x22,
'decoupled': 0xFE,
'toggle_left': 0x12,
'toggle_right': 0x22,
};
let button;
if (value.hasOwnProperty('button')) {
Expand Down
8 changes: 4 additions & 4 deletions devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ const devices = [
description: 'Aqara single key wired wall switch',
supports: 'on/off',
fromZigbee: [
fz.QBKG04LM_QBKG11LM_state, fz.ignore_onoff_change, fz.ignore_basic_change, fz.ignore_basic_report,
fz.QBKG04LM_QBKG11LM_state, fz.ignore_onoff_change, fz.QBKG04LM_operation_mode, fz.ignore_basic_report,
],
toZigbee: [tz.on_off, tz.xiaomi_decoupled_mode],
toZigbee: [tz.on_off, tz.xiaomi_switch_operation_mode],
ep: (device) => {
return {'system': 1, 'default': 2};
},
Expand All @@ -236,9 +236,9 @@ const devices = [
description: 'Aqara double key wired wall switch',
supports: 'release/hold, on/off',
fromZigbee: [
fz.QBKG03LM_QBKG12LM_state, fz.QBKG03LM_buttons, fz.ignore_basic_change, fz.ignore_basic_report,
fz.QBKG03LM_QBKG12LM_state, fz.QBKG03LM_buttons, fz.QBKG03LM_operation_mode, fz.ignore_basic_report,
],
toZigbee: [tz.on_off, tz.xiaomi_decoupled_mode],
toZigbee: [tz.on_off, tz.xiaomi_switch_operation_mode],
ep: (device) => {
return {'system': 1, 'left': 2, 'right': 3};
},
Expand Down

0 comments on commit 37fb0cd

Please sign in to comment.