diff --git a/lib/Gateway.js b/lib/Gateway.js index 9f982b31011..a959bef7735 100755 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -1155,8 +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 + // check if device it's a thermostat if (!node.deviceClass || node.deviceClass.generic !== 0x08) { - // it's a thermostat return } @@ -1168,6 +1168,7 @@ Gateway.prototype.discoverClimates = function (node) { return } + // arrays of strings valueIds (without the node prefix) const setpoints = [] const temperatures = [] const modes = [] @@ -1192,7 +1193,10 @@ Gateway.prototype.discoverClimates = function (node) { } } + // take the first as valid (there shouldn't be more then one) const modeId = modes[0] + + // TODO: if the device supports multiple endpoints how could we identify the correct one to use? const temperatureId = temperatures[0] if (!temperatureId || !modeId) { @@ -1204,12 +1208,12 @@ Gateway.prototype.discoverClimates = function (node) { const mode = node.values[modeId] - // [0, 1, 2] ---> ['off', 'heat', 'cold'] + // [0, 1, 2 ... ] (['off', 'heat', 'cold', ...]) const availableModes = mode.states.map(s => s.value) - // zwave modes: https://github.com/zwave-js/node-zwave-js/blob/master/packages/zwave-js/src/lib/commandclass/ThermostatModeCC.ts#L54 + // Zwave modes: https://github.com/zwave-js/node-zwave-js/blob/master/packages/zwave-js/src/lib/commandclass/ThermostatModeCC.ts#L54 + // Available hass modes: [“auto”, “off”, “cool”, “heat”, “dry”, “fan_only”] const hassModes = [ - // Available hass modes: [“auto”, “off”, “cool”, “heat”, “dry”, “fan_only”] 'off', 'heat', 'cool', @@ -1228,6 +1232,7 @@ Gateway.prototype.discoverClimates = function (node) { undefined // manufacturer specific ] + // generic configuration const config = copy(hassCfg.thermostat) config.mode_map = {} @@ -1239,13 +1244,15 @@ Gateway.prototype.discoverClimates = function (node) { // for all available modes update the modes map and setpoint topics for (const m of availableModes) { + if (hassModes[m] === undefined) continue + config.mode_map[hassModes[m]] = availableModes[m] config.discovery_payload.modes.push(hassModes[m]) if (m > 0) { // find the mode setpoint, ignore off const setId = setpoints.find(v => v.endsWith('-' + m)) - if (setId) { - const setpoint = node.values[setId] + const setpoint = node.values[setId] + if (setpoint) { if (setpoint.propertyKey === 1) { config.default_setpoint = setId }