Socket
Socket
Sign inDemoInstall

node-red-contrib-deconz

Package Overview
Dependencies
Maintainers
2
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 2.0.0-beta.3 to 2.0.0-beta.4

6

deconz.js

@@ -151,5 +151,5 @@ const NODE_PATH = '/node-red-contrib-deconz/';

let config = JSON.parse(data.config);
let configMigration = new ConfigMigration(data.type, config);
let controller = RED.nodes.getNode(config.server);
let result = configMigration.migrate(controller);
let server = RED.nodes.getNode(config.server);
let configMigration = new ConfigMigration(data.type, config, server);
let result = configMigration.migrate(config);
res.json(result);

@@ -156,0 +156,0 @@ });

@@ -13,9 +13,2 @@ const OutputMsgFormatter = require("../src/runtime/OutputMsgFormatter");

// Config migration
let configMigration = new ConfigMigration(NodeType, node.config);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(error => console.error(error));
}
//get server node

@@ -32,10 +25,20 @@ node.server = RED.nodes.getNode(node.config.server);

if (node.config.search_type === "device") {
node.config.device_list.forEach(function (item) {
node.server.registerNodeByDevicePath(node.config.id, item);
});
} else {
node.server.registerNodeWithQuery(node.config.id);
}
node.server.on('onStart', () => {
// Config migration
let configMigration = new ConfigMigration(NodeType, node.config, node.server);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(
error => console.error(`Error with migration of node ${node.type} with id ${node.id}`, error)
);
}
if (node.config.search_type === "device") {
node.config.device_list.forEach(function (item) {
node.server.registerNodeByDevicePath(node.config.id, item);
});
} else {
node.server.registerNodeWithQuery(node.config.id);
}
});
}

@@ -42,0 +45,0 @@

@@ -14,9 +14,2 @@ const ConfigMigration = require("../src/migration/ConfigMigration");

// Config migration
let configMigration = new ConfigMigration(NodeType, node.config);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(error => console.error(error));
}
node.cleanTimer = null;

@@ -35,14 +28,26 @@

if (node.config.search_type === 'device' && node.config.device_list.length === 0) {
node.status({
fill: "red",
shape: "dot",
text: "node-red-contrib-deconz/get:status.device_not_set"
});
return;
}
node.server.on('onStart', () => {
// Config migration
let configMigration = new ConfigMigration(NodeType, node.config, node.server);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(
error => console.error(`Error with migration of node ${node.type} with id ${node.id}`, error)
);
}
// Cleanup old status
node.status({});
if (node.config.search_type === 'device' && node.config.device_list.length === 0) {
node.status({
fill: "red",
shape: "dot",
text: "node-red-contrib-deconz/get:status.device_not_set"
});
return;
}
// Cleanup old status
node.status({});
});
node.on('input', async (message_in) => {

@@ -59,2 +64,3 @@ clearTimeout(node.cleanTimer);

}
//TODO wait for migration ?

@@ -61,0 +67,0 @@ let msgs = new Array(this.config.output_rules.length);

@@ -14,12 +14,2 @@ const dotProp = require('dot-prop');

// Config migration
let configMigration = new ConfigMigration(NodeType, node.config);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(error => console.error(error));
}
// Format : {'state':{__PATH__ : {"buttonevent": 1002}}}
//node.oldValues = {'state': {}, 'config': {} /*, 'name': false*/};
//get server node

@@ -36,10 +26,2 @@ node.server = RED.nodes.getNode(node.config.server);

