node-red-contrib-tplink-smarthome
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "node-red-contrib-tplink-smarthome", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A collection of node-red nodes for tp-link smart home devices", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/Felixls/node-red-contrib-tplink-smarthome", |
@@ -27,27 +27,29 @@ module.exports = function(RED) { | ||
const client = new Client(); | ||
client.getDevice({ | ||
host: deviceIP | ||
}) | ||
.then((device) => { | ||
deviceInstance = device; | ||
device.startPolling(parseInt(node.config.interval)); | ||
node.status({fill: 'green', shape: 'dot', text: 'connected'}); | ||
device.on('lightstate-on', () => { | ||
node.sendPowerUpdateEvent(true); | ||
node.connectClient = function () { | ||
const client = new Client(); | ||
client.getDevice({ | ||
host: deviceIP | ||
}) | ||
.then((device) => { | ||
deviceInstance = device; | ||
device.startPolling(parseInt(node.config.interval)); | ||
node.status({fill: 'green', shape: 'dot', text: 'connected'}); | ||
device.on('lightstate-on', () => { | ||
node.sendPowerUpdateEvent(true); | ||
}); | ||
device.on('lightstate-off', () => { | ||
node.sendPowerUpdateEvent(false); | ||
}); | ||
device.on('device-online', () => { | ||
node.sendDeviceOnlineEvent(true); | ||
}); | ||
device.on('device-offline', () => { | ||
node.sendDeviceOnlineEvent(false); | ||
}); | ||
}) | ||
.catch(error => { | ||
node.error(error); | ||
node.status({fill: 'red', shape: 'ring', text: 'not reachable'}); | ||
}); | ||
device.on('lightstate-off', () => { | ||
node.sendPowerUpdateEvent(false); | ||
}); | ||
device.on('device-online', () => { | ||
node.sendDeviceOnlineEvent(true); | ||
}); | ||
device.on('device-offline', () => { | ||
node.sendDeviceOnlineEvent(false); | ||
}); | ||
}) | ||
.catch(error => { | ||
node.error(error); | ||
node.status({fill: 'red', shape: 'ring', text: 'not reachable'}); | ||
}); | ||
}; | ||
@@ -68,2 +70,3 @@ node.recheck = setInterval(function() { | ||
node.status({fill: 'red', shape: 'ring', text: 'not reachable'}); | ||
node.connectClient(); | ||
return false; | ||
@@ -148,3 +151,5 @@ } | ||
clearInterval(node.recheck); | ||
}); | ||
}); | ||
node.connectClient(); | ||
} | ||
@@ -151,0 +156,0 @@ RED.nodes.registerType('smart-bulb', SmartBulbNode); |
@@ -28,33 +28,35 @@ module.exports = function(RED) { | ||
const client = new Client(); | ||
client.getDevice({ | ||
host: deviceIP | ||
}) | ||
.then((device) => { | ||
deviceInstance = device; | ||
device.startPolling(parseInt(node.config.interval)); | ||
node.status({fill: 'green', shape: 'dot', text: 'connected'}); | ||
device.on('power-on', () => { | ||
node.sendPowerUpdateEvent(true); | ||
node.connectClient = function () { | ||
const client = new Client(); | ||
client.getDevice({ | ||
host: deviceIP | ||
}) | ||
.then((device) => { | ||
deviceInstance = device; | ||
device.startPolling(parseInt(node.config.interval)); | ||
node.status({fill: 'green', shape: 'dot', text: 'connected'}); | ||
device.on('power-on', () => { | ||
node.sendPowerUpdateEvent(true); | ||
}); | ||
device.on('power-off', () => { | ||
node.sendPowerUpdateEvent(false); | ||
}); | ||
device.on('in-use', () => { | ||
node.sendInUseEvent(true); | ||
}); | ||
device.on('not-in-use', () => { | ||
node.sendInUseEvent(false); | ||
}); | ||
device.on('device-online', () => { | ||
node.sendDeviceOnlineEvent(true); | ||
}); | ||
device.on('device-offline', () => { | ||
node.sendDeviceOnlineEvent(false); | ||
}); | ||
}) | ||
.catch(error => { | ||
node.error(error); | ||
node.status({fill: 'red', shape: 'ring', text: 'not reachable'}); | ||
}); | ||
device.on('power-off', () => { | ||
node.sendPowerUpdateEvent(false); | ||
}); | ||
device.on('in-use', () => { | ||
node.sendInUseEvent(true); | ||
}); | ||
device.on('not-in-use', () => { | ||
node.sendInUseEvent(false); | ||
}); | ||
device.on('device-online', () => { | ||
node.sendDeviceOnlineEvent(true); | ||
}); | ||
device.on('device-offline', () => { | ||
node.sendDeviceOnlineEvent(false); | ||
}); | ||
}) | ||
.catch(error => { | ||
node.error(error); | ||
node.status({fill: 'red', shape: 'ring', text: 'not reachable'}); | ||
}); | ||
}; | ||
@@ -78,2 +80,3 @@ node.recheck = setInterval(function() { | ||
node.status({fill: 'red', shape: 'ring', text: 'not reachable'}); | ||
node.connectClient(); | ||
return false; | ||
@@ -194,3 +197,5 @@ } | ||
clearInterval(node.recheck); | ||
}); | ||
}); | ||
node.connectClient(); | ||
} | ||
@@ -197,0 +202,0 @@ RED.nodes.registerType('smart-plug', SmartPlugNode); |
26552
381