diff --git a/README.md b/README.md
index d4a2bc3..fe82042 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ Lights can be controlled by sending an objet with one or more of the following p
* `saturation` `number` `[0,100]` Sets the saturation of the light. Only for CWS. (UNTESTED)
### Output
-If the node is set to observe and the target light is updated or if triggered manually by sending a `"status"` request as `msg.payload` to the node, the node will send a `msg.payload` for which the `light` property is the current status of the light.
+If the node is set to observe and the target light is updated or if triggered manually by sending a `"status"` request as `msg.payload` to the node, the node will send a `msg.payload` with the current status of the light.
* `id` `number` The id of the light.
* `name` `string` The given name of the light.
* `model` `string` The model of the light.
@@ -40,3 +40,13 @@ If the node is set to observe and the target light is updated or if triggered ma
* `seen` `number` When the light was last interacted with by the gateway (or similar), measured in epoch time.
* `type` `number` The type of device where 2 is light.
* `power` `number` The type of power source powering the light. Will most likely always be 1.
+
+## Changelog
+
+### 0.1.2
+* Moved output status object from `msg.payload.light` to `msg.payload`.
+* Updated security code, identity and PSK to be saved as credentials in config.
+* Updated info panels and tweaked node appearance.
+
+### 0.1.1
+* Published to NPM
diff --git a/dist/node-tradfri.html b/dist/node-tradfri.html
index 86fb560..419beff 100755
--- a/dist/node-tradfri.html
+++ b/dist/node-tradfri.html
@@ -1,13 +1,15 @@
-
+
-
+
+
+
diff --git a/dist/node-tradfri.js b/dist/node-tradfri.js
index e8b13c2..632bce3 100644
--- a/dist/node-tradfri.js
+++ b/dist/node-tradfri.js
@@ -60,9 +60,9 @@ module.exports = function (RED) {
RED.nodes.createNode(node, config);
node.name = config.name;
node.address = config.address;
- node.securityCode = config.securityCode;
- node.identity = config.identity;
- node.psk = config.psk;
+ node.securityCode = node.credentials.securityCode;
+ node.identity = node.credentials.identity;
+ node.psk = node.credentials.psk;
if ((node.identity == null && node.psk != null) || (node.identity != null && node.psk == null)) {
RED.log.error("Must provide both identity and PSK or leave both blank to generate new credentials from security code.");
}
@@ -169,7 +169,7 @@ module.exports = function (RED) {
for (let instanceId in _listeners) {
if (_listeners[instanceId].hasOwnProperty(nodeId)) {
delete _listeners[instanceId][nodeId];
- RED.log.debug(`[Tradfri: ${nodeId}] unregistered event listeners`);
+ RED.log.info(`[Tradfri: ${nodeId}] unregistered event listeners`);
}
}
};
@@ -179,7 +179,13 @@ module.exports = function (RED) {
RED.log.debug(`[Tradfri: ${node.id}] Config was closed`);
});
}
- RED.nodes.registerType("tradfri-connection", TradfriConnectionNode);
+ RED.nodes.registerType("tradfri-connection", TradfriConnectionNode, {
+ credentials: {
+ securityCode: { type: "text" },
+ identity: { type: "text" },
+ psk: { type: "text" }
+ }
+ });
function TradfriNode(config) {
var node = this;
RED.nodes.createNode(node, config);
@@ -189,6 +195,9 @@ module.exports = function (RED) {
node.observe = config.observe;
var _config = RED.nodes.getNode(config.connection);
var _prev = {};
+ var _send = (payload) => {
+ node.send({ topic: "tradfri", payload: payload });
+ };
var _getPayload = (accessory) => {
let light = lightFromAccessory(accessory);
light['prev'] = Object.assign({}, _prev);
@@ -197,7 +206,7 @@ module.exports = function (RED) {
var _deviceUpdated = (accessory) => {
let ret = _getPayload(accessory);
_prev = lightFromAccessory(accessory);
- node.send({ payload: { light: ret } });
+ _send(ret);
RED.log.trace(`[Tradfri: ${node.id}] recieved update for '${accessory.name}' (${accessory.instanceId})`);
};
var _getTargetId = (msg) => {
@@ -215,24 +224,20 @@ module.exports = function (RED) {
throw new Error('No valid target device');
}
};
- var _handleDirectStatus = (msg) => __awaiter(this, void 0, void 0, function* () {
+ var _handleDirectStatus = () => __awaiter(this, void 0, void 0, function* () {
try {
let client = yield _config.getClient();
let res = yield client.request('15001/' + node.deviceId, 'get');
- msg.payload = res;
- node.send(msg);
+ _send(res);
}
catch (e) {
- msg.payload = e;
- node.send(msg);
+ _send(e);
}
});
- var _handleStatus = (msg) => __awaiter(this, void 0, void 0, function* () {
+ var _handleStatus = () => __awaiter(this, void 0, void 0, function* () {
try {
let accessory = yield _config.getLight(node.deviceId);
- msg.payload.light = _getPayload(accessory);
- delete msg.payload.status;
- node.send(msg);
+ _send(_getPayload(accessory));
RED.log.trace(`[Tradfri: ${node.id}] Status request successful`);
}
catch (e) {
@@ -290,10 +295,10 @@ module.exports = function (RED) {
let isDirect = msg.payload.hasOwnProperty('direct');
let isStatus = msg.payload.hasOwnProperty('status');
if (isDirect && isStatus) {
- _handleDirectStatus(msg);
+ _handleDirectStatus();
}
else if (isStatus) {
- _handleStatus(msg);
+ _handleStatus();
}
else if (isDirect) {
_handleDirectLightOp(msg.payload);
diff --git a/package.json b/package.json
index f7f3368..a039fc4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-node-tradfri",
- "version": "0.1.1",
+ "version": "0.1.2",
"description": "Node-RED node to utilize IKEA Trådfri devices. Fully implemented in Node.js.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
diff --git a/src/node-tradfri.html b/src/node-tradfri.html
index 86fb560..419beff 100755
--- a/src/node-tradfri.html
+++ b/src/node-tradfri.html
@@ -1,13 +1,15 @@
-
+
-
+
+
+
diff --git a/src/node-tradfri.ts b/src/node-tradfri.ts
index a2c2254..0cde480 100644
--- a/src/node-tradfri.ts
+++ b/src/node-tradfri.ts
@@ -55,9 +55,9 @@ module.exports = function(RED) {
RED.nodes.createNode(node, config);
node.name = config.name;
node.address = config.address;
- node.securityCode = config.securityCode;
- node.identity = config.identity;
- node.psk = config.psk;
+ node.securityCode = node.credentials.securityCode;
+ node.identity = node.credentials.identity;
+ node.psk = node.credentials.psk;
if ((node.identity == null && node.psk != null) || (node.identity != null && node.psk == null)) {
RED.log.error("Must provide both identity and PSK or leave both blank to generate new credentials from security code.");
@@ -171,7 +171,7 @@ module.exports = function(RED) {
for (let instanceId in _listeners) {
if (_listeners[instanceId].hasOwnProperty(nodeId)) {
delete _listeners[instanceId][nodeId];
- RED.log.debug(`[Tradfri: ${nodeId}] unregistered event listeners`);
+ RED.log.info(`[Tradfri: ${nodeId}] unregistered event listeners`);
}
}
}
@@ -184,7 +184,13 @@ module.exports = function(RED) {
}
- RED.nodes.registerType("tradfri-connection", TradfriConnectionNode);
+ RED.nodes.registerType("tradfri-connection", TradfriConnectionNode, {
+ credentials: {
+ securityCode: {type:"text"},
+ identity: {type:"text"},
+ psk: {type:"text"}
+ }
+ });
function TradfriNode(config) {
var node = this;
@@ -196,6 +202,10 @@ module.exports = function(RED) {
var _config = RED.nodes.getNode(config.connection);
var _prev = {};
+ var _send = (payload: any) => {
+ node.send({topic:"tradfri", payload:payload});
+ }
+
var _getPayload = (accessory: tradfri.Accessory) => {
let light = lightFromAccessory(accessory);
light['prev'] = Object.assign({}, _prev);
@@ -205,7 +215,7 @@ module.exports = function(RED) {
var _deviceUpdated = (accessory: tradfri.Accessory) => {
let ret = _getPayload(accessory);
_prev = lightFromAccessory(accessory);
- node.send({payload: {light: ret}});
+ _send(ret);
RED.log.trace(`[Tradfri: ${node.id}] recieved update for '${accessory.name}' (${accessory.instanceId})`);
}
@@ -222,24 +232,20 @@ module.exports = function(RED) {
}
}
- var _handleDirectStatus = async (msg: any) => {
+ var _handleDirectStatus = async () => {
try {
let client = await _config.getClient();
let res = await client.request('15001/' + node.deviceId, 'get');
- msg.payload = res;
- node.send(msg);
+ _send(res);
} catch (e) {
- msg.payload = e;
- node.send(msg);
+ _send(e);
}
}
- var _handleStatus = async (msg: any) => {
+ var _handleStatus = async () => {
try {
let accessory = await _config.getLight(node.deviceId);
- msg.payload.light = _getPayload(accessory);
- delete msg.payload.status;
- node.send(msg);
+ _send(_getPayload(accessory));
RED.log.trace(`[Tradfri: ${node.id}] Status request successful`);
} catch (e) {
RED.log.info(`[Tradfri: ${node.id}] Status request unsuccessful, '${e.toString()}'`);
@@ -304,9 +310,9 @@ module.exports = function(RED) {
let isStatus = msg.payload.hasOwnProperty('status');
if (isDirect && isStatus) {
- _handleDirectStatus(msg);
+ _handleDirectStatus();
} else if (isStatus) {
- _handleStatus(msg);
+ _handleStatus();
} else if (isDirect) {
_handleDirectLightOp(msg.payload);
} else {