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)); diff --git a/README.md b/README.md index bd81c0c..fa59647 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,12 @@ miio --discover --sync ``` Wait until you get output. For more information about token, please refer to [OpenMiHome](https://github.com/OpenMiHome/mihome-binary-protocol) and [miio](https://github.com/aholstenson/miio). + ## Version Logs +### 0.3 (2020-05-27) +1. Added IP address to logs. +2. Added Homebridge-Config-UI support. + ### 0.2.3 (2018-02-10) 1.update 'package.json'. ### 0.2.2 (2017-11-18) diff --git a/config.schema.json b/config.schema.json new file mode 100644 index 0000000..a8b1482 --- /dev/null +++ b/config.schema.json @@ -0,0 +1,57 @@ +{ + "pluginAlias": "MiPhilipsLightPlatform", + "pluginType": "platform", + "singular": true, + "headerDisplay": "Add individual lights below.", + "schema": { + "deviceCfgs": { + "title": "Devices", + "type": "array", + "items": { + "title": "Light Config", + "type": "object", + "properties": { + "type": { + "title": "Light Model", + "type": "string", + "required": true, + "oneOf": [{ + "title": "MiPhilipsSmartBulb", + "enum": ["MiPhilipsSmartBulb"] + }, + { + "title": "MiPhilipsTableLamp2", + "enum": ["MiPhilipsTableLamp2"] + }, + { + "title": "MiPhilipsCeilingLamp", + "enum": ["MiPhilipsCeilingLamp"] + } + ] + }, + "ip": { + "title": "IP Address", + "type": "string", + "required": true, + "format": "ipv4" + }, + "token": { + "title": "Token", + "type": "string", + "required": true + }, + "lightName": { + "title": "Name", + "type": "string", + "required": true + }, + "lightDisable": { + "title": "Disabled", + "type": "boolean", + "default": false + } + } + } + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index b6a7b31..b746831 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-mi-philips-light", - "version": "0.2.3", + "version": "0.3.0", "description": "XiaoMi Philips light plugins for HomeBridge(https://github.com/nfarina/homebridge).", "keywords": [ "homebridge-plugin",