Skip to content

Commit

Permalink
fix: some nits
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Dec 1, 2020
1 parent bb3057e commit 7cde312
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -1168,6 +1168,7 @@ Gateway.prototype.discoverClimates = function (node) {
return
}

// arrays of strings valueIds (without the node prefix)
const setpoints = []
const temperatures = []
const modes = []
Expand All @@ -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) {
Expand All @@ -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',
Expand All @@ -1228,6 +1232,7 @@ Gateway.prototype.discoverClimates = function (node) {
undefined // manufacturer specific
]

// generic configuration
const config = copy(hassCfg.thermostat)

config.mode_map = {}
Expand All @@ -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
}
Expand Down

0 comments on commit 7cde312

Please sign in to comment.