@mschaeffler/node-red-bthome 1.8.1 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +8 -8
  2. package/bthome.html +81 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -90,7 +90,7 @@ There are two output ports:
90
90
 
91
91
  |config | type | description |
92
92
  |:------------|:-------|:----------------------------------|
93
- |Devices | JSON | configuration of the BT-Home devices |
93
+ |Devices | object | configuration of the BT-Home devices |
94
94
  |counter is time|Boolean| the counter in encrypted messages is checked again the actual time |
95
95
  |Status-Prefix| string | prefix for the topic for state output |
96
96
  |Event-Prefix | string | prefix for the topic for event output |
@@ -99,12 +99,12 @@ There are two output ports:
99
99
 
100
100
  #### Device-Configuration
101
101
 
102
- With this JSON string the installed [BT-Home](https://bthome.io) devices are configured:
103
- ```
104
- {
105
- "<mac address of the device in lower case>": { "topic": "<name of the device>", "key": "<encryption key, if device is encrypted>" }
106
- }
107
- ```
102
+ The installed [BT-Home](https://bthome.io) devices are configured with:
103
+ |config | type | description |
104
+ |:--------|:---------|:----------------------------------|
105
+ |mac |hex string| mac address of the device in lower case.|
106
+ |name |string | name of the device.|
107
+ |key |hex string| encryption key, if device is encrypted.|
108
108
 
109
109
  An example for such a config from the unit tests:
110
110
  ```
@@ -174,7 +174,7 @@ This is an example of such a message payload:
174
174
  "precipitation": 121.5
175
175
  }
176
176
  ```
177
-
177
+
178
178
  ### Outputs
179
179
 
180
180
  There are 12 output ports:
package/bthome.html CHANGED
@@ -26,10 +26,6 @@
26
26
  outputLabels: ['state output','event output'],
27
27
  oneditprepare: function() {
28
28
  const node = this;
29
- $("#node-input-devices").typedInput({
30
- type:"json",
31
- types:["json"]
32
- });
33
29
  // populate store names
34
30
  $("#node-input-contextStore").empty();
35
31
  $("#node-input-contextStore").append(`<option value="none">None</option>`);
@@ -54,6 +50,72 @@
54
50
  });
55
51
  // select the current option
56
52
  $("#node-input-contextStore").val(currentStore);
53
+ // Devices-List
54
+ const devicesList = $("#node-input-devices-container").css('min-height','150px').css('min-width','450px').editableList({
55
+ addItem: function(container,i,device) {
56
+ container.css({
57
+ overflow: 'hidden',
58
+ whiteSpace: 'nowrap'
59
+ });
60
+ const row1 = $('<div/>').appendTo(container);
61
+ const row2 = $('<div/>').appendTo(container);
62
+ $('<div/>',{style: 'display:inline-block; width:8%;'})
63
+ .text('mac')
64
+ .appendTo(row1);
65
+ const propertyMac = $('<input/>',{class:"node-input-device-mac",type:"text"})
66
+ .css("width","40%")
67
+ .appendTo(row1)
68
+ .typedInput({types:['str']});
69
+ $('<div/>',{style: 'display:inline-block; padding:0px 6px;'})
70
+ .text('=')
71
+ .appendTo(row1);
72
+ const propertyTopic = $('<input/>',{class:"node-input-device-topic",type:"text"})
73
+ .css("width","45%")
74
+ .appendTo(row1)
75
+ .typedInput({types:['str']});
76
+ $('<div/>',{style: 'display:inline-block; width: 8%;'})
77
+ .text('key')
78
+ .appendTo(row2);
79
+ const propertyKey = $('<input/>',{class:"node-input-device-key",type:"text"})
80
+ .css("width","89%")
81
+ .appendTo(row2)
82
+ .typedInput({types:['str']});
83
+ propertyMac .typedInput('value',device.mac ?? "");
84
+ propertyTopic.typedInput('value',device.topic ?? "");
85
+ propertyKey .typedInput('value',device.key ?? "");
86
+ },
87
+ //sortable: true,
88
+ removable: true
89
+ });
90
+ console.log(this.devices)
91
+ const help = JSON.parse( this.devices ?? "[]" );
92
+ for( const i in help ) {
93
+ const v = help[i];
94
+ devicesList.editableList('addItem',typeof v == "string" ? {name:v} : {mac:i,topic:v.topic,key:v.key});
95
+ }
96
+ },
97
+ oneditresize: function(size) {
98
+ const rows = $("#dialog-form>div:not(.node-input-devices-container-row)");
99
+ let height = size.height;
100
+ for(let i=0; i<rows.length; i++) {
101
+ height -= $(rows[i]).outerHeight(true);
102
+ }
103
+ const editorRow = $("#dialog-form>div.node-input-devices-container-row");
104
+ height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
105
+ $("#node-input-devices-container").editableList('height',height);
106
+ },
107
+ oneditsave: function() {
108
+ const devices = $("#node-input-devices-container").editableList('items');
109
+ let help = {};
110
+ devices.each(function(i) {
111
+ const device = $(this);
112
+ const mac = device.find(".node-input-device-mac") .typedInput('value');
113
+ const topic = device.find(".node-input-device-topic").typedInput('value');
114
+ const key = device.find(".node-input-device-key") .typedInput('value');
115
+ help[mac] = key==="" ? { topic:topic } : { topic:topic, key:key };
116
+ });
117
+ console.log(JSON.stringify( help ))
118
+ this.devices = JSON.stringify( help );
57
119
  }
58
120
  });
59
121
  </script>
@@ -63,10 +125,6 @@
63
125
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
64
126
  <input type="text" id="node-input-name" placeholder="Name">
65
127
  </div>
66
- <div class="form-row">
67
- <label for="node-input-devices"><i class="fa fa-bluetooth-b"></i> Devices</label>
68
- <input type="text" id="node-input-devices">
69
- </div>
70
128
  <div class="form-row">
71
129
  <label for="node-input-counterMode"><i class="fa fa-clock-o"></i> Countermode</label>
72
130
  <select type="text" id="node-input-counterMode">
@@ -95,6 +153,10 @@
95
153
  <label for="node-input-batteryState"><i class="fa fa-"></i> battery is state</label>
96
154
  <input type="checkbox" id="node-input-batteryState" style="display:inline-block; width:20px; vertical-align:baseline;">
97
155
  </div>
156
+ <div class="form-row node-input-devices-container-row">
157
+ <label for="node-input-devices"><i class="fa fa-bluetooth-b"></i> Devices</label>
158
+ <ol id="node-input-devices-container"></ol>
159
+ </div>
98
160
  </script>
99
161
 
100
162
  <script type="text/x-red" data-help-name="bthome">
@@ -176,7 +238,7 @@
176
238
 
177
239
  <h3>Parameters</h3>
178
240
  <dl class="message-properties">
179
- <dt>Devices <span class="property-type">JSON</span></dt>
241
+ <dt>Devices <span class="property-type">object</span></dt>
180
242
  <dd> configuration of the BT-Home devices.</dd>
181
243
  <dt>counter is times <span class="property-type">Boolean</span></dt>
182
244
  <dd> the counter in encrypted messages is checked again the actual time.</dd>
@@ -189,14 +251,19 @@
189
251
  <dt>Contextstore <span class="property-type">string</span></dt>
190
252
  <dd> context store to be used.</dd>
191
253
  <dt>battery is state <span class="property-type">Boolean</span></dt>
192
- <dd> battery level is included in state mesage.</dt>
254
+ <dd> battery level is included in state mesage.</dd>
193
255
  </dl>
194
256
 
195
257
  <h4>Device-Configuration</h4>
196
- <p>With this JSON string the installed <a href="https://bthome.io">BT-Home</a> devices are configured:</p>
197
- <pre><code>{
198
- "<mac address of the device in lower case>": { "topic": "<name of the device>", "key": "<encryption key, if device is encrypted>" }
199
- }</code></pre>
258
+ <p>The installed <a href="https://bthome.io">BT-Home</a> devices are configured with:</p>
259
+ <dl class="message-properties">
260
+ <dt>mac <span class="property-type">hex string</span></dt>
261
+ <dd> mac address of the device in lower case.</dd>
262
+ <dt>name <span class="property-type">string</span></dt>
263
+ <dd> name of the device.</dd>
264
+ <dt>key <span class="property-type">hex string</span></dt>
265
+ <dd> encryption key, if device is encrypted.</dd>
266
+ </dl>
200
267
 
201
268
  <p>An example for such a config from the unit tests:</p>
202
269
  <pre><code>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mschaeffler/node-red-bthome",
3
- "version": "1.8.1",
3
+ "version": "1.9.1",
4
4
  "description": "A Node Red node to decrypt and decode BT-Home frames",
5
5
  "author": {
6
6
  "name": "Mathias Schäffler",