thing-it-device-enocean-ip
Advanced tools
Comparing version
@@ -9,2 +9,12 @@ module.exports = { | ||
services: [], | ||
events: [{ | ||
id: "motionDetected", | ||
label: "Motion detected" | ||
}, { | ||
id: "tic", | ||
label: "Motion Tic" | ||
}, { | ||
id: "noMoreMotion", | ||
label: "No more Motion" | ||
}], | ||
state: [{ | ||
@@ -41,3 +51,11 @@ label: "Occupied", | ||
} | ||
}] | ||
}, { | ||
label: "Release Time", | ||
id: "releaseTime", | ||
type: { | ||
id: "integer" | ||
}, | ||
defaultValue: 240, | ||
unit: "s" | ||
},] | ||
}, | ||
@@ -62,2 +80,4 @@ create: function () { | ||
//this.logLevel = 'debug'; | ||
this.state = {occupied: false, ticksPerMinute: 0}; | ||
@@ -98,57 +118,58 @@ | ||
if (telegram.deviceId === this.configuration.deviceId) { | ||
this.logDebug('Device ' + telegram.friendlyId + ' is processing ', telegram.functions); | ||
//console.log('Device ' + telegram.friendlyId + ' is processing ', telegram.functions); | ||
for (var n in telegram.functions) { | ||
if (telegram.functions[n].key === 'motionDetected') { | ||
for (var n in telegram.functions) { | ||
if (telegram.functions[n].key === 'motionDetected') { | ||
if (telegram.functions[n].value === 'true') { | ||
this.publishEvent('tic', {}); | ||
if (telegram.functions[n].value === 'true') { | ||
this.publishEvent('tic', {}); | ||
this.state.lastMotionTimestamp = moment().toISOString(); | ||
this.state.lastMotionTimestamp = moment().toISOString(); | ||
++tickCount; | ||
++tickCount; | ||
this.publishStateChange(); | ||
this.publishStateChange(); | ||
if (this.occupancyInterval) { | ||
clearInterval(this.occupancyInterval); | ||
} | ||
if (this.occupancyInterval) { | ||
clearInterval(this.occupancyInterval); | ||
} | ||
if (!this.state.occupied) { | ||
this.state.occupied = true; | ||
if (!this.state.occupied) { | ||
this.state.occupied = true; | ||
this.publishStateChange(); | ||
} | ||
this.publishStateChange(); | ||
} | ||
// Simulates repeated ticks | ||
// Simulates repeated ticks | ||
if (this.configuration.ghostTickInterval) { | ||
this.tickRepeatInterval = setInterval(() => { | ||
if (this.configuration.ghostTickInterval) { | ||
this.tickRepeatInterval = setInterval(() => { | ||
this.logDebug('Sending Ghost Tick'); | ||
this.publishEvent('tic', {}); | ||
this.publishEvent('tic', {}); | ||
this.state.lastMotionTimestamp = moment().toISOString(); | ||
this.state.lastMotionTimestamp = moment().toISOString(); | ||
++tickCount; | ||
++tickCount; | ||
this.publishStateChange(); | ||
}, this.configuration.ghostTickInterval * 1000); | ||
} | ||
this.publishStateChange(); | ||
}, this.configuration.ghostTickInterval * 1000); | ||
} | ||
this.occupancyInterval = setInterval(() => { | ||
this.state.occupied = false; | ||
this.occupancyInterval = setInterval(() => { | ||
this.state.occupied = false; | ||
this.publishStateChange(); | ||
}, 30000); | ||
} else { | ||
if (this.tickRepeatInterval) { | ||
clearInterval(this.tickRepeatInterval); | ||
this.publishStateChange(); | ||
}, this.configuration.releaseTime * 1000); | ||
} else { | ||
if (this.tickRepeatInterval) { | ||
clearInterval(this.tickRepeatInterval); | ||
} | ||
} | ||
break; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -155,0 +176,0 @@ deferred.resolve(); |
@@ -52,7 +52,8 @@ module.exports = { | ||
this.state = {light: "off"}; | ||
//TODO GET ACTUAL STATE FROM REAL DEVICE | ||
this.state = {light: false}; | ||
if (this.isSimulated()) { | ||
this.interval = setInterval(function () { | ||
this.state.light = !this.state.light; | ||
}.bind(this), 10000); | ||
@@ -72,6 +73,5 @@ | ||
// this.interval = setInterval(function () { | ||
// | ||
// | ||
// this.toggle(); | ||
// }.bind(this), 3000); | ||
// console.log("TestInterval"); | ||
// }.bind(this), Math.floor(Math.random() * 5000) + 500); | ||
@@ -104,3 +104,15 @@ | ||
} else { | ||
this.state = state; | ||
this.device.adapter.setDeviceState(this.configuration.deviceId, [{ | ||
key: "switch", | ||
value: this.state.light, | ||
}, { | ||
key: "channel", | ||
value: this.configuration.channel, | ||
},]).then(function () { | ||
this.publishStateChange(); | ||
}.bind(this)).fail(function (error) { | ||
this.logError(error); | ||
}.bind(this)); | ||
} | ||
@@ -123,3 +135,3 @@ }; | ||
if (this.state.light === "off") { | ||
this.state.light = "on"; | ||
var output = "on"; | ||
} else { | ||
@@ -131,6 +143,6 @@ this.state.light = "off"; | ||
key: "switch", | ||
value: this.state.light, | ||
value: output, | ||
}, { | ||
key: "channel", | ||
value: "1", | ||
value: this.configuration.channel, | ||
},]).then(function () { | ||
@@ -137,0 +149,0 @@ |
@@ -20,3 +20,3 @@ module.exports = { | ||
}, | ||
defaultValue: "192.168.192.1" | ||
defaultValue: "0.0.0.0" | ||
}, { | ||
@@ -28,3 +28,3 @@ label: "Port", | ||
}, | ||
defaultValue: 55555 | ||
defaultValue: 8080 | ||
}, { | ||
@@ -107,3 +107,3 @@ label: "Gateway ID", | ||
} else { | ||
this.adapter = new Adapter().initialize(this.configuration.host, this.configuration.port, this); | ||
this.adapter = new Adapter().initialize(this.configuration.host, this.configuration.port, this, this.configuration.adminAccount, this.configuration.adminPassword); | ||
@@ -153,3 +153,3 @@ this.logDebug('Adapter initialized.'); | ||
function Adapter() { | ||
Adapter.prototype.initialize = function (host, port, logger) { | ||
Adapter.prototype.initialize = function (host, port, logger, account, password) { | ||
if (!this.request) { | ||
@@ -163,3 +163,3 @@ this.request = require('request-json'); | ||
// TODO Get from config | ||
this.client.setBasicAuth('admin', 'admin'); | ||
this.client.setBasicAuth(account, password); | ||
// this.client.get('devices', function (err, res) { | ||
@@ -183,7 +183,7 @@ // console.log('Devices retrieved'); | ||
request.get('http://admin:admin@' + host + ':' + port + '/devices/stream', function (error, response, body) { | ||
request.get('http://' + account + ':' + password + '@' + host + ':' + port + '/devices/stream', function (error, response, body) { | ||
if (error) { | ||
this.logger.logDebug('Cannot connect.', error); | ||
this.logger.logDebug('Authorization Error ' + error) | ||
} | ||
}).on('data', function (data) { | ||
}.bind(this)).on('data', function (data) { | ||
message += data.toString('utf8'); | ||
@@ -243,2 +243,3 @@ | ||
} else { | ||
//TODO usefull result debug here | ||
deferred.resolve(body); | ||
@@ -261,5 +262,5 @@ } | ||
} else { | ||
console.log(body); | ||
//TODO usefull result debug here | ||
deferred.resolve(); | ||
deferred.resolve(body); | ||
} | ||
@@ -266,0 +267,0 @@ }); |
{ | ||
"name": "thing-it-device-enocean-ip", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "[thing-it-node] Device Plugin for EnOcean IP products.", | ||
@@ -5,0 +5,0 @@ "authors": "Marc Gille", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
67336
15.19%22
15.79%1350
26.4%1
Infinity%