From 08e0d871753b2d0e0307452ce9fff55e1acd1346 Mon Sep 17 00:00:00 2001 From: Andrey Ivaschenko Date: Sat, 29 Feb 2020 02:27:06 +0300 Subject: [PATCH] Add AC Control commands 0x193A, 0x193B --- CHANGELOG.md | 1 + lib/commands.js | 93 ++++++++++++++++++++++++++++++++++++++- test/fixtures/commands.js | 68 ++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24c0851..212d80a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Fix channels info for scene status commands (`0x0003`, `0xEFFF`) * Fix parsing of "Response Read Sensors Status" (`0x1605`) * Add Panel buttons control commands (`0xE012`, `0xE14E`) + * Add AC Control commands (`0x193A`, `0x193B`) **BREAKING:** diff --git a/lib/commands.js b/lib/commands.js index 27fb03e..5f2d456 100644 --- a/lib/commands.js +++ b/lib/commands.js @@ -44,6 +44,86 @@ var date = { } }; +var AC = { + modes: ['cooling', 'heating', 'fan', 'auto', 'dry'], + speeds: ['auto', 'high', 'medium', 'low'], + + parse: function(buffer) { + var mode = buffer.readUInt8(7); + var temperature = buffer.readUInt8(11); + + var swing = buffer.readUInt8(12); + + return { + ac: buffer.readUInt8(0), + + temperature: { + type: buffer.readUInt8(1) ? 'F' : 'C', + + current: buffer.readUInt8(2), + + cooling: buffer.readUInt8(3), + heating: buffer.readUInt8(4), + auto: buffer.readUInt8(5), + dry: buffer.readUInt8(6) + }, + + current: { + mode: AC.modes[mode >> 4], + speed: AC.speeds[mode & 15] + }, + + status: Boolean(buffer.readUInt8(8)), + + setup: { + mode: AC.modes[buffer.readUInt8(9)], + speed: AC.speeds[buffer.readUInt8(10)], + temperature: temperature + }, + + swing: { + enabled: Boolean(swing >> 4), + active: Boolean(swing & 15) + } + }; + }, + + encode: function(data) { + var buffer = new Buffer(13); + + var temperature = data.temperature || {}; + var current = data.current || {}; + var setup = data.setup || {}; + var swing = data.swing || {}; + + var modes = AC.modes; + var speeds = AC.speeds; + + buffer.writeUInt8(data.ac, 0); + + buffer.writeUInt8(temperature.type === 'F' ? 1 : 0, 1); + buffer.writeUInt8(temperature.current, 2); + buffer.writeUInt8(temperature.cooling, 3); + buffer.writeUInt8(temperature.heating, 4); + buffer.writeUInt8(temperature.auto, 5); + buffer.writeUInt8(temperature.dry, 6); + + buffer.writeUInt8( + modes.indexOf(current.mode) << 4 | speeds.indexOf(current.speed), 7); + + buffer.writeUInt8(data.status ? 1 : 0, 8); + + buffer.writeUInt8(modes.indexOf(setup.mode), 9); + buffer.writeUInt8(speeds.indexOf(setup.speed), 10); + buffer.writeUInt8(setup.temperature, 11); + + buffer.writeUInt8( + ((swing.enabled ? 1 : 0) << 4) | (swing.active ? 1 : 0), 12); + + return buffer; + } +}; + /* Commands as decribed in "Operation Code of HDL Buspro v1.111.pdf" from http://hdlautomation.com @@ -964,10 +1044,19 @@ module.exports = { // 0x1939 // 10.1.3 Control AC Status - // 0x193A + // Documetation is wrong + 0x193A: { + parse: AC.parse, + encode: AC.encode, + + response: 0x193B + }, // 10.1.4 Response Control AC Status - // 0x193B + 0x193B: { + parse: AC.parse, + encode: AC.encode + }, /* 11.1 Floor Heating Control from DLP */ diff --git a/test/fixtures/commands.js b/test/fixtures/commands.js index 97b84f8..7b76ca0 100644 --- a/test/fixtures/commands.js +++ b/test/fixtures/commands.js @@ -412,6 +412,74 @@ module.exports = { { payload: new Buffer('0E32', 'hex'), data: { key: 14, value: 50 } }, ], + /* 10. AC Control */ + + // 10.1.1 Read AC Status + // 0x1938 + + // 10.1.2 Response Read AC Status + // 0x1939 + + // 10.1.3 Control AC Status + '0x193A': { + payload: new Buffer('01001C10131516230101001311', 'hex'), + data: { + ac: 1, + temperature: { + type: 'C', + current: 28, + cooling: 16, + heating: 19, + auto: 21, + dry: 22 + }, + current: { + mode: 'fan', + speed: 'low' + }, + status: true, + setup: { + mode: 'heating', + speed: 'auto', + temperature: 19 + }, + swing: { + enabled: true, + active: true + } + } + }, + + // 10.1.4 Response Control AC Status + '0x193B': { + payload: new Buffer('01001C10131516010100001000', 'hex'), + data: { + ac: 1, + temperature: { + type: 'C', + current: 28, + cooling: 16, + heating: 19, + auto: 21, + dry: 22 + }, + current: { + mode: 'cooling', + speed: 'high' + }, + status: true, + setup: { + mode: 'cooling', + speed: 'auto', + temperature: 16 + }, + swing: { + enabled: false, + active: false + } + } + }, + /* 11.1 Floor Heating Control from DLP */ // 11.1.1 Read Floor Heating Status