if (node.config.search_type === "device") {
node.config.device_list.forEach(function (item) {
node.server.registerNodeByDevicePath(node.config.id, item);
});
} else {
node.server.registerNodeWithQuery(node.config.id);
}
node.status({

@@ -52,2 +34,19 @@ fill: "blue",

node.server.on('onStart', () => {
// Config migration
let configMigration = new ConfigMigration(NodeType, node.config, node.server);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(
error => console.error(`Error with migration of node ${node.type} with id ${node.id}`, error)
);
}
if (node.config.search_type === "device") {
node.config.device_list.forEach(function (item) {
node.server.registerNodeByDevicePath(node.config.id, item);
});
} else {
node.server.registerNodeWithQuery(node.config.id);
}
// Display usefull info

@@ -60,3 +59,2 @@ node.status({

console.log('OnStart');
});

@@ -63,0 +61,0 @@

@@ -15,9 +15,2 @@ const CommandParser = require("../src/runtime/CommandParser");

// Config migration
let configMigration = new ConfigMigration(NodeType, node.config);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(error => console.error(error));
}
node.status({}); //clean

@@ -36,5 +29,26 @@

node.server.on('onStart', () => {
// Config migration
let configMigration = new ConfigMigration(NodeType, node.config, node.server);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(
error => console.error(`Error with migration of node ${node.type} with id ${node.id}`, error)
);
}
});
node.cleanTimer = null;
this.on('input', async (message_in, send, done) => {
// Wait until the server is ready
if (node.server.ready === false) {
await node.server.waitForReady();
if (node.server.ready === false) {
//TODO send error, the server is not ready
return;
}
}
//TODO wait for migration ?
let delay = Utils.getNodeProperty(node.config.specific.delay, this, message_in);

@@ -150,3 +164,7 @@ if (typeof delay !== 'number') delay = 50;

await Utils.sleep(delay - error.timings.phases.total);
if (error.timings !== undefined) {
await Utils.sleep(delay - error.timings.phases.total);
} else {
await Utils.sleep(delay);
}
}

@@ -156,2 +174,3 @@ }

node.error(`Error while processing command #${id + 1}, ${error}`, message_in);
console.warn(error);
}

@@ -158,0 +177,0 @@

@@ -21,6 +21,8 @@ const got = require('got');

// Config migration
let configMigration = new ConfigMigration('deconz-server', node.config);
let configMigration = new ConfigMigration('deconz-server', node.config, this);
let migrationResult = configMigration.applyMigration(node.config, node);
if (Array.isArray(migrationResult.errors) && migrationResult.errors.length > 0) {
migrationResult.errors.forEach(error => console.error(error));
migrationResult.errors.forEach(
error => console.error(`Error with migration of node ${node.type} with id ${node.id}`, error)
);
}

@@ -61,2 +63,3 @@

node.ready = true;
node.emit('onStart');

@@ -63,0 +66,0 @@ this.setupDeconzSocket(node);

