From 9554dfe88d6498f87645a60d62c45b24e924b864 Mon Sep 17 00:00:00 2001 From: Jeremy Higgs Date: Wed, 11 Mar 2020 22:07:46 +0500 Subject: [PATCH] Add IP address to result and error messages, to help diagnosis. --- Devices/MiPhilipsCeilingLamp.js | 24 ++++++++++---------- Devices/MiPhilipsSmartBulb.js | 24 ++++++++++---------- Devices/MiPhilipsTableLamp2.js | 40 ++++++++++++++++----------------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Devices/MiPhilipsCeilingLamp.js b/Devices/MiPhilipsCeilingLamp.js index ead59ed..ad12f98 100644 --- a/Devices/MiPhilipsCeilingLamp.js +++ b/Devices/MiPhilipsCeilingLamp.js @@ -71,23 +71,23 @@ MiPhilipsCeilingLampLight.prototype.getServices = function() { CeilingLampOnCharacteristic .on('get', function(callback) { this.device.call("get_prop", ["power"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - getPower: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp (" + that.device.address + ") - getPower: " + result); callback(null, result[0] === 'on' ? true : false); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - getPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp (" + that.device.address + ") - getPower Error: " + err); callback(err); }); }.bind(this)) .on('set', function(value, callback) { that.device.call("set_power", [value ? "on" : "off"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - setPower Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp (" + that.device.address + ") - setPower Result: " + result); if(result[0] === "ok") { callback(null); } else { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - setPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp (" + that.device.address + ") - setPower Error: " + err); callback(err); }); }.bind(this)); @@ -95,24 +95,24 @@ MiPhilipsCeilingLampLight.prototype.getServices = function() { .addCharacteristic(Characteristic.Brightness) .on('get', function(callback) { this.device.call("get_prop", ["bright"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - getBrightness: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp (" + that.device.address + ") - getBrightness: " + result); callback(null, result[0]); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - getBrightness Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp (" + that.device.address + ") - getBrightness Error: " + err); callback(err); }); }.bind(this)) .on('set', function(value, callback) { if(value > 0) { this.device.call("set_bright", [value]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - setBrightness Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp (" + that.device.address + ") - setBrightness Result: " + result); if(result[0] === "ok") { callback(null); } else { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - setBrightness Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp (" + that.device.address + ") - setBrightness Error: " + err); callback(err); }); } else { @@ -123,10 +123,10 @@ MiPhilipsCeilingLampLight.prototype.getServices = function() { .getCharacteristic(Characteristic.ColorTemperature) .on('get', function(callback) { this.device.call("get_prop", ["cct"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - getColorTemperature: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp (" + that.device.address + ") - getColorTemperature: " + result); callback(null, result[0] * 350); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - getColorTemperature Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp (" + that.device.address + ") - getColorTemperature Error: " + err); callback(err); }); }.bind(this)) @@ -139,14 +139,14 @@ MiPhilipsCeilingLampLight.prototype.getServices = function() { } that.platform.log.debug("[MiPhilipsLightPlatform]MiPhilipsCeilingLamp - setColorTemperature : " + value + "%"); this.device.call("set_cct", [value]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp - setColorTemperature Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsCeilingLamp (" + that.device.address + ") - setColorTemperature Result: " + result); if(result[0] === "ok") { callback(null); } else { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp - setColorTemperature Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsCeilingLamp (" + that.device.address + ") - setColorTemperature Error: " + err); callback(err); }); }.bind(this)); diff --git a/Devices/MiPhilipsSmartBulb.js b/Devices/MiPhilipsSmartBulb.js index f964672..6607891 100644 --- a/Devices/MiPhilipsSmartBulb.js +++ b/Devices/MiPhilipsSmartBulb.js @@ -73,10 +73,10 @@ MiPhilipsSmartBulbLight.prototype.getServices = function() { MiPhilipsSmartBulbLight.prototype.getPower = function(callback) { var that = this; this.device.call("get_prop", ["power"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light - getPower: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light (" + that.device.address + ") - getPower: " + result); callback(null, result[0] === 'on' ? true : false); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light - getPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light (" + that.device.address + ") - getPower Error: " + err); callback(err); }); } @@ -84,14 +84,14 @@ MiPhilipsSmartBulbLight.prototype.getPower = function(callback) { MiPhilipsSmartBulbLight.prototype.setPower = function(value, callback) { var that = this; that.device.call("set_power", [value ? "on" : "off"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light - setPower Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light (" + that.device.address + ") - setPower Result: " + result); if(result[0] === "ok") { callback(null); } else { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light - setPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light (" + that.device.address + ") - setPower Error: " + err); callback(err); }); } @@ -99,10 +99,10 @@ MiPhilipsSmartBulbLight.prototype.setPower = function(value, callback) { MiPhilipsSmartBulbLight.prototype.getBrightness = function(callback) { var that = this; this.device.call("get_prop", ["bright"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light - getBrightness: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light (" + that.device.address + ") - getBrightness: " + result); callback(null, result[0]); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light - getBrightness Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light (" + that.device.address + ") - getBrightness Error: " + err); callback(err); }); } @@ -111,14 +111,14 @@ MiPhilipsSmartBulbLight.prototype.setBrightness = function(value, callback) { var that = this; if(value > 0) { this.device.call("set_bright", [value]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light - setBrightness Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light (" + that.device.address + ") - setBrightness Result: " + result); if(result[0] === "ok") { callback(null); } else { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light - setBrightness Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light (" + that.device.address + ") - setBrightness Error: " + err); callback(err); }); } else { @@ -129,10 +129,10 @@ MiPhilipsSmartBulbLight.prototype.setBrightness = function(value, callback) { MiPhilipsSmartBulbLight.prototype.getColorTemperature = function(callback) { var that = this; this.device.call("get_prop", ["cct"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light - getColorTemperature: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light (" + that.device.address + ") - getColorTemperature: " + result); callback(null, result[0] * 350); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light - getColorTemperature Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light (" + that.device.address + ") - getColorTemperature Error: " + err); callback(err); }); } @@ -146,14 +146,14 @@ MiPhilipsSmartBulbLight.prototype.setColorTemperature = function(value, callback } var that = this; this.device.call("set_cct", [value]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light - setColorTemperature Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsSmartBulb - Light (" + that.device.address + ") - setColorTemperature Result: " + result); if(result[0] === "ok") { callback(null); } else { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light - setColorTemperature Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsSmartBulb - Light (" + that.device.address + ") - setColorTemperature Error: " + err); callback(err); }); } diff --git a/Devices/MiPhilipsTableLamp2.js b/Devices/MiPhilipsTableLamp2.js index dfe3d0a..d40f5c9 100644 --- a/Devices/MiPhilipsTableLamp2.js +++ b/Devices/MiPhilipsTableLamp2.js @@ -63,16 +63,16 @@ MiPhilipsTableLamp2Light.prototype.getServices = function() { mainLightOnCharacteristic .on('get', function(callback) { this.device.call("get_prop", ["power"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - MainLight - getPower: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - MainLight (" + that.device.address + ") - getPower: " + result); callback(null, result[0] === 'on' ? true : false); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - MainLight - getPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - MainLight (" + that.device.address + ") - getPower Error: " + err); callback(err); }); }.bind(this)) .on('set', function(value, callback) { that.device.call("set_power", [value ? "on" : "off"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - MainLight - setPower Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - MainLight (" + that.device.address + ") - setPower Result: " + result); if(result[0] === "ok") { if(value) { eyecareSwitchOnCharacteristic.getValue(); @@ -90,7 +90,7 @@ MiPhilipsTableLamp2Light.prototype.getServices = function() { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - MainLight - setPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - MainLight (" + that.device.address + ") - setPower Error: " + err); callback(err); }); }.bind(this)); @@ -98,24 +98,24 @@ MiPhilipsTableLamp2Light.prototype.getServices = function() { .addCharacteristic(Characteristic.Brightness) .on('get', function(callback) { this.device.call("get_prop", ["bright"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - MainLight - getBrightness: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - MainLight (" + that.device.address + ") - getBrightness: " + result); callback(null, result[0]); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - MainLight - getBrightness Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - MainLight (" + that.device.address + ") - getBrightness Error: " + err); callback(err); }); }.bind(this)) .on('set', function(value, callback) { if(value > 0) { this.device.call("set_bright", [value]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - MainLight - setBrightness Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - MainLight (" + that.device.address + ") - setBrightness Result: " + result); if(result[0] === "ok") { callback(null); } else { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - MainLight - setBrightness Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - MainLight (" + that.device.address + ") - setBrightness Error: " + err); callback(err); }); } else { @@ -127,16 +127,16 @@ MiPhilipsTableLamp2Light.prototype.getServices = function() { secondLightOnCharacteristic .on('get', function(callback) { this.device.call("get_prop", ["ambstatus"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - SecondLight - getPower: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - SecondLight (" + that.device.address + ") - getPower: " + result); callback(null, result[0] === 'on' && mainLightOnCharacteristic.value ? true : false); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - SecondLight - getPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - SecondLight (" + that.device.address + ") - getPower Error: " + err); callback(err); }); }.bind(this)) .on('set', function(value, callback) { that.device.call("enable_amb", [value ? "on" : "off"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - SecondLight - setPower Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - SecondLight (" + that.device.address + ") - setPower Result: " + result); if(result[0] === "ok") { if(value) { mainLightOnCharacteristic.getValue(); @@ -147,7 +147,7 @@ MiPhilipsTableLamp2Light.prototype.getServices = function() { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - SecondLight - setPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - SecondLight (" + that.device.address + ") - setPower Error: " + err); callback(err); }); }.bind(this)); @@ -155,24 +155,24 @@ MiPhilipsTableLamp2Light.prototype.getServices = function() { .addCharacteristic(Characteristic.Brightness) .on('get', function(callback) { this.device.call("get_prop", ["ambvalue"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - SecondLight - getBrightness: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - SecondLight (" + that.device.address + ") - getBrightness: " + result); callback(null, result[0]); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - SecondLight - getBrightness Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - SecondLight (" + that.device.address + ") - getBrightness Error: " + err); callback(err); }); }.bind(this)) .on('set', function(value, callback) { if(value > 0) { this.device.call("set_amb_bright", [value]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - SecondLight - setBrightness Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - SecondLight (" + that.device.address + ") - setBrightness Result: " + result); if(result[0] === "ok") { callback(null); } else { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - SecondLight - setBrightness Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - SecondLight (" + that.device.address + ") - setBrightness Error: " + err); callback(err); }); } else { @@ -186,16 +186,16 @@ MiPhilipsTableLamp2Light.prototype.getServices = function() { eyecareSwitchOnCharacteristic .on('get', function(callback) { this.device.call("get_prop", ["eyecare"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - EyecareSwitch - getPower: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - EyecareSwitch (" + that.device.address + ") - getPower: " + result); callback(null, result[0] === 'on' && mainLightOnCharacteristic.value ? true : false); }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - EyecareSwitch - getPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - EyecareSwitch (" + that.device.address + ") - getPower Error: " + err); callback(err); }); }.bind(this)) .on('set', function(value, callback) { that.device.call("set_eyecare", [value ? "on" : "off"]).then(result => { - that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - EyecareSwitch - setPower Result: " + result); + that.platform.log.debug("[MiPhilipsLightPlatform][DEBUG]MiPhilipsTableLamp2 - EyecareSwitch (" + that.device.address + ") - setPower Result: " + result); if(result[0] === "ok") { if(value) { mainLightOnCharacteristic.getValue(); @@ -206,7 +206,7 @@ MiPhilipsTableLamp2Light.prototype.getServices = function() { callback(new Error(result[0])); } }).catch(function(err) { - that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - EyecareSwitch - setPower Error: " + err); + that.platform.log.error("[MiPhilipsLightPlatform][ERROR]MiPhilipsTableLamp2 - EyecareSwitch (" + that.device.address + ") - setPower Error: " + err); callback(err); }); }.bind(this));