From fa2b0222b1c63bbd044df2a77faec5654c84e569 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Mon, 3 Feb 2020 09:18:24 +0100 Subject: [PATCH] fix: Alarms hass discovery and undefined units bug #232 #231 --- lib/Gateway.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/Gateway.js b/lib/Gateway.js index 1a97774d494..63dfc242352 100755 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -858,15 +858,12 @@ Gateway.prototype.discoverValue = function (node, valueId) { break case 'alarm': - switch (valueId.index) { - case 0: cfg = 'sensor_alarm_type' - break - case 1: cfg = 'sensor_alarm_level' - break - case 10: cfg = 'sensor_alarm_burglar' - break - default: - return + if (valueId.index < 256) { + cfg = 'sensor_alarm_burglar' + } else if (valueId.index === 512) { + cfg = 'sensor_alarm_type' + } else if (valueId.index === 513) { + cfg = 'sensor_alarm_level' } if (cfg && hassCfg[cfg]) { @@ -885,12 +882,12 @@ Gateway.prototype.discoverValue = function (node, valueId) { cfg = Constants.meterType(valueId.index) } + cfg = cfg ? copy(hassCfg[cfg]) : copy(hassCfg.sensor_generic) + if (valueId.units) { cfg.discovery_payload.unit_of_measurement = valueId.units } - cfg = cfg ? copy(hassCfg[cfg]) : copy(hassCfg.sensor_generic) - // check if there is a custom value configuration for this valueID if (valueConf) { if (valueConf.device_class) {