bt-sensors-plugin-sk 1.2.0-beta.0.0.1.test → 1.2.0-beta.0.0.10

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 (45) hide show
  1. package/.vscode/launch.json +7 -0
  2. package/BTSensor.js +57 -11
  3. package/Queue.js +48 -0
  4. package/README.md +34 -12
  5. package/classLoader.js +38 -0
  6. package/index.js +71 -105
  7. package/package.json +2 -1
  8. package/plugin_defaults.json +99 -10
  9. package/public/893.js +1 -1
  10. package/sensor_classes/ATC.js +5 -3
  11. package/sensor_classes/Aranet/AranetSensor.js +4 -0
  12. package/sensor_classes/Aranet2.js +16 -15
  13. package/sensor_classes/Aranet4.js +23 -17
  14. package/sensor_classes/GoveeH50xx.js +12 -12
  15. package/sensor_classes/GoveeH510x.js +4 -5
  16. package/sensor_classes/IBeacon.js +13 -9
  17. package/sensor_classes/Inkbird.js +4 -2
  18. package/sensor_classes/JBDBMS.js +33 -25
  19. package/sensor_classes/KilovaultHLXPlus.js +33 -16
  20. package/sensor_classes/LancolVoltageMeter.js +4 -3
  21. package/sensor_classes/MopekaTankSensor.js +19 -10
  22. package/sensor_classes/Renogy/RenogySensor.js +1 -1
  23. package/sensor_classes/RenogyBattery.js +15 -13
  24. package/sensor_classes/RenogyRoverClient.js +2 -3
  25. package/sensor_classes/RuuviTag.js +36 -27
  26. package/sensor_classes/ShellySBHT003C.js +19 -22
  27. package/sensor_classes/SwitchBotMeterPlus.js +10 -12
  28. package/sensor_classes/SwitchBotTH.js +13 -16
  29. package/sensor_classes/UltrasonicWindMeter.js +13 -5
  30. package/sensor_classes/VictronACCharger.js +19 -8
  31. package/sensor_classes/VictronBatteryMonitor.js +41 -24
  32. package/sensor_classes/VictronDCDCConverter.js +14 -5
  33. package/sensor_classes/VictronDCEnergyMeter.js +26 -7
  34. package/sensor_classes/VictronGXDevice.js +2 -5
  35. package/sensor_classes/VictronInverter.js +18 -14
  36. package/sensor_classes/VictronInverterRS.js +18 -7
  37. package/sensor_classes/VictronLynxSmartBMS.js +15 -13
  38. package/sensor_classes/VictronOrionXS.js +15 -3
  39. package/sensor_classes/VictronSmartBatteryProtect.js +5 -6
  40. package/sensor_classes/VictronSmartLithium.js +18 -18
  41. package/sensor_classes/VictronSolarCharger.js +31 -18
  42. package/sensor_classes/VictronVEBus.js +2 -5
  43. package/sensor_classes/XiaomiMiBeacon.js +20 -19
  44. package/src/components/PluginConfigurationPanel.js +52 -27
  45. package/testqueue.js +64 -0
@@ -15,27 +15,33 @@ class Aranet4 extends AranetSensor{
15
15
  return null
16
16
  }
17
17
 
18
- async init() {
19
- await super.init()
20
- this.initMetadata()
21
- }
22
18
 
