Skip to content

Commit

Permalink
TuYa TS0121, add support power_outage_memory (#1947)
Browse files Browse the repository at this point in the history
* TuYa TS0121, add support power_outage_memory

* Update devices.js

* Update fromZigbee.js

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
  • Loading branch information
artem-sedykh and Koenkk authored Dec 20, 2020
1 parent 147d5c6 commit ebb7170
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
16 changes: 16 additions & 0 deletions converters/fromZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -4758,6 +4758,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).
Expand Down
15 changes: 15 additions & 0 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__: () => {
Expand Down
8 changes: 5 additions & 3 deletions devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -1390,8 +1390,8 @@ const devices = [
description: '10A UK or 16A EU smart plug',
whiteLabel: [{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);
Expand All @@ -1404,6 +1404,9 @@ const devices = [
},
// This device doesn't support reporting correctly.
// https://github.com/Koenkk/zigbee-herdsman-converters/pull/1270
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')],
onEvent: (type, data, device, options) => {
const endpoint = device.getEndpoint(1);
if (type === 'stop') {
Expand All @@ -1418,7 +1421,6 @@ const devices = [
globalStore.putValue(device, 'interval', interval);
}
},
exposes: [e.switch(), e.power(), e.current(), e.voltage(), e.energy()],
},
{
zigbeeModel: ['mcdj3aq', 'mcdj3aq\u0000'],
Expand Down

0 comments on commit ebb7170

Please sign in to comment.