Skip to content

Commit

Permalink
fix: add more hass modes maps
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Dec 1, 2020
1 parent 2d0167e commit 720a9c0
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
}
}
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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))
Expand Down

0 comments on commit 720a9c0

Please sign in to comment.