diff --git a/lib/Constants.js b/lib/Constants.js index ff2cc18940e..7f876b47467 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -1,3 +1,5 @@ +const { lookupMeterScale } = require('@zwave-js/config') + module.exports = { // https://github.com/OpenZWave/open-zwave/blob/0d94c9427bbd19e47457578bccc60b16c6679b49/config/Localization.xml#L606 _productionMap: { @@ -17,32 +19,12 @@ module.exports = { }, // https://github.com/OpenZWave/open-zwave/blob/0d94c9427bbd19e47457578bccc60b16c6679b49/config/Localization.xml#L679 // https://github.com/OpenZWave/open-zwave/blob/0d94c9427bbd19e47457578bccc60b16c6679b49/cpp/src/command_classes/Meter.cpp#L74 - _metersMap: { - 0: 'kwh', // electricity - 1: 'kvah', - 2: 'w', - 3: 'pulses', - 4: 'v', - 5: 'a', - 6: 'pf', - 8: 'kvar', - 9: 'kvarh', - 16: 'm3', // gas - 17: 'ft3', - 19: 'pulses', - 32: 'm3', // water - 33: 'ft3', - 34: 'gal', - 35: 'pulses', - 48: 'kwh', // heating (electricity) - 64: 'kwh' // cooling (electricity) - }, - meterType (index) { + meterType (ccSpecific) { let cfg = null - if (index >= 16 && index < 32) { + if (ccSpecific.meterType >= 16 && ccSpecific.meterType < 32) { // gas cfg = this.sensorType(55) - } else if (index >= 32 && index < 48) { + } else if (ccSpecific.meterType >= 32 && ccSpecific.meterType < 48) { // water cfg = this.sensorType(12) } else { @@ -50,7 +32,9 @@ module.exports = { cfg = this.sensorType(4) } - cfg.objectId = (this._metersMap[index] || 'unknown') + '_meter' + const scale = lookupMeterScale(ccSpecific.meterType, ccSpecific.scale) + + cfg.objectId = (scale ? scale.label : 'unknown') + '_meter' return cfg }, // https://github.com/OpenZWave/open-zwave/blob/4478eea26b0e1a29184df0515a8034757258ff88/cpp/src/ValueIDIndexesDefines.def#L1068 diff --git a/lib/Gateway.js b/lib/Gateway.js index a959bef7735..682c0372d5d 100755 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -1472,7 +1472,7 @@ Gateway.prototype.discoverValue = function (node, vId) { // In some cases Metering devices offer Reset option or DeltaTime sensors, but do not include ccSpecific // information. With this change, we target only the sensors and not the additional Properties. if (valueId.ccSpecific) { - sensor = Constants.meterType(valueId.ccSpecific.meterType) + sensor = Constants.meterType(valueId.ccSpecific) } else { return }