bt-sensors-plugin-sk 1.2.0-beta.0.0.3 → 1.2.0-beta.0.0.5

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 (37) hide show
  1. package/BTSensor.js +7 -6
  2. package/Queue.js +3 -3
  3. package/index.js +8 -5
  4. package/package.json +1 -1
  5. package/plugin_defaults.json +98 -10
  6. package/sensor_classes/ATC.js +2 -3
  7. package/sensor_classes/Aranet/AranetSensor.js +4 -0
  8. package/sensor_classes/Aranet2.js +16 -15
  9. package/sensor_classes/Aranet4.js +23 -17
  10. package/sensor_classes/GoveeH50xx.js +10 -12
  11. package/sensor_classes/GoveeH510x.js +2 -5
  12. package/sensor_classes/IBeacon.js +4 -7
  13. package/sensor_classes/Inkbird.js +2 -2
  14. package/sensor_classes/JBDBMS.js +31 -23
  15. package/sensor_classes/KilovaultHLXPlus.js +32 -15
  16. package/sensor_classes/LancolVoltageMeter.js +4 -3
  17. package/sensor_classes/RenogyBattery.js +15 -13
  18. package/sensor_classes/RenogyRoverClient.js +2 -3
  19. package/sensor_classes/RuuviTag.js +35 -27
  20. package/sensor_classes/ShellySBHT003C.js +17 -17
  21. package/sensor_classes/SwitchBotMeterPlus.js +8 -12
  22. package/sensor_classes/SwitchBotTH.js +11 -16
  23. package/sensor_classes/VictronACCharger.js +5 -5
  24. package/sensor_classes/VictronBatteryMonitor.js +40 -23
  25. package/sensor_classes/VictronDCDCConverter.js +14 -5
  26. package/sensor_classes/VictronDCEnergyMeter.js +26 -7
  27. package/sensor_classes/VictronGXDevice.js +2 -5
  28. package/sensor_classes/VictronInverter.js +18 -14
  29. package/sensor_classes/VictronInverterRS.js +2 -2
  30. package/sensor_classes/VictronLynxSmartBMS.js +3 -5
  31. package/sensor_classes/VictronOrionXS.js +2 -2
  32. package/sensor_classes/VictronSmartBatteryProtect.js +4 -6
  33. package/sensor_classes/VictronSmartLithium.js +18 -18
  34. package/sensor_classes/VictronSolarCharger.js +31 -18
  35. package/sensor_classes/VictronVEBus.js +2 -5
  36. package/sensor_classes/XiaomiMiBeacon.js +17 -18
  37. package/testqueue.js +64 -0
package/BTSensor.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const { Variant } = require('dbus-next');
2
2
  const { log } = require('node:console');
3
3
  const EventEmitter = require('node:events');
4
- const AutoQueue = require("./Queue")
4
+ const AutoQueue = require("./Queue.js")
5
5
 
6
6
  /**
7
7
  * @author Andrew Gerngross <oh.that.andy@gmail.com>
@@ -314,11 +314,6 @@ class BTSensor extends EventEmitter {
314
314
  }
315
315
  }
316
316
 
317
- }
318
- async init(){
319
- this.currentProperties = await this.constructor.getDeviceProps(this.device)
320
- this.initSchema()
321
-
322
317
 
323
318
  //create the 'name' parameter
324
319
  this.addDefaultParam("name")
@@ -331,6 +326,12 @@ class BTSensor extends EventEmitter {
331
326
  this.addDefaultPath("RSSI","sensors.RSSI")
332
327
  this.getPath("RSSI").read=()=>{return this.getRSSI()}
333
328
  this.getPath("RSSI").read.bind(this)
329
+
330
+ }
331
+ async init(){
332
+ this.currentProperties = await this.constructor.getDeviceProps(this.device)
333
+ this.initSchema()
334
+
334
335
  this.initListen()
335
336
  }
336
337
 
package/Queue.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /*
2
2
  see: https://stackoverflow.com/questions/53540348/js-async-await-tasks-queue
3
3
  */
