From 720a9c0b1e15b0e889f9d98facacc187174ac5f8 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Tue, 1 Dec 2020 14:09:57 +0100 Subject: [PATCH] fix: add more hass modes maps --- lib/Gateway.js | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/Gateway.js b/lib/Gateway.js index bb3708ead74..e06b73183bb 100755 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -1155,7 +1155,8 @@ Gateway.prototype.discoverDevice = function (node, hassDevice) { */ Gateway.prototype.discoverClimates = function (node) { // https://github.com/zwave-js/node-zwave-js/blob/master/packages/config/config/deviceClasses.json#L177 - if (!node.deviceClass.generic === 0x08) { // it's a thermostat + if (!node.deviceClass.generic === 0x08) { + // it's a thermostat return } @@ -1172,11 +1173,20 @@ Gateway.prototype.discoverClimates = function (node) { for (const vId in node.values) { const v = node.values[vId] - if (v.commandClass === CommandClasses['Thermostat Setpoint'] && v.property === 'setpoint') { + if ( + v.commandClass === CommandClasses['Thermostat Setpoint'] && + v.property === 'setpoint' + ) { setpoints.push(v) - } else if (v.commandClass === CommandClasses['Multilevel Sensor'] && v.property === 'Air temperature') { + } else if ( + v.commandClass === CommandClasses['Multilevel Sensor'] && + v.property === 'Air temperature' + ) { temperatures.push(v) - } else if (v.commandClass === CommandClasses['Thermostat Mode'] && v.property === 'mode') { + } else if ( + v.commandClass === CommandClasses['Thermostat Mode'] && + v.property === 'mode' + ) { modes.push(v) } } @@ -1187,10 +1197,25 @@ Gateway.prototype.discoverClimates = function (node) { // [0, 1, 2] ---> ['off', 'heat', 'cold'] const availableModes = mode.states.map(s => s.value) - const hassModes = [ // [“auto”, “off”, “cool”, “heat”, “dry”, “fan_only”] + // zwave modes: https://github.com/zwave-js/node-zwave-js/blob/master/packages/zwave-js/src/lib/commandclass/ThermostatModeCC.ts#L54 + const hassModes = [ + // Available hass modes: [“auto”, “off”, “cool”, “heat”, “dry”, “fan_only”] 'off', 'heat', - 'cool' + 'cool', + 'auto', + undefined, // auxiliary + undefined, // resume + 'fan_only', + undefined, // furnace + 'dry', + undefined, // moist + 'auto', // auto changeover + 'heat', // energy heat + 'cool', // energy cool + 'off', // away + 'heat', // full power + undefined // manufacturer specific ] const config = copy(hassCfg.thermostat) @@ -1202,10 +1227,12 @@ Gateway.prototype.discoverClimates = function (node) { config.discovery_payload.mode_state_topic = mode.id config.discovery_payload.current_temperature_topic = temperature.id + // for all available modes update the modes map and setpoint topics for (const m of availableModes) { config.mode_map[hassModes[m]] = availableModes[m] config.discovery_payload.modes.push(hassModes[m]) - if (m > 0) { // find the mode setpoint, ignore off + if (m > 0) { + // find the mode setpoint, ignore off const setpoint = setpoints.find(v => v.propertyKey === m) if (setpoint) { if (setpoint.propertyKey === 1) { @@ -1218,6 +1245,8 @@ Gateway.prototype.discoverClimates = function (node) { } } + // add the new climate config to the nodeDevices so it will be + // discovered later when we call `discoverDevice` nodeDevices.push(config) debug('New climate device discovered: ' + JSON.stringify(config))