Skip to content

Commit 32015e5

Browse files
authored
Bug Fixes and Minor Developments (#1)
* Bug Fixes * Update index.js * Update package.json * Update index.js * Add files via upload * Delete UUIDcheck.js * Update HomeSeerUtilities.js * Update HomeSeerUtilities.js * Update HomeSeerUtilities.js * Update index.js * Update HomeSeerUtilities.js * Update package.json * Add files via upload * Update package.json * Add files via upload * Update index.js * First Attempt to break out code to select devices * Update HSgetServices.js * Delete HSPolling.js * Delete HSgetServices.js
1 parent e4ed5f4 commit 32015e5

File tree

3 files changed

+341
-208
lines changed

3 files changed

+341
-208
lines changed

index.js

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111

112112

113113
var promiseHTTP = require("request-promise-native");
114+
var chalk = require("chalk");
115+
var HSutilities = require("./lib/HomeSeerUtilities");
114116

115117
var Accessory, Service, Characteristic, UUIDGen;
116118

@@ -148,12 +150,15 @@ module.exports = function (homebridge) {
148150
function getHSValue(ref) {
149151
return _HSValues[ref];
150152
}
151-
function setHSValue(ref, level)
153+
function forceHSValue(ref, level)
152154
{
153155
// This function is used to temporarily 'fake' a HomeSeer poll update.
154156
// Used when, e.g., you set a new value of an accessory in HomeKit - this provides a fast update to the
155157
// Retrieved HomeSeer device values which will then be "corrected / confirmed" on the next poll.
156158
_HSValues[ref] = level;
159+
160+
// Debugging
161+
console.log("** DEBUG ** - called forceHSValue with reference: %s, level: %s, resulting in new value: %s", ref, level, _HSValues[ref]);
157162
}
158163

159164

@@ -176,13 +181,28 @@ HomeSeerPlatform.prototype = {
176181
var foundAccessories = [];
177182
var that = this;
178183
var refList = [];
184+
185+
try
186+
{
187+
HSutilities.checkConfig.call(this, this.config);
188+
}
189+
catch(err)
190+
{
191+
this.log(chalk.bold.red("--------------------------------------------------------------------------------"));
192+
this.log(chalk.bold.red("** ERROR ** ERROR ** ERROR ** Etc. **"));
193+
this.log(chalk.bold.red("** Format error in your config.json file **"));
194+
this.log(chalk.bold.red("Fix your config.json file!!"));
195+
this.log(chalk.bold.red(err));
196+
this.log(chalk.bold.red("--------------------------------------------------------------------------------"));
197+
198+
throw err;
199+
}
179200

180201
/////////////////////////////////////////////////////////////////////////////////
181202
// Make devices for each HomeSeer event in the config.json file
182203
try
183204
{
184205
if (this.config.events) {
185-
this.log("Creating HomeSeer events. Caution currently untested.");
186206
for (var i = 0; i < this.config.events.length; i++) {
187207
var event = new HomeSeerEvent(that.log, that.config, that.config.events[i]);
188208
foundAccessories.push(event);
@@ -191,11 +211,11 @@ HomeSeerPlatform.prototype = {
191211
}
192212
catch(err)
193213
{
194-
this.log("--------------------------------------------------------------------------------");
214+
this.log(chalk.bold.red("--------------------------------------------------------------------------------"));
195215
this.log("** ERROR ** ERROR ** ERROR ** Etc. **");
196216
this.log("** ERROR attempting to add HomeSeer event specified in config.json to HomeKit **")
197217
this.log("Processing will continue with adding of Accessories");
198-
this.log("--------------------------------------------------------------------------------");
218+
this.log(chalk.bold.red("--------------------------------------------------------------------------------"));
199219
}
200220

201221
/////////////////////////////////////////////////////////////////////////////////
@@ -215,11 +235,15 @@ HomeSeerPlatform.prototype = {
215235
)
216236
.catch(function(err)
217237
{
218-
this.log("----------------------- ERROR ----------------------------");
238+
this.log(""); this.log("");
239+
this.log(chalk.bold.red("**************************************************************************"));
240+
this.log(chalk.bold.red("---------------------------- ERROR ---------------------------------"));
219241
this.log("Unable to Access HomeSeer at address %s", this.config["host"]);
220242
this.log("HTTP Error Message: %s", err);
221243
this.log(" *** Check if HomeSeer is running. ***");
222-
this.log("----------------------------------------------------------------");
244+
this.log(chalk.bold.red("--------------------------------------------------------------------------"));
245+
this.log(chalk.bold.red("**************************************************************************\n\n"));
246+
throw(err);
223247
}.bind(this) // need to bind to "this" for logging to work.
224248
)
225249

@@ -359,7 +383,7 @@ HomeSeerAccessory.prototype = {
359383

360384
if (!this.UUID) {
361385
var error = "*** PROGRAMMING ERROR **** - setHSValue called by something without a UUID";
362-
console.log ("*** PROGRAMMING ERROR **** - setHSValue called by something without a UUID");
386+
console.log (chalk.bold.red("*** PROGRAMMING ERROR **** - setHSValue called by something without a UUID"));
363387
console.log (this);
364388
callback(error);
365389
}
@@ -374,7 +398,7 @@ HomeSeerAccessory.prototype = {
374398
// Maximum ZWave value is 99 so covert 100% to 99!
375399
transmitValue = (transmitValue == 100) ? 99 : level;
376400

377-
setHSValue(this.HSRef, transmitValue);
401+
forceHSValue(this.HSRef, transmitValue);
378402
callbackValue = level; // but call back with the value instructed by HomeKit rather than the modified 99 sent to HomeSeer
379403

380404
// this.updateValue(transmitValue); // Assume success. This gets corrected on next poll if assumption is wrong.
@@ -406,15 +430,15 @@ HomeSeerAccessory.prototype = {
406430
{
407431
transmitValue = 0 ;
408432
callbackValue = 0;
409-
setHSValue(this.HSRef, 0); // assume success and set to 0 to avoid jumping of any associated dimmer / range slider.
433+
forceHSValue(this.HSRef, 0); // assume success and set to 0 to avoid jumping of any associated dimmer / range slider.
410434
}
411435
else // turn on!
412436
{
413437
if(getHSValue(this.HSRef) == 0) // if it is currently off, then turn fully on.
414438
{
415439
// if it is off, turn on to full level.
416440
transmitValue = 255;
417-
setHSValue(this.HSRef, 99);
441+
forceHSValue(this.HSRef, 99);
418442
callbackValue = 1; // and callback with a 1 meaning it was turned on
419443
}
420444
else // If it appears to be on, then send same value!
@@ -433,7 +457,7 @@ HomeSeerAccessory.prototype = {
433457

434458
default:
435459
{
436-
console.log ("*** PROGRAMMING ERROR **** - Service or Characteristic UUID not handled by setHSValue routine");
460+
console.log (chalk.bold.red("*** PROGRAMMING ERROR **** - Service or Characteristic UUID not handled by setHSValue routine"));
437461

438462
var err = "*** PROGRAMMING ERROR **** - Service or Characteristic UUID not handled by setHSValue routine"
439463
+ characteristicObject.UUID + " named " + characteristicObject.displayName;
@@ -444,8 +468,12 @@ HomeSeerAccessory.prototype = {
444468
}
445469

446470
if (isNaN(transmitValue))
447-
{console.log ("*** PROGRAMMING ERROR **** - Attempting to transmit non-numeric value to HomeSeer for %s with UUID %s", this.displayName, this.UUID);
471+
{
472+
console.log(chalk.bold.red("*************************** PROGRAM ERROR ***************************"));
473+
console.log ("Attempting to transmit non-numeric value to HomeSeer for %s with UUID %s", this.displayName, this.UUID);
448474
callback("Programming Error in function setHSValue. Attempt to send value to HomeSeer that is not a number");
475+
console.log(chalk.bold.red("*********************************************************************"));
476+
449477
};
450478

451479
url = _accessURL + "request=controldevicebyvalue&ref=" + this.HSRef + "&value=" + transmitValue;
@@ -462,7 +490,7 @@ HomeSeerAccessory.prototype = {
462490
// updateCharacteristic(this);// poll for this one changed Characteristic after setting its value.
463491
}.bind(this))
464492
.catch(function(err)
465-
{ console.log("Error attempting to update %s, with error %s", this.displayName, this.UUID, err);
493+
{ console.log(chalk.bold.red("Error attempting to update %s, with error %s", this.displayName, this.UUID, err));
466494
}.bind(this)
467495
);
468496
},
@@ -762,7 +790,15 @@ HomeSeerAccessory.prototype = {
762790
*/
763791

764792
case "Lightbulb":
765-
default: {
793+
default:
794+
{
795+
if(!this.config || !this.config.type || (this.config.type == null))
796+
{
797+
this.log(chalk.bold.yellow("WARNING: adding unspecified device type with HomeSeer reference " + this.config.ref + ". Defaulting to type Lightbulb. "));
798+
this.log(chalk.bold.yellow("Future versions of this plugin may require specification of the type of each device."));
799+
this.log(chalk.bold.yellow("Please update your config.json file to specify the device type."));
800+
}
801+
766802
// this.log("** Debug ** - Setting up bulb %s with can_dim %s", this.config.name, this.config.can_dim);
767803
var lightbulbService = new Service.Lightbulb();
768804
lightbulbService.isPrimaryService = true;
@@ -780,7 +816,7 @@ HomeSeerAccessory.prototype = {
780816
_statusObjects.push(lightbulbService.getCharacteristic(Characteristic.On));
781817

782818
if (this.config.can_dim == null || this.config.can_dim == true) {
783-
this.log(" Making lightbulb dimmable");
819+
// this.log(" Making lightbulb dimmable");
784820

785821
lightbulbService
786822
.addCharacteristic(new Characteristic.Brightness())

0 commit comments

Comments
 (0)