4
- class Queue {
4
+ class Queue {
5
5
  constructor() { this._items = []; }
6
6
  enqueue(item) { this._items.push(item); }
7
7
  dequeue() { return this._items.shift(); }
8
8
  get size() { return this._items.length; }
9
9
  }
10
10
 
11
- class AutoQueue extends Queue {
11
+ class AutoQueue extends Queue {
12
12
  constructor() {
13
13
  super();
14
14
  this._pendingPromise = false;
@@ -45,4 +45,4 @@ class Queue {
45
45
  return true;
46
46
  }
47
47
  }
48
- module.exports = AutoQueue
48
+ module.exports = AutoQueue
package/index.js CHANGED
@@ -20,6 +20,10 @@ class MissingSensor {
20
20
  this.config=config
21
21
  this.addPath=BTSensor.prototype.addPath.bind(this)
22
22
  this.addParameter=BTSensor.prototype.addParameter.bind(this)
23
+ this.addDefaultPath=BTSensor.prototype.addDefaultPath.bind(this)
24
+ this.addDefaultParam=BTSensor.prototype.addDefaultPath.bind(this)
25
+ this.addDefaultParam=BTSensor.prototype.addDefaultPath.bind(this)
26
+ this.getPath=BTSensor.prototype.getPath.bind(this)
23
27
 
24
28
  this.getJSONSchema = BTSensor.prototype.getJSONSchema.bind(this)
25
29
  this.initSchema = BTSensor.prototype.initSchema.bind(this)
@@ -50,6 +54,7 @@ class MissingSensor {
50
54
  initGATTConnection(){
51
55
 
52
56
  }
57
+
53
58
  getGATTDescription(){
54
59
  return ""
55
60
  }
@@ -342,15 +347,13 @@ module.exports = function (app) {
342
347
  //filter options which can cause issues with Device::Connect()
343
348
  //turning off Discovery
344
349
  //try {await adapter.startDiscovery()}
345
- const _transport = transport?plugin.schema.properties.transport.default:transport
346
350
  try{
347
- if (_transport) {
348
- app.debug(`Setting Bluetooth transport option to ${_transport}`)
351
+ if (transport) {
352
+ app.debug(`Setting Bluetooth transport option to ${transport}`)
349
353
  await adapter.helper.callMethod('SetDiscoveryFilter', {
350
- Transport: new Variant('s', _transport)
354
+ Transport: new Variant('s', transport)
351
355
  })
352
356
  }
353
- adapter._transport=_transport
354
357
  await adapter.helper.callMethod('StartDiscovery')
355
358
  }
356
359
  catch (error){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-sensors-plugin-sk",
3
- "version": "1.2.0-beta.0.0.3",
3
+ "version": "1.2.0-beta.0.0.5",
4
4
  "description": "Bluetooth Sensors for Signalk -- support for Victron devices, RuuviTag, Xiaomi, ATC and Inkbird, Ultrasonic wind meters, Mopeka tank readers, Renogy Battery and Solar Controllers, Aranet4 environment sensors, SwitchBot temp and humidity sensors, KilovaultHLXPlus smart batteries, and Govee GVH51xx temp sensors",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -6,29 +6,117 @@
6
6
  "location":{
7
7
  "description": "Sensor location",
8
8
  "examples": ["inside", "outside", "galley", "freezer", "refrigerator", "head", "cabin", "engine", "deck", "cockpit"]
9
+ },
10
+ "zone":{
11
+ "description": "Zone where sensor operates on boat AKA location ",
12
+ "examples": ["inside", "outside", "galley", "freezer", "refrigerator", "head", "cabin", "engine", "deck", "cockpit"]
13
+ },
14
+ "batteryID":{
15
+ "description": "Battery ID",
16
+ "examples": ["starter", "house"]
17
+ },
18
+ "id":{
19
+ "description": "Sensor ID"
9
20
  }
10
21
  },
11
22
  "environment":{
12
- "temperature":
23
+ "temperature":
13
24
  {
14
25
  "unit":"K",
15
- "default": "environment.{location}.temperature"
26
+ "default": "environment.{zone}.temperature"
16
27
  },
17
28
  "humidity":
18
29
  {
19
30
  "unit":"ratio",
20
- "default":"environment.{location}.humidity"
31
+ "default":"environment.{zone}.humidity"
32
+ },
33
+ "relativeHumidity":
34
+ {
35
+ "title":"Current relative humidity",
36
+ "unit":"ratio",
37
+ "default":"environment.{zone}.humidity"
38
+ },
39
+ "pressure":
40
+ {
41
+ "title": "Current outside air ambient pressure",
42
+ "unit":"Pa",
43
+ "default":"environment.{zone}.humidity"
21
44
  }
22
45
  },
23
46
  "electrical":{
24
- "current":{
25
- "unit": "A",
26
- "default":"electrical.batteries.0.current"
47
+ "inverters":{
48
+ "ac":{
49
+ "current":{
50
+ "unit": "A",
51
+ "default":"electrical.inverters.{id}.ac.current"
52
+ },
53
+ "voltage":
54
+ {
55
+ "unit": "V",
56
+ "default":"electrical.inverters.{id}.ac.voltage"
57
+ },
58
+ "power":
59
+ {
60
+ "unit": "W",
61
+ "default":"electrical.inverters.{id}.ac.power"
62
+ }
63
+
64
+
65
+ },
66
+ "dc":{
67
+ "current":{
68
+ "unit": "A",
69
+ "default":"electrical.inverters.{id}.dc.current"
70
+ },
71
+ "voltage":
72
+ {
73
+ "unit": "V",
74
+ "default":"electrical.inverters.{id}.dc.voltage"
75
+ }
76
+
77
+ }
27
78
  },
28
- "voltage":
29
- {
30
- "unit": "V",
31
- "default": "electrical.batteries.0.voltage"
79
+ "batteries":{
80
+
81
+ "current":{
82
+ "unit": "A",
83
+ "default":"electrical.batteries.{batteryID}.current"
84
+ },
85
+ "voltage":
86
+ {
87
+ "unit": "V",
88
+ "default": "electrical.batteries.{batteryID}.voltage"
89
+ },
90
+
91
+ "temperature":{
92
+ "unit": "K",
93
+ "default": "electrical.batteries.{batteryID}.temperature"
94
+ },
95
+ "cycles":{
96
+ "unit": "",
97
+ "default": "electrical.batteries.{batteryID}.cycles"
98
+ },
99
+
100
+ "capacity":{
101
+ "remaining":{
102
+ "unit":"Ah",
103
+ "default": "electrical.batteries.{batteryID}.capacity.remaining"
104
+ },
105
+ "actual":{
106
+ "unit":"Ah",
107
+ "default": "electrical.batteries.{batteryID}.capacity.actual"
108
+ },
109
+ "stateOfCharge":{
110
+ "unit":"ratio",
111
+ "default": "electrical.batteries.{batteryID}.capacity.stateOfCharge"
112
+ },
113
+ "timeRemaining":{
114
+ "unit":"s",
115
+ "default": "electrical.batteries.{batteryID}.capacity.timeRemaining"
116
+
117
+ }
118
+ }
119
+
32
120
  }
33
121
  },
34
122
  "sensors":{
@@ -30,10 +30,9 @@ class ATC extends BTSensor{
30
30
  if (!this.parser){
31
31
  this.parser="ATC-LE"
32
32
  }
33
- this.initMetadata()
34
33
  }
35
- initMetadata(){
36
-
34
+ initSchema(){
35
+ super.initSchema()
37
36
  this.addDefaultPath('batteryStrength','sensors.batteryStrength')
38
37
  .read=(buff)=>{return ((buff.readUInt8(12))/100)}
39
38
 
@@ -19,6 +19,10 @@ class AranetSensor extends BTSensor{
19
19
 
20
20
  return null
21
21
  }
22
+ initSchema(){
23
+ super.initSchema()
24
+ this.addDefaultParam("zone")
25
+ }
22
26
 
23
27
  }
24
28
  module.exports=AranetSensor
@@ -13,25 +13,26 @@ class Aranet2 extends AranetSensor{
13
13
  return null //not supported for now
14
14
  }
15
15
  }
16
- async init() {
17
- await super.init()
18
- this.initMetadata()
19
- }
20
16
 
21
- initMetadata(){
22
- this.addMetadatum('c02', '', 'c02 concentration',
17
+ initSchema(){
18
+ super.initSchema()
19
+
20
+ this.addMetadatum('co2', 'ppm', 'co2 concentration in zone',
23
21
  (buff)=>{return ((buff.readUInt16LE(8)))})
24
- this.addMetadatum('temp','K', 'temperature',
25
- (buff)=>{return parseFloat((273.15+(buff.readInt16LBE(15))/1000).toFixed(2))})
22
+ .default="environment.{zone}.co2"
23
+
24
+ this.addDefaultPath('temp', 'environment.temperature')
25
+ .read=(buff)=>{return parseFloat((273.15+(buff.readInt16LBE(15))/1000).toFixed(2))}
26
26
 
27
- this.addMetadatum("pressure","","atmospheric pressure",
28
- (buff)=>{return ((buff.readUInt16LE(13)))/10})
29
- this.addMetadatum('batteryStrength', 'ratio', 'sensor battery strength',
30
- (buff)=>{return ((buff.readUInt8(12))/100)})
27
+ this.addDefaultPath('pressure', 'environment.pressure')
28
+ .read= (buff)=>{return ((buff.readUInt16LE(13)))/10}
29
+
30
+ this.addDefaultPath('relativeHumidity','environment.relativeHumidity')
31
+ .read=(buff)=>{return ((buff.readUInt16LE(8))/10000)}
32
+
33
+ this.addDefaultPath("battery","sensors.batteryStrength")
34
+ .read=(buff)=>{return ((buff.readUInt8(12))/100)}
31
35
 
32
- this.addMetadatum('humidity','ratio', 'humidity',
33
- (buff)=>{return ((buff.readUInt16LE(8))/10000)})
34
-
35
36
  }
36
37
  propertiesChanged(props){
37
38
  super.propertiesChanged(props)
@@ -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.relative')
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,16 @@ 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.addDefaultPath("temp","environment.temperature")
23
+ .read= (buffer)=>{return 273.15+(buffer.readUInt16LE(1)/100) }
24
+
25
+ this.addDefaultPath("humidity", "environment.humidity")
26
+ .read = (buffer)=>{return buffer.readUInt16LE(3)/10000}
27
+
28
+ this.addDefaultPath("battery","sensors.batteryStrength")
29
+ .read = (buffer)=>{return buffer.readUInt8(5)/100}
32
30
  }
33
31
 
34
32
  getManufacturer(){
@@ -34,11 +34,8 @@ 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()
42
39
  this.addDefaultPath("temp","environment.temperature")
43
40
  this.addDefaultPath("humidity", "environment.humidity")
44
41
  this.addDefaultPath("battery","sensors.batteryStrength")
@@ -13,13 +13,10 @@ class IBeacon extends BTSensor {
13
13
  return null
14
14
  }
15
15
 
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]})
16
+ initSchema(){
17
+ super.initSchema()
18
+ this.addDefaultPath("battery","sensors.batteryStrength")
19
+ .read=(buffer)=>{return buffer[6]}
23
20
  }
24
21
 
25
22
  propertiesChanged(props){
@@ -13,8 +13,8 @@ class Inkbird extends BTSensor{
13
13
 
14
14
  }
15
15
 
16
- async init(){
17
- await super.init()
16
+ initSchema() {
17
+ super.initSchema()
18
18
  this.addDefaultPath('temp','environment.temperature')
19
19
  this.addDefaultPath('battery', 'sensors.batteryStrength')
20
20
  if (this.getName() == 'sps'){
@@ -28,26 +28,35 @@ 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
61
  await this.deviceConnect()
53
62
  await this.initCharacteristics()
@@ -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( async (resolve,reject )=>{
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(){
@@ -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.
@@ -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(){
@@ -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() {