Skip to content

Commit

Permalink
fix(hass): meterScale #38
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Dec 2, 2020
1 parent eac3095 commit 8a621bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
32 changes: 8 additions & 24 deletions lib/Constants.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -17,40 +19,22 @@ 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) {

This comment has been minimized.

Copy link
@AlCalzone

AlCalzone Dec 2, 2020

Member

Where are you getting these values from?
https://github.com/zwave-js/node-zwave-js/blob/master/packages/config/config/meters.json
meterType goes from 1 to 5.

This comment has been minimized.

Copy link
@robertsLando

robertsLando Dec 2, 2020

Author Member

Coming from ozw, I think I need to fix this too. Thanks for looking at it @AlCalzone :) Thought it was the same

// water
cfg = this.sensorType(12)
} else {
// electricity
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
Expand Down
2 changes: 1 addition & 1 deletion lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8a621bd

Please sign in to comment.