Skip to content

Commit

Permalink
do not convert *_MODE metrics from/to celcius when key contains _TEMP_ (
Browse files Browse the repository at this point in the history
  • Loading branch information
hacki11 authored and danielbayerlein committed May 6, 2019
1 parent c0942a7 commit ff2744c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module.exports = class Vallox {

keys.forEach(key => {
const value = vlxReceiveBuffer[calculateOffset(VlxDevConstants[key])]
result[key] = key.indexOf('_TEMP_') === -1 ? value : this._toCelsius(value)
result[key] = this.convert(key, value, () => this._toCelsius(value))
})

return result
Expand All @@ -160,12 +160,16 @@ module.exports = class Vallox {
const item = new VlxWriteItem()

item.address = VlxDevConstants[key]
item.value = key.indexOf('_TEMP_') === -1 ? value : this._toKelvin(value)
item.value = this.convert(key, value, () => this._toKelvin(value))
buf.appendData(item)
})

await this._request(buf.convertDataToBuffer(VlxDevConstants.WS_WEB_UI_COMMAND_WRITE_DATA))

return true
}

convert (key, value, converter) {
return (key.indexOf('_TEMP_') === -1 || key.indexOf('_MODE') > 0) ? value : converter()
}
}

0 comments on commit ff2744c

Please sign in to comment.