From 37fb0cd21b39f965ef0890fb93bf1c0b860b815f Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Tue, 19 Feb 2019 23:43:24 +0000 Subject: [PATCH] [Xiaomi wired switch] Parse operation mode response --- converters/fromZigbee.js | 38 ++++++++++++++++++++++++++++++++++++++ converters/toZigbee.js | 9 +++++---- devices.js | 8 ++++---- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/converters/fromZigbee.js b/converters/fromZigbee.js index 9793afabf1c85..e9daba5abf2fc 100644 --- a/converters/fromZigbee.js +++ b/converters/fromZigbee.js @@ -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', @@ -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', diff --git a/converters/toZigbee.js b/converters/toZigbee.js index e8db0a9afce6c..0f1a467b7e44b 100644 --- a/converters/toZigbee.js +++ b/converters/toZigbee.js @@ -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 = { @@ -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')) { diff --git a/devices.js b/devices.js index dfefdf7182477..6963a46611106 100644 --- a/devices.js +++ b/devices.js @@ -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}; }, @@ -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}; },