Bug Fix for decodeValveData / improvedNaming / CIRCUIT_VALUE_MAP (#33)

* initial code to interpret valveDataArray

* Some additional comments on the valveDataArray decoding message

* Adds decodeSensorData, decodeValveData, decodeDelayData, decodeMiscData

* reverts unintended change to index.js

* Refactor / rename variables
	- renamed variables to better describe their use
	- created a helper function 'isValvePresent' to simplify code
	- changed while loop to for loop

* - Fixes bug in decodeValveData where only last valve's data was returned
- renames some variables based on testing to more descriptive names
- add CIRCUIT_NAME_VALUE_MAP for fixed values that the system uses (determined by testing on my system)

* refactored decodeMiscData to simplify code

* - Changed CIRCUIT_NAME_VALUE_MAP to array of objects
- Refactored getCircuitByDeviceId
- Added getCircuitsMap as helper to getCircuitByDeviceId and as a utility function to help in UI development
This commit is contained in:
Bruce Sheplan
2020-06-19 09:57:51 -05:00
committed by GitHub
parent 1e13036faf
commit 0a0c8c7cd0
2 changed files with 34 additions and 18 deletions

View File

@ -4,6 +4,14 @@ const SLMessage = require('./SLMessage.js').SLMessage;
const MSG_ID = 12532;
const CIRCUIT_NAME_VALUE_MAP = [
{name: 'Unused', deviceId: 0},
{name: 'Solar Active', deviceId: 128},
{name: 'Pool or Spa Heater Active', deviceId: 129},
{name: 'Pool Heater Active', deviceId: 130},
{name: 'Spa Heater Active', deviceId: 131},
];
exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMessage {
constructor(buf) {
var size;
@ -129,14 +137,28 @@ exports.SLControllerConfigMessage = class SLControllerConfigMessage extends SLMe
}
getCircuitByDeviceId(deviceId) {
if (this.bodyArray) {
for (var i = 0; i < this.bodyArray.length; i++) {
if (this.bodyArray[i].deviceId === deviceId) {
return this.bodyArray[i];
}
var deviceArray = this.getCircuitsMap();
for (var i = 0; i < deviceArray.length; i++) {
if (deviceArray[i].deviceId === deviceId) {
return deviceArray[i];
}
}
return null;
}
getCircuitsMap() {
var deviceArray;
if (this.bodyArray) {
deviceArray = this.bodyArray.concat(CIRCUIT_NAME_VALUE_MAP);
} else {
deviceArray = [].concat(CIRCUIT_NAME_VALUE_MAP);
}
return deviceArray;
}
};