23
- initMetadata(){
24
- this.addMetadatum('co2', 'ppm', 'co2 concentration',
25
- (buff)=>{return ((buff.readUInt16LE(8)))})
26
- this.addMetadatum('temp','K', 'temperature',
27
- (buff)=>{return parseFloat((273.15+(buff.readInt16LE(10))/20).toFixed(2))})
19
+ initSchema(){
28
20
 
29
- this.addMetadatum("pressure","hPa","atmospheric pressure",
30
- (buff)=>{return ((buff.readUInt16LE(12)))/10})
31
21
 
32
- this.addMetadatum('humidity','ratio', 'humidity',
33
- (buff)=>{return ((buff.readUInt8(14))/100)})
34
- this.addMetadatum('batteryStrength', 'ratio', 'sensor battery strength',
35
- (buff)=>{return ((buff.readUInt8(15))/100)})
36
- this.addMetadatum('color', '', 'Warning color (G Y R)',
37
- (buff)=>{return this.COLOR[buff.readUInt8(16)]})
22
+ super.initSchema()
23
+ this.addMetadatum('co2', 'ppm', 'co2 concentration in zone',
24
+ (buff)=>{return ((buff.readUInt16LE(8)))})
25
+ .default="environment.{zone}.co2"
26
+
27
+ this.addDefaultPath('temp','environment.temperature')
28
+ .read=
29
+ (buff)=>{return parseFloat((273.15+(buff.readInt16LE(10))/20).toFixed(2))}
38
30
 
31
+ this.addDefaultPath("pressure","environment.pressure")
32
+ .read=(buff)=>{return ((buff.readUInt16LE(12)))/10}
33
+
34
+ this.addDefaultPath('relativeHumidity','environment.relativeHumidity')
35
+ .read=(buff)=>{return ((buff.readUInt8(14))/100)}
36
+
37
+ this.addMetadatum('color', '', 'Warning color (G Y R)',
38
+ (buff)=>{return this.COLOR[buff.readUInt8(16)]})
39
+ .default="environment.{zone}.warningColor"
40
+
41
+ this.addDefaultPath("battery","sensors.batteryStrength")
42
+ .read=(buff)=>{return ((buff.readUInt8(15))/100)}
43
+
44
+
39
45
  }
40
46
  propertiesChanged(props){
41
47
  super.propertiesChanged(props)
@@ -17,18 +17,18 @@ class GoveeH50xx extends BTSensor {
17
17
  t
18
18
  }
19
19
 
20
- async init(){
21
- await super.init()
22
- this.initMetadata()
23
- }
24
- initMetadata(){
25
- this.addMetadatum('temp','K', 'temperature',
26
- (buffer)=>{return 273.15+(buffer.readUInt16LE(1)/100)
27
- })
28
- this.addMetadatum('humidity','ratio', 'humidity',
29
- (buffer)=>{return buffer.readUInt16LE(3)/10000
30
- })
31
- this.addMetadatum('battery','ratio', 'battery strength', (buffer)=>{return buffer.readUInt8(5)/100})
20
+ initSchema(){
21
+ super.initSchema()
22
+ this.addDefaultParam("zone")
23
+
24
+ this.addDefaultPath("temp","environment.temperature")
25
+ .read= (buffer)=>{return 273.15+(buffer.readUInt16LE(1)/100) }
26
+
27
+ this.addDefaultPath("humidity", "environment.humidity")
28
+ .read = (buffer)=>{return buffer.readUInt16LE(3)/10000}
29
+
30
+ this.addDefaultPath("battery","sensors.batteryStrength")
31
+ .read = (buffer)=>{return buffer.readUInt8(5)/100}
32
32
  }
33
33
 
34
34
  getManufacturer(){
@@ -34,11 +34,10 @@ class GoveeH510x extends BTSensor{
34
34
 
35
35
  }
36
36
 
37
- async init(){
38
- await super.init()
39
- this.initMetadata()
40
- }
41
- initMetadata(){
37
+ initSchema(){
38
+ super.initSchema()
39
+ this.addDefaultParam("zone")
40
+
42
41
  this.addDefaultPath("temp","environment.temperature")
43
42
  this.addDefaultPath("humidity", "environment.humidity")
44
43
  this.addDefaultPath("battery","sensors.batteryStrength")
@@ -4,22 +4,26 @@ class IBeacon extends BTSensor {
4
4
  static isSystem = true;
5
5
 
6
6
  static async identify(device) {
7
- const md = await this.getDeviceProp(device,'ManufacturerData');
7
+ /*const md = await this.getDeviceProp(device,'ManufacturerData');
8
8
  if (md && Object.hasOwn(md, 0x004c)) {
9
9
  if (md[0x004c].value.slice(0,2).join() == [0x02, 0x15].join()) {
10
10
  return this
11
11
  }
12
- }
12
+ }*/
13
+ // IBeacon protocol (see above) is incorporated into multiple BT devices
14
+ // The identify:: method above will misidentify any sensor (Govee for example)
15
+ // that the scanner finds.
16
+ // Sensors can still be classified as IBeacons, they'll appear as Unknown devices in
17
+ // the config. Users can then select IBeacon from the dropdown to
18
+ // instantiate the sensor as an IBeacon object.
19
+
13
20
  return null
14
21
  }
15
22
 
16
- async init() {
17
- await super.init();
18
- this.initMetadata();
19
- }
20
-
21
- initMetadata(){
22
- this.addMetadatum('battery','ratio', 'Battery charge state', (buffer)=>{return buffer[6]})
23
+ initSchema(){
24
+ super.initSchema()
25
+ this.addDefaultPath("battery","sensors.batteryStrength")
26
+ .read=(buffer)=>{return buffer[6]}
23
27
  }
24
28
 
25
29
  propertiesChanged(props){
@@ -13,8 +13,10 @@ class Inkbird extends BTSensor{
13
13
 
14
14
  }
15
15
 
16
- async init(){
17
- await super.init()
16
+ initSchema() {
17
+ super.initSchema()
18
+ this.addDefaultParam("zone")
19
+
18
20
  this.addDefaultPath('temp','environment.temperature')
19
21
  this.addDefaultPath('battery', 'sensors.batteryStrength')
20
22
  if (this.getName() == 'sps'){
@@ -28,28 +28,37 @@ class JBDBMS extends BTSensor {
28
28
  return await this.txChar.writeValueWithResponse(Buffer.from(this.jbdCommand(command)))
29
29
 
30
30
  }
31
- async init(){
32
- await super.init()
33
- this.addMetadatum('voltage', 'V', 'Total battery voltage',
34
- (buffer)=>{return buffer.readUInt16BE(4) / 100})
35
- this.addMetadatum('current', 'A', 'Current flow',
36
- (buffer)=>{return buffer.readInt16BE(6) / 100} )
37
- this.addMetadatum('remainingCapacity', 'Ah', 'Remaining battery capacity',
38
- (buffer)=>{return buffer.readUInt16BE(8) / 100} )
39
- this.addMetadatum('capacity', 'Ah', 'Battery capacity',
40
- (buffer)=>{return buffer.readUInt16BE(10) / 100} )
41
- this.addMetadatum('cycles', '', 'cycles',
42
- (buffer)=>{return buffer.readUInt16BE(12)} )
31
+ async initSchema(){
32
+ super.initSchema()
33
+ this.addDefaultParam("batteryID")
34
+
35
+ this.addDefaultPath('voltage','electrical.batteries.voltage')
36
+ .read=(buffer)=>{return buffer.readUInt16BE(4) / 100}
37
+
38
+ this.addDefaultPath('voltage','electrical.batteries.current')
39
+ .read=(buffer)=>{return buffer.readInt16BE(6) / 100}
40
+
41
+ this.addDefaultPath('remainingCapacity','electrical.batteries.capacity.remaining')
42
+ .read=(buffer)=>{return buffer.readUInt16BE(8) / 100}
43
+
44
+ this.addDefaultPath('capacity','electrical.batteries.capacity.actual')
45
+ .read=(buffer)=>{return buffer.readUInt16BE(10) / 100}
46
+
47
+ this.addDefaultPath('cycles','electrical.batteries.cycles' )
48
+ .read=(buffer)=>{return buffer.readUInt16BE(12)}
49
+
43
50
  this.addMetadatum('protectionStatus', '', 'Protection Status',
44
- (buffer)=>{return buffer.readUInt16BE(20)} )
45
-
46
- this.addMetadatum('SOC', 'ratio', 'State of Charge',
47
- (buffer)=>{return buffer.readUInt8(23)/100} )
51
+ (buffer)=>{return buffer.readUInt16BE(20)} )
52
+ .default="electrical.batteries.{batteryID}.protectionStatus"
53
+
54
+ this.addDefaultPath('SOC','electrical.batteries.capacity.stateOfCharge')
55
+ .read=(buffer)=>{return buffer.readUInt8(23)/100}
48
56
 
49
57
  this.addMetadatum('FET', '', 'FET Control',
50
58
  (buffer)=>{return buffer.readUInt8(24)} )
59
+ .default="electrical.batteries.{batteryID}.FETControl"
51
60
 
52
- await this.device.connect()
61
+ await this.deviceConnect()
53
62
  await this.initCharacteristics()
54
63
  const cellsAndTemps = await this.getNumberOfCellsAndTemps()
55
64
  this.numberOfCells=cellsAndTemps.cells
@@ -65,23 +74,22 @@ class JBDBMS extends BTSensor {
65
74
  for (let i=0; i<this.numberOfCells; i++){
66
75
  this.addMetadatum(`cell${i}Voltage`, 'V', `Cell ${i+1} voltage`,
67
76
  (buffer)=>{return buffer.readUInt16BE((4+(i*2)))/1000} )
77
+ .default=`electrical.batteries.{batteryID}.cell${i}.voltage`
68
78
  this.addMetadatum(`cell${i}Balance`, 'V', `Cell ${i+1} balance` )
79
+ .default=`electrical.batteries.{batteryID}.cell${i}.balance`
80
+
69
81
  }
70
-
71
-
72
- }
82
+ }
73
83
  hasGATT(){
74
84
  return true
75
85
  }
76
- initCharacteristics(){
77
- return new Promise((resolve,reject )=>{ this.device.connect().then(async ()=>{
86
+ async initCharacteristics(){
78
87
  const gattServer = await this.device.gatt()
79
88
  const txRxService= await gattServer.getPrimaryService(this.constructor.TX_RX_SERVICE)
80
89
  this.rxChar = await txRxService.getCharacteristic(this.constructor.NOTIFY_CHAR_UUID)
81
90
  this.txChar = await txRxService.getCharacteristic(this.constructor.WRITE_CHAR_UUID)
82
91
  await this.rxChar.startNotifications()
83
- resolve(this)
84
- }) .catch((e)=>{ reject(e.message) }) })
92
+ return this
85
93
  }
86
94
 
87
95
  async initGATTNotifications(){
@@ -92,7 +100,7 @@ class JBDBMS extends BTSensor {
92
100
 
93
101
  emitGATT(){
94
102
  this.getAndEmitBatteryInfo()
95
- setTimeout(()=>{this.getAndEmitCellVoltages()}, 5000)
103
+ setTimeout(()=>{this.getAndEmitCellVoltages()}, 10000)
96
104
  }
97
105
 
98
106
  async getNumberOfCellsAndTemps(){
@@ -60,35 +60,52 @@ class KilovaultHLXPlus extends BTSensor{
60
60
  // Nothing to do here. HLX+ only reports via BLE notify, not BLE read
61
61
  }
62
62
 
63
- async init(){
64
- await super.init()
65
-
66
- this.addMetadatum("voltage","V","Battery Voltage",
67
- (buffer)=>{return Number(buffer.readInt16LE(0)) / 1000})
68
- this.addMetadatum("current","A","Battery Current",
69
- (buffer)=>{return buffer.readInt32LE(4) / 1000})
70
- this.addMetadatum("energy","AHr","Battery Capacity",
71
- (buffer)=>{return buffer.readInt32LE(8) / 1000})
72
- this.addMetadatum("cycles","","Number of Charge Cycles",
73
- (buffer)=>{return buffer.readInt16LE(12)})
74
- this.addMetadatum("soc","ratio","Battery State of Charge",
75
- (buffer)=>{return buffer.readInt16LE(14)})
76
- this.addMetadatum("temperature","K","Battery Temperature",
77
- (buffer)=>{return buffer.readInt16LE(16)/10 })
63
+ async initSchema(){
64
+ super.initSchema()
65
+ this.addDefaultParam("batteryID")
66
+
67
+ this.addDefaultPath("voltage","electrical.batteries.voltage")
68
+ .read=(buffer)=>{return Number(buffer.readInt16LE(0)) / 1000}
69
+
70
+ this.addDefaultPath("current","electrical.batteries.current")
71
+ .read=(buffer)=>{return buffer.readInt32LE(4) / 1000}
72
+
73
+ this.addDefaultPath("energy", "electrical.batteries.capacity.remaining")
74
+ .read=(buffer)=>{return buffer.readInt32LE(8) / 1000}
75
+
76
+ this.addDefaultPath("cycles",'electrical.batteries.cycles')
77
+ .read=(buffer)=>{return buffer.readInt16LE(12)}
78
+
79
+ this.addDefaultPath("soc",'electrical.batteries.capacity,stateOfCharge')
80
+ .read=(buffer)=>{return buffer.readInt16LE(14)}
81
+
82
+ this.addDefaultPath("temperature",'electrical.batteries.temperature')
83
+ .read=(buffer)=>{return buffer.readInt16LE(16)/10 }
78
84
 
79
85
  this.addMetadatum("status","","Battery Status",
80
86
  (buffer)=>{return buffer.readInt16LE(18) })
87
+ .default="electrical.batteries.{batteryID}.status"
88
+
81
89
  this.addMetadatum("AFEStatus","","Battery AFE Status",
82
90
  (buffer)=>{return buffer.readInt16LE(20) })
91
+ .default="electrical.batteries.{batteryID}.AFEStatus"
83
92
 
84
93
  this.addMetadatum("cell1_voltage","V","Cell 1 Voltage",
85
94
  (buffer)=>{return buffer.readInt16LE(22) / 1000})
95
+ .default="electrical.batteries.{batteryID}.cell1.voltage"
96
+
86
97
  this.addMetadatum("cell2_voltage","V","Cell 2 Voltage",
87
98
  (buffer)=>{return buffer.readInt16LE(24) / 1000})
99
+ .default="electrical.batteries.{batteryID}.cell2.voltage"
100
+
88
101
  this.addMetadatum("cell3_voltage","V","Cell 3 Voltage",
89
102
  (buffer)=>{return buffer.readInt16LE(26) / 1000})
103
+ .default="electrical.batteries.{batteryID}.cell3.voltage"
104
+
90
105
  this.addMetadatum("cell4_voltage","V","Cell 4 Voltage",
91
106
  (buffer)=>{return buffer.readInt16LE(28) / 1000})
107
+ .default="electrical.batteries.{batteryID}.cell4.voltage"
108
+
92
109
  }
93
110
 
94
111
  // Concatentate chunks received by notification into a complete message.
@@ -175,7 +192,7 @@ class KilovaultHLXPlus extends BTSensor{
175
192
  }
176
193
 
177
194
  initGATTConnection(){
178
- return new Promise((resolve,reject )=>{ this.device.connect().then(async ()=>{
195
+ return new Promise((resolve,reject )=>{ this.deviceConnect().then(async ()=>{
179
196
  if (!this.gattServer) {
180
197
  this.gattServer = await this.device.gatt()
181
198
  this.battService = await this.gattServer.getPrimaryService("0000ffe0-0000-1000-8000-00805f9b34fb")
@@ -14,9 +14,10 @@ class LancolVoltageMeter extends BTSensor{
14
14
 
15
15
  }
16
16
 
17
- async init(){
18
- await super.init()
19
- this.addMetadatum('voltage','V', 'battery voltage')
17
+ initSchema(){
18
+ super.initSchema()
19
+ this.addDefaultParam("batteryID")
20
+ this.addDefaultPath('voltage',"electrical.batteries.voltage")
20
21
  }
21
22
 
22
23
  getManufacturer(){
@@ -257,7 +257,6 @@ class MopekaTankSensor extends BTSensor{
257
257
  await super.init()
258
258
  const md = this.valueIfVariant(this.getManufacturerData(this.constructor.manufacturerID))
259
259
  this.modelID = md[0]
260
- this.initMetadata()
261
260
  }
262
261
 
263
262
  getMedium(){
@@ -272,11 +271,12 @@ class MopekaTankSensor extends BTSensor{
272
271
  return rawLevel * (coefs[0] + (coefs[1] * (this.temp-233.15)) + (coefs[2] * ((this.temp-233.15)^2)))
273
272
  }
274
273
 
275
- initMetadata(){
274
+ initSchema(){
275
+ super.initSchema()
276
276
  this.addParameter("medium",
277
277
  {
278
278
  title:"type of liquid in tank",
279
- enum: Object.keys(Media)
279
+ enum: Object.keys(Media)
280
280
  }
281
281
  )
282
282
  this.addParameter("tankHeight",
@@ -286,34 +286,43 @@ class MopekaTankSensor extends BTSensor{
286
286
  unit:"mm"
287
287
  }
288
288
  )
289
+ this.addDefaultParam("id")
289
290
 
290
- this.addMetadatum("battVolt","V","sensor battery in volts",
291
- ((buffer)=>{
291
+ this.addDefaultPath("battVolt","sensors.batteryVoltage")
292
+ .read=((buffer)=>{
292
293
  this.battVolt = (buffer.readUInt8(1)/32)
293
294
  return this.battVolt
294
295
  }).bind(this)
295
- )
296
- this.addMetadatum("battStrength","ratio","sensor battery strength",
297
- (buffer)=>{ return Math.max(0, Math.min(1, (((this.battVolt) - 2.2) / 0.65))) }
298
- )
296
+
297
+ this.addDefaultPath("battStrength", "sensors.batteryStrength")
298
+ .read=(buffer)=>{ return Math.max(0, Math.min(1, (((this.battVolt) - 2.2) / 0.65))) }
299
+
299
300
  this.addMetadatum("temp","K","temperature",
300
301
  ((buffer)=>{
301
302
  this.temp = parseFloat(((buffer.readUInt8(2)&0x7F)+233.15).toFixed(2))
302
303
  return this.temp
303
- }).bind(this)
304
+ })
304
305
  )
306
+ .default="tanks.{id}.temperature"
305
307
  this.addMetadatum("tankLevel","ratio","tank level",
306
308
  (buffer)=>{ return (this._tankLevel(((buffer.readUInt16LE(3))&0x3FFF)))/this.getTankHeight()}
307
309
  )
310
+ .default="tanks.{id}.currentLevel"
311
+
308
312
  this.addMetadatum("readingQuality","","quality of read",
309
313
  (buffer)=>{ return buffer.readUInt8(4)>>6}
310
314
  )
315
+ .default="sensors.{macAndName}.readingQuality"
316
+
311
317
  this.addMetadatum("accX","Mg","acceleration on X-axis",
312
318
  (buffer)=>{ return buffer.readUInt8(8)}
313
319
  )
320
+ .default="sensors.{macAndName}.accelerationXAxis"
321
+
314
322
  this.addMetadatum("accY","Mg","acceleration on Y-axis",
315
323
  (buffer)=>{ return buffer.readUInt8(9)}
316
324
  )
325
+ .default="sensors.{macAndName}.accelerationYAxis"
317
326
  }
318
327
 
319
328
  propertiesChanged(props){
@@ -57,7 +57,7 @@ class RenogySensor extends BTSensor{
57
57
  )
58
58
 
59
59
 
60
- await this.device.connect()
60
+ await this.deviceConnect()
61
61
  const rw = await this.constructor.getReadWriteCharacteristics(this.device)
62
62
 
63
63
  this.readChar = rw.read
@@ -22,25 +22,27 @@ class RenogyBattery extends RenogySensor {
22
22
  initMetadata(){
23
23
 
24
24
  this.addMetadatum('numberOfCells','', 'number of cells')
25
- this.addMetadatum('current','A','current',
26
- (buffer)=>{return buffer.readInt16BE(3)/100})
25
+ this.addDefaultPath('current','electrical.batteries.current')
26
+ .read=(buffer)=>{return buffer.readInt16BE(3)/100}
27
27
 
28
- this.addMetadatum('voltage','V','voltage',
29
- (buffer)=>{return buffer.readUInt16BE(5)/10})
28
+ this.addDefaultPath('voltage','electrical.batteries.voltage')
29
+ .read=(buffer)=>{return buffer.readUInt16BE(5)/10}
30
30
 
31
- this.addMetadatum('remainingCharge', 'Ah', 'remaining charge', //TODO: units
32
- (buffer)=>{return buffer.readUInt32BE(7)/1000})
33
-
34
- this.addMetadatum('capacity','Ah', 'capacity',
35
- (buffer)=>{return buffer.readUInt32BE(11)/1000})
31
+ this.addDefaultPath('remainingCharge', 'electrical.batteries.capacity.remaining')
32
+ .read=(buffer)=>{return buffer.readUInt32BE(7)/1000}
33
+
34
+ this.addDefaultPath('capacity', 'electrical.batteries.capacity.actual')
35
+ .read=(buffer)=>{return buffer.readUInt32BE(11)/1000}
36
36
 
37
37
  for (let i = 0; i++ ; i < this.numberOfCells) {
38
38
  this.addMetadatum(`cellVoltage${i}`, 'V', `cell #${i} voltage`,
39
- (buffer)=>{ return buffer.readUInt16(5+ i*2) }
40
- )
39
+ (buffer)=>{ return buffer.readUInt16(5+ i*2) })
40
+ .default=`electrical.batteries.{batteryID}.cell${i}.voltage`
41
+
41
42
  this.addMetadatum(`cellTemp${i}`, 'K', `cell #${i} temperature`,
42
- (buffer)=>{ return buffer.readUInt16(5+ i*2)+273.15 }
43
- )
43
+ (buffer)=>{ return buffer.readUInt16(5+ i*2)+273.15 })
44
+ .default=`electrical.batteries.{batteryID}.cell${i}.temperature`
45
+
44
46
  }
45
47
  }
46
48
  async initGATTConnection() {
@@ -10,13 +10,12 @@ class RenogyRoverClient extends RenogySensor {
10
10
 
11
11
  async init(){
12
12
  await super.init()
13
- this.initMetadata()
14
13
  this.modelID=await this.retrieveModelID()
15
14
  }
16
15
 
17
- initMetadata(){
16
+ initSchema(){
18
17
  //Buffer(73) [1, 3, 68, 32, 32, 82, 78, 71, 45, 67, 84, 82, 76, 45, 87, 78, 68, 51, 48, 7, 140, 0, 132, 0, 126, 0, 120, 0, 111, 0, 106, 100, 50, 0, 5, 0, 120, 0, 120, 0, 28, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 5, 0, 5, 2, 148, 0, 5, 206, 143, 34, 228, buffer: ArrayBuffer(8192), byteLength: 73, byteOffset: 6144, length: 73, Symbol(Symbol.toStringTag): 'Uint8Array']
19
-
18
+ super.initSchema()
20
19
  this.addMetadatum('batteryType', '', "battery type")
21
20
  this.addMetadatum('batteryPercentage', 'ratio', "battery percentage",
22
21
  (buffer)=>{return buffer.readUInt16BE(3) })
@@ -8,14 +8,17 @@ class RuuviTag extends BTSensor{
8
8
  return null
9
9
  }
10
10
 
11
- async init(){
12
- await super.init()
11
+ initSchema(){
12
+ super.initSchema()
13
+ this.addDefaultParam("zone")
14
+
13
15
  const md = this.valueIfVariant(this.getManufacturerData(this.constructor.manufacturerID))
14
16
  this.mode = md[0]
15
17
  if (this['_initModeV'+this.mode])
16
18
  this['_initModeV'+this.mode]()
17
19
  else
18
20
  throw new Error("Unrecognized Ruuvitag data mode "+md[0])
21
+
19
22
  }
20
23
 
21
24
  /**
@@ -35,33 +38,39 @@ class RuuviTag extends BTSensor{
35
38
  18-23 Any valid mac 48bit MAC address.
36
39
  **/
37
40
  _initModeV5(){
38
- this.addMetadatum("temp","K","temperature in Kelvin",
39
- (buffer)=>{ return parseFloat((273.15+buffer.readInt16BE(1)*.005).toFixed(3))}
40
- )
41
- this.addMetadatum("humidity","ratio","humidity",
42
- (buffer)=>{ return parseFloat(((buffer.readUInt16BE(3)*.0025)/100).toFixed(2))}
43
- )
44
- this.addMetadatum("pressure","Pa","atmospheric pressure",
45
- (buffer)=>{ return buffer.readUInt16BE(5)+50000}
46
- )
41
+ this.addDefaultPath("temp","environment.temperature")
42
+ .read=(buffer)=>{ return parseFloat((273.15+buffer.readInt16BE(1)*.005).toFixed(3))}
43
+
44
+ this.addDefaultPath("humidity","environment.humidity")
45
+ .read=(buffer)=>{ return parseFloat(((buffer.readUInt16BE(3)*.0025)/100).toFixed(2))}
46
+
47
+ this.addDefaultPath("pressure","environment.pressure")
48
+ .read=(buffer)=>{ return buffer.readUInt16BE(5)+50000}
49
+
47
50
  this.addMetadatum("accX","Mg","acceleration on X-axis",
48
51
  (buffer)=>{ return buffer.readInt16BE(7)}
49
- )
52
+ ).default="sensors.{macAndName}.accX"
53
+
50
54
  this.addMetadatum("accY","Mg","acceleration on Y-axis",
51
55
  (buffer)=>{ return buffer.readInt16BE(9)}
52
- )
56
+ ) .default="sensors.{macAndName}.accY"
57
+
53
58
  this.addMetadatum("accZ","Mg","acceleration on Z-axis",
54
59
  (buffer)=>{ return buffer.readInt16BE(11)}
55
- )
56
- this.addMetadatum("battV","V","battery voltage",
57
- (buffer)=>{ return parseFloat((1.6+(buffer.readUInt16BE(13)>>5)/1000).toFixed(2))}
58
- )
60
+ ) .default="sensors.{macAndName}.accZ"
61
+
62
+ this.addDefaultPath("battV","sensors.batteryVoltage")
63
+ .read=(buffer)=>{ return parseFloat((1.6+(buffer.readUInt16BE(13)>>5)/1000).toFixed(2))}
64
+
59
65
  this.addMetadatum("mc","","movement counter",
60
66
  (buffer)=>{ return buffer.readUInt16BE(13) && 0x1F}
61
67
  )
68
+ .default="sensors.{macAndName}.movementCounter"
69
+
62
70
  this.addMetadatum("msc","","measurement sequence counter",
63
71
  (buffer)=>{ return buffer.readUInt16BE(15)}
64
72
  )
73
+ .default="sensors.{macAndName}.measurementSequenceCounter"
65
74
 
66
75
  }
67
76
 
@@ -82,18 +91,18 @@ Offset Allowed values Description
82
91
  **/
83
92
 
84
93
  _initModeV3(){
85
- this.addMetadatum("humidity","ratio","humidity",
86
- (buffer)=>{ return (buffer.readUInt(1)*.5)/100}
87
- )
88
- this.addMetadatum("temp","K","temperature in Kelvin",
89
- (buffer)=>{ return (buffer.readInt(2)+(buffer.readInt(3)/100))+273.15}
90
- )
91
- this.addMetadatum("pressure","Pa","atmospheric pressure",
92
- (buffer)=>{ return buffer.readUInt16BE(4)+50000}
93
- )
94
+ this.addDefaultPath("humidity","environment.humidity")
95
+ .read=(buffer)=>{ return (buffer.readUInt(1)*.5)/100}
96
+
97
+ this.addDefaultPath("temp", "environment.temperature")
98
+ .read=(buffer)=>{ return (buffer.readInt(2)+(buffer.readInt(3)/100))+273.15}
99
+
100
+ this.addDefaultPath("pressure", "environment.pressure")
101
+ .read=(buffer)=>{ return buffer.readUInt16BE(4)+50000}
102
+
94
103
  this.addMetadatum("accX","Mg","acceleration on X-axis",
95
104
  (buffer)=>{ return buffer.readInt16BE(6)}
96
- )
105
+ ).
97
106
  this.addMetadatum("accY","Mg","acceleration on Y-axis",
98
107
  (buffer)=>{ return buffer.readInt16BE(8)}
99
108
  )
@@ -13,11 +13,6 @@ class ShellySBHT003C extends AbstractBTHomeSensor {
13
13
  */
14
14
  static SHORTENED_LOCAL_NAME = "SBHT-003C";
15
15
 
16
- async init() {
17
- await super.init();
18
- this.initMetadata();
19
- }
20
-
21
16
  /**
22
17
  * @typedef ButtonPressEvent {string}
23
18
  */
@@ -78,31 +73,33 @@ class ShellySBHT003C extends AbstractBTHomeSensor {
78
73
  return null;
79
74
  }
80
75
 
81
- initMetadata() {
82
- this.addMetadatum(
76
+ initSchema() {
77
+ super.initSchema()
78
+ this.addDefaultParam("zone")
79
+
80
+ this.addDefaultPath(
83
81
  "battery",
84
- "ratio",
85
- "battery level",
86
- ShellySBHT003C.parseBatteryLevel,
87
- );
88
- this.addMetadatum(
82
+ "sensors.batteryStrength")
83
+ .read=ShellySBHT003C.parseBatteryLevel
84
+
85
+ this.addDefaultPath(
89
86
  "temp",
90
- "K",
91
- "temperature",
92
- ShellySBHT003C.parseTemperature,
93
- );
94
- this.addMetadatum(
95
- "humidity",
96
- "ratio",
87
+ "environment.temperature"
88
+ )
89
+ .read=ShellySBHT003C.parseTemperature
90
+
91
+ this.addDefaultPath(
97
92
  "humidity",
98
- ShellySBHT003C.parseHumidity,
99
- );
93
+ "environment.humidity")
94
+ .read=ShellySBHT003C.parseHumidity,
95
+
100
96
  this.addMetadatum(
101
97
  "button",
102
98
  "enum",
103
99
  "button",
104
100
  ShellySBHT003C.parseShellySBHT003CButton,
105
- );
101
+ )
102
+ .default="sensors.{macAndName}.button"
106
103
  }
107
104
  }
108
105