Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-red-contrib-deconz

Package Overview
Dependencies
Maintainers
1
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-deconz - npm Package Compare versions

Comparing version 0.6.3 to 0.7.0

static/js/node-red-contrib-deconz-battery.js

203

deconz.js

@@ -113,12 +113,12 @@ var request = require('request');

//check if this device exists
node.server.getDeviceMeta(function(deviceMeta){
if (!deviceMeta) {
node.status({
fill: "red",
shape: "dot",
text: 'Device not found'
});
}
}, config.device);
// //check if this device exists
// node.server.getDeviceMeta(function(deviceMeta){
// if (!deviceMeta) {
// node.status({
// fill: "red",
// shape: "dot",
// text: 'Device not found'
// });
// }
// }, config.device);

@@ -131,3 +131,5 @@ if (typeof (config.device) == 'string' && config.device.length) {

if (node.config.outputAtStartup) {
node.sendState(deviceMeta);
setTimeout(function(){
node.sendState(deviceMeta);
}, 1500); //we need this timeout after restart of node-red (homekit delays)
}

@@ -429,2 +431,6 @@ } else {

//*************** Server Node ***************

@@ -436,2 +442,3 @@ function deConzServerNode(n) {

node.items_list = undefined;
node.discoverProcess = false;
node.name = n.name;

@@ -447,2 +454,3 @@ node.ip = n.ip;

if (forceRefresh || node.items === undefined) {
node.discoverProcess = true;
node.log('discoverDevices: Refreshing devices list');

@@ -484,3 +492,6 @@

}
// console.log(node.items);
// console.log('discoverProcess = false');
node.discoverProcess = false;
callback(node.items);

@@ -499,16 +510,42 @@ return node.items;

node.discoverDevices(function(items){
if (items) {
for (var index in items) {
var item = items[index];
if (index === uniqueid) {
result = item;
break;
if (node.items === undefined && !node.discoverProcess) {
node.discoverDevices(function (items) {
if (items) {
for (var index in items) {
var item = items[index];
if (index === uniqueid) {
result = item;
break;
}
}
}
callback(result);
return result;
}, false);
} else {
if (node.getDiscoverProcess()) {
var refreshIntervalId = setInterval(function(){
if (!node.getDiscoverProcess()) {
clearInterval(refreshIntervalId);
result = [];
if ((node.items)) {
for (var index in (node.items)) {
var item = (node.items)[index];
if (index === uniqueid) {
result = item;
break;
}
}
}
callback(result);
return result;
}
}, 100);
} else {
callback(node.items);
return node.items;
}
callback(result);
return result;
}, false);
}
}

@@ -534,2 +571,6 @@

node.getDiscoverProcess = function() {
return node.discoverProcess;
}
// this.heartbeat = function() {

@@ -553,2 +594,82 @@ // clearTimeout(node.pingTimeout);

//*************** Input Node ***************
function deConzItemBattery(config) {
RED.nodes.createNode(this, config);
var node = this;
node.config = config;
node.sendState = function (device) {
if (device.state === undefined) {
// console.log("CODE: #66");
// console.log(device);
} else {
var battery = null;
if ("config" in device && "battery" in device.config && device.config.battery !== undefined && device.config.battery != null) {
battery = device.config.battery;
}
//status
if (battery) {
node.status({
fill: (battery >= 20)?((battery >= 50)?"green":"yellow"):"red",
shape: "dot",
text: battery+'%'
});
//outputs
node.send([
device.config,
format_to_homekit_battery(device)
]);
}
}
};
//get server node
node.server = RED.nodes.getNode(config.server);
if (!node.server) return status_no_server(node);
// //check if this device exists
// node.server.getDeviceMeta(function(deviceMeta){
// if (!deviceMeta) {
// node.status({
// fill: "red",
// shape: "dot",
// text: 'Device not found'
// });
// }
// }, config.device);
if (typeof (config.device) == 'string' && config.device.length) {
node.server.getDeviceMeta(function (deviceMeta) {
if (deviceMeta) {
devices[node.id] = deviceMeta.uniqueid;
node.meta = deviceMeta;
if (node.config.outputAtStartup) {
setTimeout(function(){
node.sendState(deviceMeta);
}, 1500); //we need this timeout after restart of node-red (homekit delays)
}
} else {
node.status({
fill: "red",
shape: "dot",
text: 'Device not found'
});
}
}, config.device);
} else {
node.status({
fill: "red",
shape: "dot",
text: 'Device not set'
});
}
}
RED.nodes.registerType("deconz-battery", deConzItemBattery);
function connect(serverNode, config) {

@@ -560,3 +681,3 @@ const WebSocket = require('ws');

ws.on('open', function open() {
console.log('Connected to WebSocket');
serverNode.log('Connected to WebSocket');

@@ -638,7 +759,2 @@ });

// console.log(device.state);
var characteristic = {};

@@ -731,2 +847,10 @@ if (state !== undefined){

//battery status
if ("config" in device) {
if (device.config['battery'] !== undefined && device.config['battery'] != null){
characteristic.StatusLowBattery = parseInt(device.config['battery'])<=15?1:0;
// characteristic.Battery = parseInt(device.config['battery']);
}
}
msg.payload = characteristic;

@@ -736,2 +860,23 @@ return msg;

function format_to_homekit_battery(device) {
var msg = {};
var characteristic = {};
//battery status
if ("config" in device) {
if (device.config['battery'] !== undefined && device.config['battery'] != null){
characteristic.BatteryLevel = parseInt(device.config['battery']);
characteristic.StatusLowBattery = parseInt(device.config['battery'])<=15?1:0;
msg.payload = characteristic;
// msg.topic = "battery";
return msg;
}
}
return null;
}
function format_from_homekit(message, payload) {

@@ -738,0 +883,0 @@ if (message.hap.context === undefined) {

2

package.json

@@ -34,3 +34,3 @@ {

},
"version": "0.6.3"
"version": "0.7.0"
}

@@ -15,3 +15,4 @@ function deconz_gatewayScanner(nodeItem, selectedItemElementName, options = {}) {

allowEmpty:false,
deviceType:false
deviceType:false,
batteryFilter:false
}, options);

@@ -49,2 +50,11 @@

if (options.batteryFilter &&
(!("meta" in value)
|| !("config" in value.meta)
|| !("battery" in value.meta.config)
)
) {
return true;
}
// selected = typeof(itemName) == 'string' && value.topic == itemName;

@@ -51,0 +61,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc