Skip to content

Commit

Permalink
feat: Save EFQuery from Tasmota to the global context
Browse files Browse the repository at this point in the history
The EFQuery can be saved optionally to the global context.

Resolves: #6
  • Loading branch information
erkenes committed May 8, 2021
1 parent b1853bd commit 216e87b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
8 changes: 8 additions & 0 deletions nodes/efquery-converter-tasmota.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
deviceInputData: {
value: "tasmotaToEfquery",
required: true
},
globalContextName: {
value: "",
required: false
}
},
inputs: 1,
Expand Down Expand Up @@ -64,4 +68,8 @@
<option value="efqueryToTasmota">EFQuery -> Tasmota</option>
</select>
</div>
<div class="form-row">
<label for="node-input-globalContextName"><i class="fa fa-archive"></i> <span data-i18n="label.globalContextName"></span></label>
<input type="text" id="node-input-globalContextName" data-i18n="[placeholder]placeholder.globalContextName">
</div>
</script>
18 changes: 17 additions & 1 deletion nodes/efquery-converter-tasmota.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = function(RED) {
RED.nodes.createNode(this, config);
this.deviceInputData = config.deviceInputData;
this.deviceType = config.deviceType;
this.globalContextName = config.globalContextName;

const node = this;
const devicesBulbs = ['bulb', 'bulb_ww', 'bulb_rgb', 'bulb_rgbw'];

Expand All @@ -14,10 +16,11 @@ module.exports = function(RED) {
outputOfFunction;
const deviceInputData = node.deviceInputData;
const deviceType = node.deviceType;
const globalContextName = node.globalContextName;
const inputMsg = msg;
const inputPayload = inputMsg.payload;


// If input is from tasmota
if (deviceInputData === 'tasmotaToEfquery') {
messageFormat = 'EFQ';

Expand All @@ -33,7 +36,16 @@ module.exports = function(RED) {
msg = outputOfFunction[0];
this.status(outputOfFunction[1]);
}

// Save EFQuery into the global context if a name is set
if (globalContextName) {
const globalContext = this.context().global;

globalContext.set(globalContextName, msg.payload);
}
}

// if input is form EFQuery
else if (deviceInputData === 'efqueryToTasmota') {
messageFormat = 'tasmota';
if (devicesBulbs.indexOf(deviceType) !== -1) {
Expand Down Expand Up @@ -72,6 +84,10 @@ module.exports = function(RED) {
efqueryConvertTasmotaDeviceType: {
value: "plug",
exportable: true
},
efqueryConvertTasmotaGlobalContextName: {
value: "",
exportable: true
}
}
});
Expand Down
11 changes: 11 additions & 0 deletions nodes/locales/de/efquery-converter-tasmota.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<script type="text/x-red" data-help-name="efquery-converter-tasmota">
<p>Konvertiere Daten von Tasmota in EFQuery oder EFQuery in Tasmota</p>

<h3>Tasmota -> EFQuery</h3>
<dl class="message-properties">
<dt>globalContextName
<span class="property-type">string</span>
</dt>
<dd>
der Name, der für den Globalen-Kontext ("global.%NAME%") genutzt werden soll.<br />
Der Wert funktioniert nur bei der Konvertierung "Tasmota -> EFQuery".
</dd>
</dl>
</script>

6 changes: 4 additions & 2 deletions nodes/locales/de/efquery-converter-tasmota.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"label": {
"name": "Name",
"deviceType": "Gerät",
"deviceInputData": "Konvertierung"
"deviceInputData": "Konvertierung",
"globalContextName": "Globaler-Kontext Name"
},
"placeholder": {
"name": "Name"
"name": "Name",
"globalContextName": "Globaler-Kontext Name"
},
"configuration": {
"deviceType": {
Expand Down
11 changes: 11 additions & 0 deletions nodes/locales/en-US/efquery-converter-tasmota.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<script type="text/x-red" data-help-name="efquery-converter-tasmota">
<p>Convert data from Tasmota to EFQuery or EFQuery to Tasmota.</p>

<h3>Tasmota -> EFQuery</h3>
<dl class="message-properties">
<dt>globalContextName
<span class="property-type">string</span>
</dt>
<dd>
the name to be used for the global context ("global.%NAME%").<br />
The value only works with the conversion "Tasmota -> EFQuery".
</dd>
</dl>
</script>

6 changes: 4 additions & 2 deletions nodes/locales/en-US/efquery-converter-tasmota.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"label": {
"name": "Name",
"deviceType": "Device",
"deviceInputData": "Converter"
"deviceInputData": "Converter",
"globalContextName": "Global-Context Name"
},
"placeholder": {
"name": "Name"
"name": "Name",
"globalContextName": "Global-Context Name"
},
"configuration": {
"deviceType": {
Expand Down

0 comments on commit 216e87b

Please sign in to comment.