@@ -51,3 +51,3 @@ {

},
"version": "2.0.0-beta.3",
"version": "2.0.0-beta.4",
"devDependencies": {

@@ -54,0 +54,0 @@ "grunt": "^1.3.0",

@@ -10,19 +10,19 @@ const dotProp = require('dot-prop');

constructor(type, config) {
constructor(type, config, server) {
this.type = type;
switch (this.type) {
case 'deconz-input':
this.handler = new ConfigMigrationHandlerInput(config);
this.handler = new ConfigMigrationHandlerInput(config, server);
break;
case 'deconz-get':
this.handler = new ConfigMigrationHandlerGet(config);
this.handler = new ConfigMigrationHandlerGet(config, server);
break;
case 'deconz-output':
this.handler = new ConfigMigrationHandlerOutput(config);
this.handler = new ConfigMigrationHandlerOutput(config, server);
break;
case 'deconz-battery':
this.handler = new ConfigMigrationHandlerBattery(config);
this.handler = new ConfigMigrationHandlerBattery(config, server);
break;
case 'deconz-server':
this.handler = new ConfigMigrationHandlerServer(config);
this.handler = new ConfigMigrationHandlerServer(config, server);
break;

@@ -32,3 +32,3 @@ }

migrate(controller) {
migrate(config) {
if (!this.handler || !this.handler.migrate) {

@@ -39,3 +39,3 @@ return {error: 'Configuration migration handler not found.'};

if (!this.handler.isLastestVersion) {
this.handler.migrate(controller);
this.handler.migrate(config);
return this.handler.result;

@@ -47,3 +47,3 @@ } else {

applyMigration(config, controller) {
applyMigration(config, node) {
let result = this.migrate(config);

@@ -60,7 +60,6 @@ if (result.notNeeded === true) return result;

for (const [k, v] of Object.entries(result.controller.new)) {
dotProp.set(controller, k, v);
dotProp.set(node, k, v);
}
result.controller.delete.forEach(k => dotProp.delete(controller, k));
result.controller.delete.forEach(k => dotProp.delete(node, k));
return result;

@@ -67,0 +66,0 @@ }

class ConfigMigrationHandler {
constructor(config) {
constructor(config, server) {
this.config = config;
this.server = server;
this.config_version = this.config.config_version;

@@ -30,6 +31,16 @@ this.result = {

this.result.new.device_list = [];
// Todo Handle groups
let device = this.controller.getDevice(this.config.device);
let device;
if (typeof this.config.device === 'string') {
if (this.config.device.substr(0, 6) === 'group_') {
device = this.server.device_list.getDeviceByDomainID(
'groups',
Number(this.config.device.substr(6))
);
} else {
device = this.server.device_list.getDeviceByUniqueID(this.config.device);
}
}
if (device) {
this.result.new.device_list.push(this.controller.getPathByDevice(device));
this.result.new.device_list.push(this.server.device_list.getPathByDevice(device));
} else {

@@ -36,0 +47,0 @@ this.result.errors.push(`Could not find the device '${this.config.device_name}' with uniqueID '${this.config.device}'.`);

@@ -64,3 +64,3 @@ const ConfigMigrationHandler = require('./ConfigMigrationHandler');

} else {
this.errors.push(`Invalid value '${this.config.payload}' for option Switch (true/false)`);
this.result.errors.push(`Invalid value '${this.config.payload}' for option Switch (true/false)`);
}

@@ -80,7 +80,7 @@ break;

} else {
this.errors.push(`Invalid value '${this.config.payload}' for option Switch (true/false)`);
this.result.errors.push(`Invalid value '${this.config.payload}' for option Switch (true/false)`);
}
break;
default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option Switch (true/false)`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option Switch (true/false)`);
break;

@@ -113,3 +113,3 @@ }

if (isNaN(this.config.payload)) {
this.errors.push(`Invalid value '${this.config.payload}' for option '${this.config.command}'`);
this.result.errors.push(`Invalid value '${this.config.payload}' for option '${this.config.command}'`);
} else {

@@ -120,3 +120,3 @@ command.arg[this.config.command].value = parseInt(this.config.payload);

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option '${this.config.command}'`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option '${this.config.command}'`);
break;

@@ -144,3 +144,3 @@ }

if (isNaN(this.config.payload)) {
this.errors.push(`Invalid value '${this.config.payload}' for option 'ct'`);
this.result.errors.push(`Invalid value '${this.config.payload}' for option 'ct'`);
} else {

@@ -163,3 +163,3 @@ command.arg.ct.type = 'num';

if (isNaN(this.config.payload)) {
this.errors.push(`Invalid value '${this.config.payload}' for option 'ct'`);
this.result.errors.push(`Invalid value '${this.config.payload}' for option 'ct'`);
} else {

@@ -170,3 +170,3 @@ command.arg.ct.value = parseInt(this.config.payload);

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option 'ct'`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option 'ct'`);
break;

@@ -184,3 +184,3 @@ }

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option 'xy'`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option 'xy'`);
break;

@@ -191,3 +191,3 @@ }

case 'scene':
command.new.domain = 'scene_call';
command.domain = 'scene_call';

@@ -197,3 +197,3 @@ // Strip 'group_' from device name

if (part.length === 0 || isNaN(part)) {
this.errors.push(`Invalid group ID '${this.config.device}' for calling scene`);
this.result.errors.push(`Invalid group ID '${this.config.device}' for calling scene`);
} else {

@@ -211,3 +211,3 @@ command.arg.group = {

if (isNaN(this.config.payload)) {
this.errors.push(`Invalid scene ID '${this.config.payload}' for calling scene`);
this.result.errors.push(`Invalid scene ID '${this.config.payload}' for calling scene`);
} else {

@@ -229,3 +229,3 @@ command.arg.scene = {

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for calling scene`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for calling scene`);
break;

@@ -236,2 +236,3 @@ }

case 'alert':
command.arg.alert = {};
switch (this.config.payloadType) {

@@ -246,3 +247,3 @@ case 'deconz_payload':

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option 'alert'`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option 'alert'`);
break;

@@ -263,3 +264,3 @@ }

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option 'alert'`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option 'alert'`);
break;

@@ -278,3 +279,3 @@ }

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option 'effect'`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option 'effect'`);
break;

@@ -295,3 +296,3 @@ }

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option 'effect'`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option 'effect'`);
break;

@@ -313,3 +314,3 @@ }

if (isNaN(this.config.payload)) {
this.errors.push(`Invalid value '${this.config.payload}' for option 'ct'`);
this.result.errors.push(`Invalid value '${this.config.payload}' for option 'ct'`);
} else {

@@ -320,3 +321,3 @@ command.arg.ct.value = parseInt(this.config.payload);

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option 'ct'`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option 'ct'`);
break;

@@ -349,3 +350,3 @@ }

