From 731354352252fbd0fd51d7d34fc11f8cca99d5ec Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 14 Feb 2020 14:48:25 +0100 Subject: [PATCH] fix: Hass discovery for SENSOR_ALARM cmd class --- lib/Gateway.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/Gateway.js b/lib/Gateway.js index ea3834c8bbb..2eeea271c99 100755 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -799,14 +799,16 @@ Gateway.prototype.discoverValue = function (node, valueId) { case 'switch_binary': case 'switch_all': case 'switch_toggle_binary': - let rgb = node.values['51-1-0'] - if (rgb) { - cfg = copy(hassCfg.light_rgb_switch) - cfg.discovery_payload.rgb_state_topic = this.mqtt.getTopic(this.valueTopic(node, rgb)) - cfg.discovery_payload.rgb_command_topic = cfg.discovery_payload.rgb_state_topic + '/set' - } else { - cfg = copy(hassCfg.switch) - } + if (valueId.index === 0) { + let rgb = node.values['51-1-0'] + if (rgb) { + cfg = copy(hassCfg.light_rgb_switch) + cfg.discovery_payload.rgb_state_topic = this.mqtt.getTopic(this.valueTopic(node, rgb)) + cfg.discovery_payload.rgb_command_topic = cfg.discovery_payload.rgb_state_topic + '/set' + } else { + cfg = copy(hassCfg.switch) + } + } else return break case 'switch_multilevel': case 'switch_toggle_multilevel': @@ -826,9 +828,7 @@ Gateway.prototype.discoverValue = function (node, valueId) { } else { cfg = copy(hassCfg.light_dimmer) } - } else { - return - } + } else return break case 'door_lock': if (valueId.index === 0) { // lock state @@ -870,7 +870,16 @@ Gateway.prototype.discoverValue = function (node, valueId) { break case 'sensor_alarm': + let alarmMap = { + 0: 'general', + 1: 'smoke', + 2: 'carbon_monoxide', + 3: 'carbon_dioxide', + 4: 'heat', + 5: 'flood' + } cfg = copy(hassCfg.binary_sensor_alarm) + cfg.object_id += alarmMap[valueId.index] ? '_' + alarmMap[valueId.index] : '' break case 'alarm':