homebridge-tuya-outlet
Advanced tools
Comparing version 1.0.1 to 1.1.0
28
index.js
const tuya = require('tuyapi'); | ||
const debug = require('debug')('homebridge-tuya'); | ||
@@ -13,3 +14,9 @@ module.exports = function(homebridge) { | ||
this.name = config.name; | ||
this.tuya = new tuya({type: 'outlet', ip: config.ip, id: config.devId, uid: config.uid, key: config.localKey}); | ||
if (config.ip != undefined) { | ||
this.tuya = new tuya({type: 'outlet', ip: config.ip, id: config.devId, key: config.localKey}); | ||
} | ||
else { | ||
this.tuya = new tuya({type: 'outlet', id: config.devId, key: config.localKey}); | ||
this.tuya.resolveIds(); | ||
} | ||
@@ -22,6 +29,8 @@ this._service = new Service.Outlet(this.name); | ||
TuyaOutlet.prototype._setOn = function(on, callback) { | ||
this.log("Setting device to " + on); | ||
this.tuya.setStatus(on, (error, result) => { | ||
if (error) { return callback(error, null); } | ||
debug("Setting device to " + on); | ||
this.tuya.set({set: on}).then(() => { | ||
return callback(null, true); | ||
}).catch(error => { | ||
return callback(error, null); | ||
}); | ||
@@ -31,6 +40,7 @@ } | ||
TuyaOutlet.prototype._get = function(callback) { | ||
this.log("Getting device status..."); | ||
this.tuya.getStatus((error, result) => { | ||
if (error) { return callback(error, null); } | ||
return callback(null, result); | ||
debug("Getting device status..."); | ||
this.tuya.get().then(status => { | ||
return callback(null, status); | ||
}).catch(error => { | ||
callback(error, null); | ||
}); | ||
@@ -44,4 +54,4 @@ } | ||
TuyaOutlet.prototype.identify = function (callback) { | ||
this.log(_this.config.name + " was identified."); | ||
debug(_this.config.name + " was identified."); | ||
callback(); | ||
}; |
{ | ||
"name": "homebridge-tuya-outlet", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Homebridge plugin for devices utilizing Tuya's API: https://github.com/codetheweb/homebridge-tuya-outlet", | ||
@@ -23,4 +23,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"tuyapi": "^1.1.0" | ||
"debug": "^3.1.0", | ||
"tuyapi": "^2.0.0" | ||
} | ||
} |
2505
44
2
+ Addeddebug@^3.1.0
+ Addeddebug@3.2.7(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedms@2.1.3(transitive)
+ Addednet-retry-connect@0.1.1(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-timeout@2.0.1(transitive)
+ Addedregex-occurrence@1.0.0(transitive)
+ Addedretry@0.10.10.9.0(transitive)
+ Addedstring-occurrence@1.2.0(transitive)
+ Addedtuyapi@2.0.3(transitive)
- Removed@codetheweb/recon@1.2.0(transitive)
- Removedtuyapi@1.1.2(transitive)
- Removedwait-until@0.0.2(transitive)
Updatedtuyapi@^2.0.0