From a62fc066e3cfb3ad10de9dc2e5495339dbf397d4 Mon Sep 17 00:00:00 2001 From: "artem.sedykh" Date: Sun, 20 Dec 2020 16:04:46 +0300 Subject: [PATCH 1/3] TuYa TS0121, add support power_outage_memory --- converters/fromZigbee.js | 18 ++++++++++++++++++ converters/toZigbee.js | 15 +++++++++++++++ devices.js | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/converters/fromZigbee.js b/converters/fromZigbee.js index ee5662281446b..1cc75ee919e99 100644 --- a/converters/fromZigbee.js +++ b/converters/fromZigbee.js @@ -4900,6 +4900,24 @@ const converters = { convert: (model, msg, publish, options, meta) => null, }, // #endregion + + tuya_switch_power_outage_memory: { + cluster: 'genOnOff', + type: ['attributeReport', 'readResponse'], + convert: (model, msg, publish, options, meta) => { + const property = 0x8002; + + if (msg.data.hasOwnProperty(property)) { + const dict = {0x00: 'off', 0x01: 'on', 0x02: 'restore'}; + const value = msg.data[property]; + + if (dict.hasOwnProperty(value)) { + return {[postfixWithEndpointName('power_outage_memory', msg, model)]: dict[value]}; + } + } + }, + }, + }; module.exports = converters; diff --git a/converters/toZigbee.js b/converters/toZigbee.js index 5be91610644e4..1fa39c1a46f9c 100644 --- a/converters/toZigbee.js +++ b/converters/toZigbee.js @@ -4299,6 +4299,21 @@ const converters = { } }, }, + tuya_switch_power_outage_memory: { + key: ['power_outage_memory'], + convertSet: async (entity, key, value, meta) => { + const dict = {'off': 0x00, 'on': 0x01, 'restore': 0x02}; + value = value && value.toString().toLowerCase(); + + if (value && dict.hasOwnProperty(value) === false) { + throw new Error(`${value} not supported, supported values: 'on', 'off', 'restore'`); + } + + const payload = dict[value]; + await entity.write('genOnOff', {0x8002: {value: payload, type: 0x30}}); + return {state: {power_outage_memory: value}}; + }, + }, // Not a converter, can be used by tests to clear the store. __clearStore__: () => { diff --git a/devices.js b/devices.js index 228699b8eb779..b6e498c989234 100755 --- a/devices.js +++ b/devices.js @@ -1855,8 +1855,8 @@ const devices = [ {vendor: 'BlitzWolf', model: 'BW-SHP13'}, ], vendor: 'TuYa', - fromZigbee: [fz.on_off, fz.electrical_measurement, fz.metering, fz.ignore_basic_report], - toZigbee: [tz.on_off], + fromZigbee: [fz.on_off, fz.electrical_measurement, fz.metering, fz.ignore_basic_report, fz.tuya_switch_power_outage_memory], + toZigbee: [tz.on_off, tz.tuya_switch_power_outage_memory], meta: {configureKey: 1}, configure: async (device, coordinatorEndpoint) => { const endpoint = device.getEndpoint(1); From f906bcb19c3d7d2595d5c451762be9b78b147d4a Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 20 Dec 2020 21:22:54 +0100 Subject: [PATCH 2/3] Update devices.js --- devices.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/devices.js b/devices.js index b6e498c989234..672d39892395d 100755 --- a/devices.js +++ b/devices.js @@ -1877,7 +1877,9 @@ const devices = [ // This device doesn't support reporting correctly. // https://github.com/Koenkk/zigbee-herdsman-converters/pull/1270 onEvent: setupHaElectricalMeasurementPolling, - exposes: [e.switch(), e.power(), e.current(), e.voltage(), e.energy()], + exposes: [e.switch(), e.power(), e.current(), e.voltage(), e.energy(), + exposes.enum('power_outage_memory', exposes.access.STATE_SET, ['on', 'off', 'restore']) + .withDescription('Recover state after power outage')], }, { zigbeeModel: ['mcdj3aq', 'mcdj3aq\u0000'], From fa7994654b224438a48da0c3321e5ae7e2140768 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sun, 20 Dec 2020 21:23:59 +0100 Subject: [PATCH 3/3] Update fromZigbee.js --- converters/fromZigbee.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/converters/fromZigbee.js b/converters/fromZigbee.js index 1cc75ee919e99..c599299c68e5b 100644 --- a/converters/fromZigbee.js +++ b/converters/fromZigbee.js @@ -4751,6 +4751,22 @@ const converters = { return payload; }, }, + tuya_switch_power_outage_memory: { + cluster: 'genOnOff', + type: ['attributeReport', 'readResponse'], + convert: (model, msg, publish, options, meta) => { + const property = 0x8002; + + if (msg.data.hasOwnProperty(property)) { + const dict = {0x00: 'off', 0x01: 'on', 0x02: 'restore'}; + const value = msg.data[property]; + + if (dict.hasOwnProperty(value)) { + return {[postfixWithEndpointName('power_outage_memory', msg, model)]: dict[value]}; + } + } + }, + }, // #endregion // #region Ignore converters (these message dont need parsing). @@ -4900,24 +4916,6 @@ const converters = { convert: (model, msg, publish, options, meta) => null, }, // #endregion - - tuya_switch_power_outage_memory: { - cluster: 'genOnOff', - type: ['attributeReport', 'readResponse'], - convert: (model, msg, publish, options, meta) => { - const property = 0x8002; - - if (msg.data.hasOwnProperty(property)) { - const dict = {0x00: 'off', 0x01: 'on', 0x02: 'restore'}; - const value = msg.data[property]; - - if (dict.hasOwnProperty(value)) { - return {[postfixWithEndpointName('power_outage_memory', msg, model)]: dict[value]}; - } - } - }, - }, - }; module.exports = converters;