From 28c35a33c3994c29dae4773f3259f8631ec5e1af Mon Sep 17 00:00:00 2001 From: RWensveen Date: Sat, 14 Jul 2018 21:43:19 +0200 Subject: [PATCH] add ip address to device settings --- app.js | 15 +-- app.json | 250 ++++++++++++++++++++++++++++--------- drivers/A1/device.js | 75 +---------- drivers/BroadlinkDevice.js | 62 ++++++++- drivers/BroadlinkDriver.js | 5 +- drivers/MP1/device.js | 49 +------- drivers/RM3_mini/device.js | 22 +--- drivers/RM3_mini/driver.js | 5 +- drivers/SP1/device.js | 2 - drivers/SP1/driver.js | 5 +- drivers/SP2/device.js | 67 +++------- drivers/SP3S/device.js | 2 +- drivers/SP3S/driver.js | 76 ++++++----- lib/Communicate.js | 14 +++ lib/DeviceInfo.js | 4 +- lib/util.js | 9 +- locales/en.json | 6 +- locales/nl.json | 6 +- 18 files changed, 358 insertions(+), 316 deletions(-) diff --git a/app.js b/app.js index 3a8e237..bf3f198 100644 --- a/app.js +++ b/app.js @@ -22,26 +22,15 @@ const Homey = require('homey'); const Util = require('./../lib/util.js'); -/* -.registerRunListener(( args, state, callback ) => { - // @param: args = trigger settings from app.json - // @param: state = data from trigger-event - -.registerAutocompleteListener(( query, args ) => { - // @param: query = name of already selected item in flowcard - // or empty string if no selection yet - // @param: args = other args of flow (i.e. this device) - // @return: [Promise]->return list of {name,description,anything_programmer_wants} -*/ - - /** * Main entry point for app. */ class BroadlinkApp extends Homey.App { onInit() { + } + } module.exports = BroadlinkApp; diff --git a/app.json b/app.json index d6d6810..2adbe0c 100644 --- a/app.json +++ b/app.json @@ -220,6 +220,19 @@ { "id": "RcCmd18", "type": "text", "value": "", "label": { "en": "19" } }, { "id": "RcCmd19", "type": "text", "value": "", "label": { "en": "20" } } ] + }, + { + "type":"group", + "label": { "en": "Address", "nl": "Adres" }, + "children": [ + { + "type": "text", + "id": "ipAddress", + "label": { "en": "IP address", "nl": "IP adres" }, + "value": "0.0.0.0", + "pattern": "^([1-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){2}([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$" + } + ] } ] }, @@ -315,6 +328,19 @@ { "id": "RcCmd28", "type": "text", "value": "", "label": { "en": "29" } }, { "id": "RcCmd29", "type": "text", "value": "", "label": { "en": "30" } } ] + }, + { + "type":"group", + "label": { "en": "Address", "nl": "Adres" }, + "children": [ + { + "type": "text", + "id": "ipAddress", + "label": { "en": "IP address", "nl": "IP adres" }, + "value": "0.0.0.0", + "pattern": "^([1-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){2}([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$" + } + ] } ] }, @@ -396,6 +422,19 @@ { "id": "RcCmd18", "type": "text", "value": "", "label": { "en": "19" } }, { "id": "RcCmd19", "type": "text", "value": "", "label": { "en": "20" } } ] + }, + { + "type":"group", + "label": { "en": "Address", "nl": "Adres" }, + "children": [ + { + "type": "text", + "id": "ipAddress", + "label": { "en": "IP address", "nl": "IP adres" }, + "value": "0.0.0.0", + "pattern": "^([1-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){2}([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$" + } + ] } ] }, @@ -471,21 +510,40 @@ ], "settings": [ { - "id": "CheckInterval", - "type": "number", - "value": 5, - "label": { - "en": "Interval", - "nl": "Interval" - }, - "hint": { - "en": "Time in minutes between reading of sensor values.", - "nl": "Tijd tussen het lezen van de sensor waarden, in minuten." - }, - "attr": { - "min": 1, - "max": 3600 - } + "type": "group", + "label": {"en": "Timing", "nl": "Tijdschema"}, + "children" : [ + { + "id": "CheckInterval", + "type": "number", + "value": 5, + "label": { + "en": "Interval", + "nl": "Interval" + }, + "hint": { + "en": "Time in minutes between reading of sensor values.", + "nl": "Tijd tussen het lezen van de sensor waarden, in minuten." + }, + "attr": { + "min": 1, + "max": 3600 + } + } + ] + }, + { + "type":"group", + "label": { "en": "Address", "nl": "Adres" }, + "children": [ + { + "type": "text", + "id": "ipAddress", + "label": { "en": "IP address", "nl": "IP adres" }, + "value": "0.0.0.0", + "pattern": "^([1-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){2}([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$" + } + ] } ] }, @@ -527,6 +585,21 @@ "id": "add_devices", "template": "add_devices" } + ], + "settings" : [ + { + "type":"group", + "label": { "en": "Address", "nl": "Adres" }, + "children": [ + { + "type": "text", + "id": "ipAddress", + "label": { "en": "IP address", "nl": "IP adres" }, + "value": "0.0.0.0", + "pattern": "^([1-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){2}([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$" + } + ] + } ] }, { @@ -588,21 +661,40 @@ ], "settings": [ { - "id": "CheckInterval", - "type": "number", - "value": 5, - "label": { - "en": "Interval", - "nl": "Interval" - }, - "hint": { - "en": "Time in minutes between reading of device status.", - "nl": "Tijd tussen het lezen van de apparaatstatus, in minuten." - }, - "attr": { - "min": 1, - "max": 3600 - } + "type": "group", + "label": {"en": "Timing", "nl": "Tijdschema"}, + "children" : [ + { + "id": "CheckInterval", + "type": "number", + "value": 5, + "label": { + "en": "Interval", + "nl": "Interval" + }, + "hint": { + "en": "Time in minutes between reading of device status.", + "nl": "Tijd tussen het lezen van de apparaatstatus, in minuten." + }, + "attr": { + "min": 1, + "max": 3600 + } + } + ] + }, + { + "type":"group", + "label": { "en": "Address", "nl": "Adres" }, + "children": [ + { + "type": "text", + "id": "ipAddress", + "label": { "en": "IP address", "nl": "IP adres" }, + "value": "0.0.0.0", + "pattern": "^([1-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){2}([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$" + } + ] } ] }, @@ -665,21 +757,40 @@ ], "settings": [ { - "id": "CheckInterval", - "type": "number", - "value": 5, - "label": { - "en": "Interval", - "nl": "Interval" - }, - "hint": { - "en": "Time in minutes between reading of device status.", - "nl": "Tijd tussen het lezen van de apparaatstatus, in minuten." - }, - "attr": { - "min": 1, - "max": 3600 - } + "type": "group", + "label": {"en": "Timing", "nl": "Tijdschema"}, + "children" : [ + { + "id": "CheckInterval", + "type": "number", + "value": 5, + "label": { + "en": "Interval", + "nl": "Interval" + }, + "hint": { + "en": "Time in minutes between reading of device status.", + "nl": "Tijd tussen het lezen van de apparaatstatus, in minuten." + }, + "attr": { + "min": 1, + "max": 3600 + } + } + ] + }, + { + "type":"group", + "label": { "en": "Address", "nl": "Adres" }, + "children": [ + { + "type": "text", + "id": "ipAddress", + "label": { "en": "IP address", "nl": "IP adres" }, + "value": "0.0.0.0", + "pattern": "^([1-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){2}([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$" + } + ] } ] }, @@ -746,21 +857,40 @@ ], "settings": [ { - "id": "CheckInterval", - "type": "number", - "value": 5, - "label": { - "en": "Interval", - "nl": "Interval" - }, - "hint": { - "en": "Time in minutes between reading of device status.", - "nl": "Tijd tussen het lezen van de apparaatstatus, in minuten." - }, - "attr": { - "min": 1, - "max": 3600 - } + "type": "group", + "label": {"en": "Timing", "nl": "Tijdschema"}, + "children" : [ + { + "id": "CheckInterval", + "type": "number", + "value": 5, + "label": { + "en": "Interval", + "nl": "Interval" + }, + "hint": { + "en": "Time in minutes between reading of device status.", + "nl": "Tijd tussen het lezen van de apparaatstatus, in minuten." + }, + "attr": { + "min": 1, + "max": 3600 + } + } + ] + }, + { + "type":"group", + "label": { "en": "Address", "nl": "Adres" }, + "children": [ + { + "type": "text", + "id": "ipAddress", + "label": { "en": "IP address", "nl": "IP adres" }, + "value": "0.0.0.0", + "pattern": "^([1-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){2}([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$" + } + ] } ] } diff --git a/drivers/A1/device.js b/drivers/A1/device.js index 1fbfd64..f510b40 100644 --- a/drivers/A1/device.js +++ b/drivers/A1/device.js @@ -54,25 +54,8 @@ class A1Device extends BroadlinkDevice { this.light_level = LightLevel.unknown.value; this.noise_level = NoiseLevel.unknown.value; } - - - start_sensor_check( interval ) { - var that = this - this.checkTimer = setInterval( function() { - that.check_sensors(); - }, - interval * 60 * 1000); // [minutes] to [msec] - } - - - stop_sensor_check() { - if( this.checkTimer ) { - clearInterval( this.checkTimer) - this.checkTimer = undefined - } - } - - + + getAirQualityList(mode) { if(mode == 'better') { return [ @@ -177,57 +160,11 @@ class A1Device extends BroadlinkDevice { callback(null, args.variable.value < args.device.noise_level ) } - - onInit() { - super.onInit(); - - this.getDriver() - .ready( () => { - this.start_sensor_check( this.getSetting('CheckInterval') ) - //this.check_sensors(); - }) - } - - /** - * This method is called when the user adds the device, called just after pairing. - */ - onAdded() { - super.onAdded(); - } - - - /** - * This method will be called when a device has been removed. - */ - onDeleted() { - super.onDeleted(); - this.stop_sensor_check(); - } - - - /** - * Called when the device settings are changed by the user - * (so NOT called on programmatically changing settings) - * - * @param changedKeysArr contains an array of keys that have been changed - */ - onSettings( oldSettingsObj, newSettingsObj, changedKeysArr, callback ) { - - if( changedKeysArr.indexOf('CheckInterval') >= 0 ) { - this.stop_sensor_check() - this.start_sensor_check( newSettingsObj['CheckInterval'] ) - } - callback( null, true ); - } - - - /** - * - * + * Called when the periodic timer expires */ - check_sensors() + onCheckInterval() { this._communicate.read_status() .then( response => { @@ -291,10 +228,10 @@ class A1Device extends BroadlinkDevice { if( curr_noise != this.noise_level ) { drv.a1_trigger_noise_level.trigger(this,{'noiselevel':str_noise},{}) } }, rejectReason => { - Util.debugLog('**> device.check_sensors: ' + rejectReason) + Util.debugLog('**> ' + this.getName() + '.onCheckInterval: ' + rejectReason) }) .catch(err => { - Util.debugLog('**> device.check_sensors: catch = ' + err) + Util.debugLog('**> '+this.getName()+'.onCheckInterval: catch = ' + err) }) } diff --git a/drivers/BroadlinkDevice.js b/drivers/BroadlinkDevice.js index bfd1122..004677c 100644 --- a/drivers/BroadlinkDevice.js +++ b/drivers/BroadlinkDevice.js @@ -46,6 +46,15 @@ class BroadlinkDevice extends Homey.Device { this._communicate = new Communicate() this._communicate.configure( options ) + + this.getDriver() + .ready( () => { + // if the driver has a CheckInterval, set it. otherwise ignore it. + let ci = this.getSetting('CheckInterval'); + if( ci ) { + this.start_check_interval( ci ) + } + }) } @@ -83,18 +92,67 @@ class BroadlinkDevice extends Homey.Device { .catch( err => { Util.debugLog( '**> authentication error: ' + err); }) - } - /** * This method will be called when a device has been removed. */ onDeleted() { + this.stop_check_interval(); + this._communicate.destroy(); this._communicate = null; } + + /** + * Called when the device settings are changed by the user + * (so NOT called on programmatically changing settings) + * + * @param changedKeysArr contains an array of keys that have been changed + */ + onSettings( oldSettingsObj, newSettingsObj, changedKeysArr, callback ) { + + if( changedKeysArr.indexOf('ipAddress') >= 0 ) { + this._communicate.setIPaddress( newSettingsObj['ipAddress'] ) + Util.debugLog(this.getName() + ' - onSettings - new ipaddress = ' + this._communicate.ipAddress); + } + if( changedKeysArr.indexOf('CheckInterval') >= 0 ) { + this.stop_check_interval() + this.start_check_interval( newSettingsObj['CheckInterval'] ) + } + if( callback ) { + /* only do callback if this functions was called by Homey. + * if it was called by another class, that class will do the callback. + */ + callback( null, true ); + } + } + + + /** + * Start a timer to periodically access the device. the parent class must implement onCheckInterval() + */ + start_check_interval( interval ) { + Util.debugLog(this.getName()+' start check interval - ' + interval); + var that = this + this.checkTimer = setInterval( function() { + that.onCheckInterval(); + }, + interval * 60000); // [minutes] to [msec] + } + + + /** + * Stop the periodic timer + */ + stop_check_interval() { + if( this.checkTimer ) { + clearInterval( this.checkTimer ) + this.checkTimer = null + } + } + } module.exports = BroadlinkDevice; diff --git a/drivers/BroadlinkDriver.js b/drivers/BroadlinkDriver.js index 458a398..2809407 100644 --- a/drivers/BroadlinkDriver.js +++ b/drivers/BroadlinkDriver.js @@ -35,8 +35,9 @@ class BroadlinkDriver extends Homey.Driver { */ onInit(options) { // options - this.CompatibilityID = options.CompatibilityID; - + if( options ) { + this.CompatibilityID = options.CompatibilityID; + } // list of devices discovered during pairing this.discoveredDevices = []; } diff --git a/drivers/MP1/device.js b/drivers/MP1/device.js index 34335be..d7e76ef 100644 --- a/drivers/MP1/device.js +++ b/drivers/MP1/device.js @@ -41,24 +41,7 @@ class MP1Device extends BroadlinkDevice { } } - start_state_check( interval ) { - var that = this - this.checkTimer = setInterval( function() { - that.check_power_state(); - }, - interval * 60000); // [minutes] to [msec] - } - - - stop_state_check() { - if( this.checkTimer ) { - clearInterval( this.checkTimer); - this.checkTimer = null; - } - } - - /** * Send 'on/off' command to the device. * @@ -71,18 +54,17 @@ class MP1Device extends BroadlinkDevice { this.generate_trigger( sid, mode ); return Promise.resolve(true) }, rejection => { - Util.debugLog(' set_onoff - rejection' + rejection) + return Promise.reject('') }) .catch( err => { - Util.debugLog('**>MP1device.onCapabilityOnOff - catch = ' + err); }) } /** * Returns the power state of the smart power strip. */ - check_power_state() { - return this._communicate.mp1_set_power_state() + onCheckInterval() { + return this._communicate.mp1_check_power() .then( state => { let s1,s2,s3,s4; s1 = ( state & 0x01 ); @@ -107,7 +89,7 @@ class MP1Device extends BroadlinkDevice { let onoff = this.getCapabilityValue( capa ) callback(null,onoff) } - + do_action_on(sid) { let capa = 'onoff.s' + sid this.set_onoff(sid, true) @@ -126,7 +108,8 @@ class MP1Device extends BroadlinkDevice { onCapabilityOnOff_2(mode) { this.set_onoff( "2", mode ); } onCapabilityOnOff_3(mode) { this.set_onoff( "3", mode ); } onCapabilityOnOff_4(mode) { this.set_onoff( "4", mode ); } - + + onInit() { super.onInit(); this.registerCapabilityListener('onoff.s1', this.onCapabilityOnOff_1.bind(this) ) @@ -134,26 +117,6 @@ class MP1Device extends BroadlinkDevice { this.registerCapabilityListener('onoff.s3', this.onCapabilityOnOff_3.bind(this) ) this.registerCapabilityListener('onoff.s4', this.onCapabilityOnOff_4.bind(this) ) } - - /** - * This method is called when the user adds the device, called just after pairing. - */ - onAdded() { - super.onAdded(); - this.getDriver() - .ready( () => { - this.start_state_check( this.getSetting('CheckInterval') ) - }) - } - - - /** - * This method will be called when a device has been removed. - */ - onDeleted() { - super.onDeleted(); - this.stop_state_check(); - } } diff --git a/drivers/RM3_mini/device.js b/drivers/RM3_mini/device.js index 2ab3859..470c3dd 100644 --- a/drivers/RM3_mini/device.js +++ b/drivers/RM3_mini/device.js @@ -38,8 +38,9 @@ class RM3miniDevice extends BroadlinkDevice { var idx = 0; let settingName = 'RcCmd' + idx; while( settingName in settings) { + Util.debugLog( settingName ); if( settings[ settingName ].length == 0 ) { - + Util.debugLog(this.getName()+' - storeCmdSettings - name = ' + cmdname ); let s = { [settingName] : cmdname } @@ -117,22 +118,6 @@ class RM3miniDevice extends BroadlinkDevice { } - /** - * This method is called when the user adds the device, called just after pairing. - */ - onAdded() { - super.onAdded(); - } - - - /** - * This method will be called when a device has been removed. - */ - onDeleted() { - super.onDeleted() - } - - /** * This method will be called when the learn state needs to be changed. * @param onoff @@ -178,6 +163,9 @@ class RM3miniDevice extends BroadlinkDevice { * @param changedKeysArr contains an array of keys that have been changed */ onSettings( oldSettingsObj, newSettingsObj, changedKeysArr, callback ) { + + super.onSettings( oldSettingsObj, newSettingsObj, changedKeysArr, null ); + let i = 0; let oldName = ''; let newName = ''; diff --git a/drivers/RM3_mini/driver.js b/drivers/RM3_mini/driver.js index f5c1dfb..0e25f49 100644 --- a/drivers/RM3_mini/driver.js +++ b/drivers/RM3_mini/driver.js @@ -36,9 +36,8 @@ class BroadlinkRM3miniDriver extends BroadlinkDriver { onInit() { - super.onInit({ - CompatibilityID: 0x2737 // RM MINI - }); + super.onInit(); + this.setCompatibilityID( 0x2737 ) // RM MINI this.rm3mini_action_send_cmd = new Homey.FlowCardAction('send_command'); this.rm3mini_action_send_cmd diff --git a/drivers/SP1/device.js b/drivers/SP1/device.js index 1ad4b98..0d3dd02 100644 --- a/drivers/SP1/device.js +++ b/drivers/SP1/device.js @@ -23,10 +23,8 @@ const BroadlinkDevice = require('./../BroadlinkDevice'); class SP1Device extends BroadlinkDevice { - - /** * Send a command to the device. The command was previously retrieved * with check_IR_data() diff --git a/drivers/SP1/driver.js b/drivers/SP1/driver.js index 8bde5cc..87a32c1 100644 --- a/drivers/SP1/driver.js +++ b/drivers/SP1/driver.js @@ -24,8 +24,7 @@ const Util = require('./../../lib/util.js'); class BroadlinkSP1Driver extends BroadlinkDriver { - - + sp1_check_condition_on( args, state, callback ) { return args.device.check_condition_on( callback ) @@ -39,7 +38,7 @@ class BroadlinkSP1Driver extends BroadlinkDriver { return args.device.do_action_off() } - + onInit() { super.onInit({ CompatibilityID: 0x0000 // SP1 diff --git a/drivers/SP2/device.js b/drivers/SP2/device.js index dccefd9..12bd824 100644 --- a/drivers/SP2/device.js +++ b/drivers/SP2/device.js @@ -19,7 +19,7 @@ 'use strict'; const Homey = require('homey'); -//const Util = require('./../../lib/util.js'); +const Util = require('./../../lib/util.js'); const BroadlinkDevice = require('./../BroadlinkDevice'); @@ -53,14 +53,12 @@ class SP2Device extends BroadlinkDevice { } - start_state_check( interval ) { + onCheckInterval( interval ) { - var that = this - this.checkTimer = setInterval( function() { - that.get_energy() - .then ( energy => { - that.setCapabilityValue('measure_power', energy); - this._communicate.read_status() + this.get_energy() + .then ( energy => { + that.setCapabilityValue('measure_power', energy); + this._communicate.read_status() .then( response => { let state = (( response[0] == 2 ) || ( response[0] == 3 )) @@ -70,22 +68,13 @@ class SP2Device extends BroadlinkDevice { state = (( response[0] == 1 ) || (response[0] == 3 )); that.generate_trigger_power(state); that.setCapabilityValue('onoff.power',state); - }) }, error => { }) - }, - interval * 60000); // [minutes] to [msec] + }, error => { + }) } - stop_state_check() { - if( this.checkTimer ) { - clearInterval( this.checkTimer); - this.checkTimer=undefined; - } - } - - /** * */ @@ -184,8 +173,8 @@ class SP2Device extends BroadlinkDevice { }, rejection => { }) } - - + + check_condition_power_on(callback) { this.check_power() .then( onoff => { callback(null, onoff ); @@ -193,7 +182,6 @@ class SP2Device extends BroadlinkDevice { }) } - check_condition_nightlight_on(callback) { this.check_nightlight() .then( onoff => { callback(null, onoff ); @@ -201,22 +189,25 @@ class SP2Device extends BroadlinkDevice { }) } - + do_action_power_on() { this.onCapabilityPowerOnOff(true) .then( r => { this.setCapabilityValue('onoff.power', true); }) } + do_action_power_off() { this.onCapabilityPowerOnOff(false) .then( r => { this.setCapabilityValue('onoff.power', false); }) } + do_action_nightlight_on() { this.onCapabilityNightLightOnOff(true) .then( r => { this.setCapabilityValue('onoff.nightlight', true) }) } + do_action_nightlight_off() { this.onCapabilityNightLightOnOff(false) .then( r => { this.setCapabilityValue('onoff.nightlight', false) @@ -228,36 +219,6 @@ class SP2Device extends BroadlinkDevice { super.onInit(); this.registerCapabilityListener('onoff.power', this.onCapabilityPowerOnOff.bind(this)); this.registerCapabilityListener('onoff.nightlight', this.onCapabilityNightLightOnOff.bind(this)); - - this.getDriver() - .ready( () => { - this.start_state_check( this.getSetting('CheckInterval') ) - }) - } - - - /** - * This method will be called when a device has been removed. - */ - onDeleted() { - super.onDeleted(); - this.stop_state_check(); - } - - - /** - * Called when the device settings are changed by the user - * (so NOT called on programmatically changing settings) - * - * @param changedKeysArr contains an array of keys that have been changed - */ - onSettings( oldSettingsObj, newSettingsObj, changedKeysArr, callback ) { - - if( changedKeysArr.indexOf('CheckInterval') >= 0 ) { - this.stop_state_check() - this.start_state_check( newSettingsObj['CheckInterval'] ) - } - callback( null, true ); } } diff --git a/drivers/SP3S/device.js b/drivers/SP3S/device.js index 1d4fcef..03cbc45 100644 --- a/drivers/SP3S/device.js +++ b/drivers/SP3S/device.js @@ -23,7 +23,7 @@ const Util = require('./../../lib/util.js'); const SP2Device = require('./../SP2/device'); -class SP3SDevice extends SP2Device { +class SP3SDevice extends SP2Device { } diff --git a/drivers/SP3S/driver.js b/drivers/SP3S/driver.js index 337cca6..33b8637 100644 --- a/drivers/SP3S/driver.js +++ b/drivers/SP3S/driver.js @@ -25,7 +25,6 @@ const BroadlinkDriver = require('./../BroadlinkDriver'); class SP3SDriver extends BroadlinkDriver { - check_condition_power_on( args, state, callback ) { args.device.check_condition_power_on(callback) } @@ -55,44 +54,43 @@ class SP3SDriver extends BroadlinkDriver { CompatibilityID: 0x9479 // SP3S }); - - this.trigger_power_toggle = new Homey.FlowCardTriggerDevice('sp3s_onoff_power').register(); - this.trigger_power_on = new Homey.FlowCardTriggerDevice('sp3s_onoff_power_on').register(); - this.trigger_power_off = new Homey.FlowCardTriggerDevice('sp3s_onoff_power_off').register(); - - this.trigger_nightlight_toggle = new Homey.FlowCardTriggerDevice('sp3s_onoff_nightlight').register(); - this.trigger_nightlight_on = new Homey.FlowCardTriggerDevice('sp3s_onoff_nightlight_on').register(); - this.trigger_nightlight_off = new Homey.FlowCardTriggerDevice('sp3s_onoff_nightlight_off').register(); - - this.condition_power_on = new Homey.FlowCardCondition('sp3s_onoff_power_on'); - this.condition_power_on - .register() - .registerRunListener(this.check_condition_power_on.bind(this) ) - - this.condition_nightlight_on = new Homey.FlowCardCondition('sp3s_onoff_nightlight_on'); - this.condition_nightlight_on - .register() - .registerRunListener(this.check_condition_nightlight_on.bind(this) ) - - this.action_power_on = new Homey.FlowCardAction('sp3s_onoff_power_on'); - this.action_power_on - .register() - .registerRunListener(this.do_action_power_on.bind(this)) - - this.action_power_off = new Homey.FlowCardAction('sp3s_onoff_power_off'); - this.action_power_off - .register() - .registerRunListener(this.do_action_power_off.bind(this)) - - this.action_nightlight_on = new Homey.FlowCardAction('sp3s_onoff_nightlight_on'); - this.action_nightlight_on - .register() - .registerRunListener(this.do_action_nightlight_on.bind(this)) - - this.action_nightlight_off = new Homey.FlowCardAction('sp3s_onoff_nightlight_off'); - this.action_nightlight_off - .register() - .registerRunListener(this.do_action_nightlight_off.bind(this)) + this.trigger_power_toggle = new Homey.FlowCardTriggerDevice('sp3s_onoff_power').register(); + this.trigger_power_on = new Homey.FlowCardTriggerDevice('sp3s_onoff_power_on').register(); + this.trigger_power_off = new Homey.FlowCardTriggerDevice('sp3s_onoff_power_off').register(); + + this.trigger_nightlight_toggle = new Homey.FlowCardTriggerDevice('sp3s_onoff_nightlight').register(); + this.trigger_nightlight_on = new Homey.FlowCardTriggerDevice('sp3s_onoff_nightlight_on').register(); + this.trigger_nightlight_off = new Homey.FlowCardTriggerDevice('sp3s_onoff_nightlight_off').register(); + + this.condition_power_on = new Homey.FlowCardCondition('sp3s_onoff_power_on'); + this.condition_power_on + .register() + .registerRunListener(this.check_condition_power_on.bind(this) ) + + this.condition_nightlight_on = new Homey.FlowCardCondition('sp3s_onoff_nightlight_on'); + this.condition_nightlight_on + .register() + .registerRunListener(this.check_condition_nightlight_on.bind(this) ) + + this.action_power_on = new Homey.FlowCardAction('sp3s_onoff_power_on'); + this.action_power_on + .register() + .registerRunListener(this.do_action_power_on.bind(this)) + + this.action_power_off = new Homey.FlowCardAction('sp3s_onoff_power_off'); + this.action_power_off + .register() + .registerRunListener(this.do_action_power_off.bind(this)) + + this.action_nightlight_on = new Homey.FlowCardAction('sp3s_onoff_nightlight_on'); + this.action_nightlight_on + .register() + .registerRunListener(this.do_action_nightlight_on.bind(this)) + + this.action_nightlight_off = new Homey.FlowCardAction('sp3s_onoff_nightlight_off'); + this.action_nightlight_off + .register() + .registerRunListener(this.do_action_nightlight_off.bind(this)) } } diff --git a/lib/Communicate.js b/lib/Communicate.js index 071a3d3..979917c 100644 --- a/lib/Communicate.js +++ b/lib/Communicate.js @@ -70,7 +70,15 @@ class Communicate { this.iv = new Uint8Array([0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58]) } + + /** + * Update the IPaddress. + */ + setIPaddress( address ) { + this.ipAddress = address + } + /** * */ @@ -579,9 +587,11 @@ class Communicate { resolve( p ) } else { + Util.debugLog('**> read_status: ongeldig antwoord van apparaat'); reject( Homey.__('errors.invalid_response')) } }, rejection => { + Util.debugLog('**> read_status: reject - ' + rejection); reject( rejection ); }) .catch( err => { @@ -631,9 +641,11 @@ class Communicate { resolve( p ) } else { + Util.debugLog('**> sp2_get_energy: ongeldig antwoord van apparaat'); reject( Homey.__('errors.invalid_response')) } }, rejection => { + Util.debugLog('**> read_status: reject - '+rejection); reject( rejection ); }) .catch( err => { @@ -670,9 +682,11 @@ class Communicate { Promise.resolve( payload[ 0x0e ] ) } else { + Util.debugLog('**> mp1_check_power: ongeldig antwoord van apparaat'); Promise.reject( Homey.__('errors.invalid_response')) } }, rejection => { + Util.debugLog('**> mp1_check_power: reject' + rejection); Promise.reject( rejection ); }) .catch( err => { diff --git a/lib/DeviceInfo.js b/lib/DeviceInfo.js index 79241e2..7f00968 100644 --- a/lib/DeviceInfo.js +++ b/lib/DeviceInfo.js @@ -118,8 +118,8 @@ exports.getDeviceInfo = function( founddevID, expecteddevID ) { if( foundInfo.type == expectedInfo.type ) { foundInfo.isCompatible = true; } - let mode = Homey.ManagerSettings.get('CompatSettings'); - if( mode ) { + let s = Homey.ManagerSettings.get('DebugSettings'); + if(( s ) && ( s['compat']) ) { foundInfo.isCompatible = true; // TODO: DEBUG ONLY Util.debugLog('getDeviceInfo: found = ' + founddevID + ' expected = ' + expecteddevID + ' isComp = ' + foundInfo.isCompatible) } diff --git a/lib/util.js b/lib/util.js index 47fb6a8..bc4637c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -22,13 +22,16 @@ const Homey = require('homey') exports.debugLog = function (message, data) { - console.log(this.epochToTimeFormatter(), message, data || '') + let s = Homey.ManagerSettings.get('DebugSettings'); + if( ( s ) && ( s['logging']) ) { + console.log(this.epochToTimeFormatter(), message, data || '') + } } exports.epochToTimeFormatter = function (epoch) { - if (epoch == null) epoch = new Date().getTime() - return (new Date(epoch)).toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1') + if (epoch == null) epoch = new Date().getTime() + return (new Date(epoch)).toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1') } diff --git a/locales/en.json b/locales/en.json index 5f012c7..651bb21 100644 --- a/locales/en.json +++ b/locales/en.json @@ -26,8 +26,10 @@ }, "settings":{ "title": "Broadlink Debug Settings", - "intro": "In compatibility mode, any device found during pairing will be accepted as the selected device type. This means the device paired will be treated as the choosen device type. As a result, not all (if any) of the capablities of the device will work properly", - "compatmode": "Compatibility mode" + "compatinfo": "In compatibility mode, any device found during pairing will be accepted as the selected device type. This means the device paired will be treated as the choosen device type. As a result, not all (if any) of the capablities of the device will work properly", + "compatmode": "Compatibility Mode", + "debuginfo": "Write logging text to console. This is only valid if app is loaded in debug mode.", + "debuglog" : "Log Mode" }, "air_quality": { "excellent": "excellent", diff --git a/locales/nl.json b/locales/nl.json index aa42a19..5b84da3 100644 --- a/locales/nl.json +++ b/locales/nl.json @@ -26,8 +26,10 @@ }, "settings":{ "title": "Broadlink Debug Instellingen", - "intro": "In eenheidsmode, ieder apparaat dat gevonden wordt tijdens paren, zal geaccepteerd worden alsof het van het gewenste type is. Dit betekent dat het geinstalleerde apparaat aangesproken wordt alsof het een apparaat van dat type is. Hierdoor zullen niet alle (of zelfs geen enkele) van zijn mogelijkheden naar behoren werken.", - "compatmode": "Eenheidsmode" + "compatinfo": "In eenheidsmode, ieder apparaat dat gevonden wordt tijdens paren, zal geaccepteerd worden alsof het van het gewenste type is. Dit betekent dat het geinstalleerde apparaat aangesproken wordt alsof het een apparaat van dat type is. Hierdoor zullen niet alle (of zelfs geen enkele) van zijn mogelijkheden naar behoren werken.", + "compatmode": "Eenheidsmode", + "debuginfo": "Schrijf log teksten naar console. Werkt alleen als app in debug mode is geladen.", + "debuglog" : "Logmode" }, "air_quality": { "excellent": "uitstekend",