default:
this.errors.push(`Invalid value type '${this.config.payloadType}' for option Switch (true/false)`);
this.result.errors.push(`Invalid value type '${this.config.payloadType}' for option Switch (true/false)`);
break;

@@ -406,3 +407,3 @@ }

if (isNaN(this.config.transitionTime)) {
this.errors.push(`Invalid value '${this.config.transitionTime}' for option 'transition'`);
this.result.errors.push(`Invalid value '${this.config.transitionTime}' for option 'transition'`);
} else {

@@ -413,3 +414,7 @@ command.arg.transition.value = parseInt(this.config.transitionTime);

default:
this.errors.push(`Invalid value type '${this.config.transitionTimeType}' for option 'transition'`);
if (typeof this.config.transitionTimeType === 'undefined') {
command.arg.transition = {type: 'num'};
} else {
this.result.errors.push(`Invalid value type '${this.config.transitionTimeType}' for option 'transition'`);
}
break;

@@ -425,3 +430,8 @@ }

command.arg.aftererror = 'continue';
this.result.new.commands = [command];
this.result.new.specific = {
delay: 50,
result: 'never'
};
this.config_version = 1;

@@ -432,2 +442,2 @@ }

module.exports = ConfigMigrationHandlerOutput;
module.exports = ConfigMigrationHandlerOutput;

@@ -65,3 +65,7 @@ const Utils = require("./Utils");

for (const k of ['bri', 'sat', 'hue', 'ct', 'xy']) {
if (this.arg[k].value.length === 0) continue;
if (
this.arg[k] === undefined ||
this.arg[k].value === undefined ||
this.arg[k].value.length === 0
) continue;
switch (this.arg[k].direction) {

@@ -108,5 +112,7 @@ case 'set':

for (const k of ['alert', 'effect', 'colorloopspeed', 'transitiontime'])
for (const k of ['alert', 'effect', 'colorloopspeed', 'transitiontime']) {
if (this.arg[k] === undefined || this.arg[k].value === undefined) continue;
if (this.arg[k].value.length > 0)
this.result.state[k] = this.getNodeProperty(this.arg[k]);
}
}

@@ -290,2 +296,3 @@

getNodeProperty(property, noValueTypes, valueMaps) {
if (typeof property === 'undefined') return undefined;
if (Array.isArray(valueMaps))

@@ -292,0 +299,0 @@ for (const map of valueMaps)

@@ -50,3 +50,3 @@ const dotProp = require('dot-prop');

let generateOne = (device, payloadFormat) => {
if (checkOutputMethod === undefined || checkOutputMethod(device, payloadFormat, options)) {
if (checkOutputMethod === undefined || checkOutputMethod.call(this, device, payloadFormat, options)) {
let msg = this.formatDeviceMsg(device, rawEvent, payloadFormat, options);

@@ -53,0 +53,0 @@ if (msg === null) return;

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