Skip to content

Commit 800d64c

Browse files
authored
Add files via upload
1 parent 55f4b77 commit 800d64c

File tree

3 files changed

+269
-357
lines changed

3 files changed

+269
-357
lines changed

lib/DataExchange.js

Lines changed: 75 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var promiseHTTP = require("request-promise-native");
66

77

88

9-
exports.sendToHomeSeer = function (level, callback, HomeSeerHost, Characteristic, forceHSValue, getHSValue, instantStatusEnabled, that)
9+
exports.sendToHomeSeer = function (level, callback, HomeSeerHost, Characteristic, forceHSValue, getHSValue, instantStatusEnabled, that )
1010
{
1111
var url;
1212
var error = null;
@@ -29,6 +29,20 @@ exports.sendToHomeSeer = function (level, callback, HomeSeerHost, Characteristic
2929
// Uncomment any UUID's actually used!
3030
switch( that.UUID)
3131
{
32+
case(Characteristic.SecuritySystemTargetState.UUID):
33+
{
34+
// For now, this assumes HomeSeer users same indicator values as HomeKit
35+
// This may not be a valid assumption and may need to use configuration parameters to vary this.
36+
switch (level)
37+
{
38+
case 0: { transmitValue = that.config.armStayValue; break; }// 0 = HomeKit Stay Arm
39+
case 1: { transmitValue = that.config.armAwayValue; break; } // 1 = HomeKit Away Arm
40+
case 2: { transmitValue = that.config.armNightValue; break; } // 2 = HomeKit Night Arm
41+
case 3: { transmitValue = that.config.disarmValue; break; } // 3 = HomeKit Disarmed
42+
43+
};
44+
break;
45+
}
3246
case(Characteristic.TargetRelativeHumidity.UUID):
3347
{
3448
transmitValue = level;
@@ -63,10 +77,9 @@ exports.sendToHomeSeer = function (level, callback, HomeSeerHost, Characteristic
6377

6478
case(Characteristic.TargetPosition.UUID):
6579
{
66-
// if a simple binary switch is used, then either fully open or fully closed!
6780
if (that.config.binarySwitch)
6881
{
69-
transmitValue = (level < 50) ? 0 : 255; // Turn to "on"
82+
transmitValue = (level < 50) ? that.config.closedValue : that.config.openValue; // Turn to "on"
7083
forceHSValue(that.HSRef, transmitValue);
7184
}
7285
else
@@ -124,11 +137,12 @@ exports.sendToHomeSeer = function (level, callback, HomeSeerHost, Characteristic
124137
console.log("Set TransmitValue for lock characteristic %s to %s ", that.displayName, transmitValue);
125138
break;
126139
}
140+
127141

128142
case(Characteristic.On.UUID ):
129143
{
130144
// For devices such as dimmers, HomeKit sends both "on" and "brightness" when you adjust brightness.
131-
// But Z-Wave only expects a brighness value if light is already on. So, if the device is already on (non-Zero ZWave value)
145+
// But Z-Wave only expects a brightness value if light is already on. So, if the device is already on (non-Zero ZWave value)
132146
// then don't send again.
133147
// HomeKit level == false means turn off, level == true means turn on.
134148

@@ -193,23 +207,7 @@ exports.sendToHomeSeer = function (level, callback, HomeSeerHost, Characteristic
193207
// console.log(that.displayName + ': HomeSeer setHSValue function succeeded!');
194208
callback(null);
195209
// updateCharacteristic(this);// poll for this one changed Characteristic after setting its value.
196-
197-
// Strange special case of extra poll needed for window coverings that are controlled by a binary switch.
198-
// For odd reason, if poll isn't done, then the icon remains in a changing state until next poll!
199-
if (that.UUID == Characteristic.CurrentPosition.UUID || that.UUID == Characteristic.TargetPosition.UUID)
200-
{
201-
setTimeout ( ()=>
202-
{
203-
// console.log(chalk.cyan.bold("Window Covering Extra Polling!"));
204-
var statusObjectGroup = _statusObjects[that.HSRef];
205-
for (var thisCharacteristic in statusObjectGroup)
206-
{
207-
updateCharacteristicFromHSData(statusObjectGroup[thisCharacteristic]);
208-
}
209-
}, 500);
210-
}
211-
212-
210+
213211
}.bind(this))
214212
.catch(function(err)
215213
{
@@ -240,6 +238,36 @@ exports.processDataFromHomeSeer = function (characteristicObject, that, Characte
240238

241239
switch(true)
242240
{
241+
case(characteristicObject.UUID == Characteristic.SecuritySystemTargetState.UUID):
242+
case(characteristicObject.UUID == Characteristic.SecuritySystemCurrentState.UUID):
243+
{
244+
// For now, this assumes HomeSeer users same indicator values as HomeKit
245+
// This may not be a valid assumption and may need to use configuration parameters to vary this.
246+
switch (true)
247+
{
248+
case (characteristicObject.config.armedStayValues.indexOf(newValue) != (-1)):
249+
{ characteristicObject.updateValue(0); break; } // 0 = HomeKit Stay Arm
250+
251+
case (characteristicObject.config.armedAwayValues.indexOf(newValue) != (-1)):
252+
{ characteristicObject.updateValue(1); break; } // 1 = HomeKit Away Arm
253+
254+
case (characteristicObject.config.armedNightValues.indexOf(newValue) != (-1)):
255+
{ characteristicObject.updateValue(2); break; } // 2 = HomeKit Night Arm
256+
257+
case (characteristicObject.config.disarmedValues.indexOf(newValue) != (-1)):
258+
{ characteristicObject.updateValue(3); break; } // 3 = HomeKit Disarmed
259+
260+
case (characteristicObject.config.alarmValues.indexOf(newValue) != (-1)):
261+
{
262+
// Don't update the 'target' state if its an Alarm!
263+
if(characteristicObject.UUID != Characteristic.SecuritySystemTargetState.UUID)
264+
characteristicObject.updateValue(4); // 4 = HomeKit Alarm Triggered
265+
break;
266+
}
267+
};
268+
break;
269+
}
270+
243271
case(characteristicObject.UUID == Characteristic.StatusLowBattery.UUID):
244272
{
245273
// that.log("Battery Threshold status of battery level %s with threshold %s", newValue, characteristicObject.batteryThreshold);
@@ -253,14 +281,37 @@ exports.processDataFromHomeSeer = function (characteristicObject, that, Characte
253281
{
254282
if ((newValue > 100) && (newValue < 255))
255283
{
256-
console.log(chalk.bold.red("** Warning - Possible Illegal value for window covering setting"));
284+
console.log(chalk.bold.red("** Warning - Possible Illegal value for window covering setting"));
257285
}
258286

259-
// console.log(chalk.bold.magenta("Updating Characteristic: " + characteristicObject.displayName + " to value " + ((newValue == 255) ? 100 : newValue) ));
287+
// console.log(chalk.bold.magenta("Updating Characteristic: " + characteristicObject.displayName + " using received value: " + newValue));
260288

261289
// If you get a value of 255, then its probably from a binary switch, so set as fully open.
262290
// Else, its from a percentage-adjustable shade, so set to the percentage.
263-
characteristicObject.updateValue( ( ((newValue == 255) || (newValue == 99)) ? 100 : newValue) );
291+
if(characteristicObject.config.binarySwitch)
292+
{
293+
switch(newValue)
294+
{
295+
case (characteristicObject.config.openValue):
296+
{characteristicObject.updateValue(100); break;}
297+
case (characteristicObject.config.closedValue):
298+
{characteristicObject.updateValue(0); break;}
299+
default:
300+
{
301+
console.log(chalk.magenta.red(
302+
"** Warning - Possible Illegal value for window covering setting. " +
303+
"Window covering is set as a binary (open/closed) covering but HomeSeer returned value: " + newValue +
304+
" which is not the openValue or closedValue. Treating the value as 'closed'"
305+
));
306+
characteristicObject.updateValue(0)
307+
break;
308+
}
309+
}
310+
}
311+
else
312+
{
313+
characteristicObject.updateValue( ( (newValue == 99) ? 100 : newValue) );
314+
}
264315
break;
265316

266317
}

0 commit comments

Comments
 (0)