bt-sensors-plugin-sk 1.1.0-beta.2.2.1.3 → 1.1.0-beta.2.2.1.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-sensors-plugin-sk",
3
- "version": "1.1.0-beta.2.2.1.3",
3
+ "version": "1.1.0-beta.2.2.1.4",
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 (new), Aranet4 environment sensors, and Govee GVH51xx temp sensors",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -32,12 +32,13 @@ class Inkbird extends BTSensor{
32
32
  const keys = Object.keys(this.currentProperties.ManufacturerData)
33
33
  const key = keys[keys.length-1]
34
34
  const data = this.getManufacturerData(key)
35
+ const key_i = parseInt(key)
35
36
  if (!data)
36
37
  throw new Error("Unable to get manufacturer data for "+this.getDisplayName())
37
- this.emit("temp", parseFloat((273.15+parseInt(key)/100).toFixed(2))) ;
38
+ this.emit("temp", parseFloat((273.15+(key_i & 0x8000 ? key_i - 0x10000 : key_i)/100).toFixed(2))) ;
38
39
  this.emit('battery', data[5]/100)
39
40
  if (this.getMetadata().has('humidity')){
40
- this.emit("temp", data.readUInt16LE(0)/100);
41
+ this.emit("humidity", data.readUInt16LE(0)/100);
41
42
  }
42
43
  }
43
44
  }
@@ -0,0 +1,71 @@
1
+ const BTSensor = require("../BTSensor");
2
+ class SwitchBotMeterPlus extends BTSensor{
3
+
4
+ constructor(device, config={}){
5
+ super(device,config)
6
+ if (config.parser){
7
+ this.parser=config.parser
8
+ }
9
+ }
10
+
11
+ static ID = 0x0969
12
+ static serviceDataKey = "0000fd3d-0000-1000-8000-00805f9b34fb"
13
+ static modelID = 0x69
14
+
15
+ static async identify(device){
16
+ const md = await this.getDeviceProp(device,'ManufacturerData')
17
+ const sd = await this.getDeviceProp(device,'ServiceData')
18
+
19
+ if (!md) return null
20
+ if (!sd) return null
21
+
22
+ const sdKeys = Object.keys(sd)
23
+ const keys = Object.keys(md)
24
+ if ( (keys && keys.length>0) && (sdKeys && sdKeys.length >0) ){
25
+ const id = keys[keys.length-1]
26
+ if (parseInt(id)==this.ID && md[id][0]==modelID && sdKeys[0] == this.serviceDataKey)
27
+ return this
28
+ }
29
+ return null
30
+
31
+ }
32
+
33
+ async init() {
34
+ await super.init()
35
+ this.initMetadata()
36
+ }
37
+
38
+ initMetadata(){
39
+
40
+ // Apply positive/negative (Byte[4] & 0x80), and convert from deg F if selected (Byte[5] & 0x80) Then convert to deg Kelvin
41
+ // Refer https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#(new)-broadcast-message
42
+
43
+ this.addMetadatum('temp','K', 'temperature',
44
+ (buffer)=>{return (( ( ( (buffer[4] & 0x7f) + ((buffer[3] & 0x0f)/10) ) * ( (buffer[4] & 0x80)>0 ? 1 : -1 ) ) - ( (buffer[5] & 0x80)>0 ? 32 : 0) ) / ( (buffer[5] & 0x80)>0 ? 1.8 : 1) ) + 273.15
45
+ })
46
+ this.addMetadatum('humidity','ratio', 'humidity',
47
+ (buffer)=>{return (buffer[5] & 0x7F)/100
48
+ })
49
+ this.addMetadatum('battery','ratio', 'Battery Strength', (buffer)=>{return buffer[2]/100})
50
+ }
51
+
52
+ propertiesChanged(props){
53
+ super.propertiesChanged(props)
54
+ const buff = this.getServiceData("0000fd3d-0000-1000-8000-00805f9b34fb")
55
+ if (!buff)
56
+ throw new Error("Unable to get service data for "+this.getDisplayName())
57
+ this.emitData("temp", buff)
58
+ this.emitData("humidity", buff)
59
+ this.emitData("battery", buff)
60
+
61
+ }
62
+ getManufacturer(){
63
+ return "Wonder Labs"
64
+ }
65
+
66
+ getName() {
67
+ return "SwitchBotMeterPlus"
68
+ }
69
+
70
+ }
71
+ module.exports=SwitchBotMeterPlus
@@ -22,6 +22,7 @@ class SwitchBotTH extends BTSensor {
22
22
 
23
23
  }
24
24
  static ID = 0x0969
25
+ static modelID = 0x77
25
26
  static batteryService = "0000fd3d-0000-1000-8000-00805f9b34fb"
26
27
  static async identify(device){
27
28
  const md = await this.getDeviceProp(device,'ManufacturerData')
@@ -29,7 +30,7 @@ class SwitchBotTH extends BTSensor {
29
30
  const keys = Object.keys(md)
30
31
  if (keys && keys.length>0){
31
32
  const id = keys[keys.length-1]
32
- if (parseInt(id)==this.ID && md[id].length==12)
33
+ if (parseInt(id)==this.ID && md[id].length==12 && md[id][0]==modelID)
33
34
  return this
34
35
  }
35
36
  return null