bt-sensors-plugin-sk 1.3.7 → 1.3.8-beta1

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.
@@ -0,0 +1,2 @@
1
+ {
2
+ }
package/BTSensor.js CHANGED
@@ -105,7 +105,7 @@ class BTSensor extends EventEmitter {
105
105
 
106
106
  Object.assign(this,config)
107
107
  Object.assign(this,gattConfig)
108
-
108
+
109
109
  this._state = "UNKNOWN"
110
110
  }
111
111
  /**
@@ -155,7 +155,7 @@ class BTSensor extends EventEmitter {
155
155
  static _test(data, key, config={}){
156
156
  var b = Buffer.from(data.replaceAll(" ",""),"hex")
157
157
  const d = new this(null,config)
158
- d.initMetadata()
158
+ d.initSchema()
159
159
  Object.keys(d.getPaths()).forEach((tag)=>{
160
160
  d.on(tag,(v)=>console.log(`${tag}=${v}`))
161
161
  })
@@ -328,7 +328,7 @@ class BTSensor extends EventEmitter {
328
328
  type: "integer",
329
329
  minimum: 0,
330
330
  maximum: 600,
331
- default: 2*(this?.discoveryTimeout??30) },
331
+ default: 2*(this?.discoveryTimeout??30) }
332
332
  }
333
333
  },
334
334
  paths:{
@@ -351,7 +351,13 @@ class BTSensor extends EventEmitter {
351
351
  pollFreq: { type: "number", title: "Polling frequency in seconds"}
352
352
  }
353
353
  }
354
- }
354
+ } else{
355
+ this._schema.properties.params.properties.minUpdateInterval=
356
+ {title: "Minimum update interval in milliseconds (0 to disable rate limiting).",
357
+ type: "integer",
358
+ minimum: 0,
359
+ default: 0 }
360
+ }
355
361
 
356
362
 
357
363
  //create the 'name' parameter
@@ -581,7 +587,7 @@ class BTSensor extends EventEmitter {
581
587
  isError(){
582
588
  return this._error
583
589
  }
584
- deviceConnect(isReconnecting=false, autoReconnect=false) {
590
+ deviceConnect(isReconnecting=false, autoReconnect=false, timeout=30000) {
585
591
 
586
592
  return connectQueue.enqueue( async ()=>{
587
593
  this.debug(`Connecting... ${this.getName()}`)
@@ -596,10 +602,27 @@ class BTSensor extends EventEmitter {
596
602
  this.setConnected(true)
597
603
  })
598
604
  }
599
- await this.device.helper.callMethod('Connect')
605
+ const connectTimeoutID = setTimeout(
606
+ ()=>{
607
+ const e = `Connect timed out. Unable to connect after ${timeout}ms.`
608
+ this.setError(e)
609
+ throw new Error(e)
610
+ }
611
+ ,timeout
612
+ )
613
+ try {
614
+ await this.device.helper.callMethod('Connect')
615
+ } catch (e) {
616
+ this.debug(e)
617
+ throw new Error(e.message)
618
+ }
619
+ finally {
620
+ clearTimeout(connectTimeoutID)
621
+ }
600
622
  this.setConnected(true)
601
-
623
+ this._lastContact = Date.now()
602
624
  this.debug(`Connected to ${this.getName()}`)
625
+
603
626
  if (!isReconnecting) {
604
627
  this.device.helper.on(
605
628
  "PropertiesChanged",
@@ -728,13 +751,20 @@ class BTSensor extends EventEmitter {
728
751
  * DBUS connection stays alive, doesn't tax resources and doesn't spit out spurious errors.
729
752
  */
730
753
  initPropertiesChanged(){
731
-
754
+ let lastPropsChanged = -1
732
755
  this._propertiesChanged.bind(this)
733
756
  this.device.helper._prepare()
734
757
  this.device.helper.on("PropertiesChanged",
735
758
  ((props)=> {
759
+ if ( this.minUpdateInterval &&
760
+ lastPropsChanged>0 &&
761
+ (Date.now() - lastPropsChanged) < this.minUpdateInterval) {
762
+ this.debug(`Ignoring properties changed. Last update was ${Date.now() - lastPropsChanged} ms ago.`)
763
+ return
764
+ }
736
765
  try{
737
766
  this._propertiesChanged(props)
767
+ lastPropsChanged = Date.now()
738
768
  }
739
769
  catch(error){
740
770
  this.debug(`Error occured on ${this.getNameAndAddress()}: ${error?.message??error}`)
@@ -851,7 +881,7 @@ class BTSensor extends EventEmitter {
851
881
  }
852
882
 
853
883
  getManufacturerData(key=null){
854
- if (this.currentProperties.ManufacturerData)
884
+ if (this.currentProperties?.ManufacturerData)
855
885
  if (key)
856
886
  return this.valueIfVariant (this.currentProperties.ManufacturerData[key])
857
887
  else
@@ -951,8 +981,8 @@ class BTSensor extends EventEmitter {
951
981
  this.currentProperties.ManufacturerData=this.valueIfVariant(props.ManufacturerData)
952
982
  if (this.isActive())
953
983
  this.propertiesChanged(props)
954
-
955
984
  }
985
+
956
986
  propertiesChanged(props){
957
987
  //implemented by subclass
958
988
  }
@@ -973,7 +1003,7 @@ class BTSensor extends EventEmitter {
973
1003
  this._currentValues[tag]=value
974
1004
  }
975
1005
 
976
- emit(tag, value){
1006
+ _emit(tag, value){
977
1007
  super.emit(tag, value)
978
1008
  if (this.usingGATT()) //update last contact time only for GATT devices
979
1009
  //which do not receive propertyChanged events when connected
package/README.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## WHAT'S NEW
4
4
 
5
+ # Version 1.3.8-beta1
6
+
7
+ ## New sensors
8
+
9
+ - MicrotikTag
10
+ - SensorPush
11
+
12
+ ## New features
13
+
14
+ - Rate limiter
15
+
5
16
  # Version 1.3.7
6
17
 
7
18
  ### Issues Addressed
@@ -0,0 +1,170 @@
1
+ {
2
+ "configuration": {
3
+ "discoveryInterval": 10,
4
+ "peripherals": [
5
+ {
6
+ "active": true,
7
+ "discoveryTimeout": 30,
8
+ "params": {
9
+ "name": "ATC_9FF77E",
10
+ "zone": "inside.cabin",
11
+ "parser": "ATC-LE",
12
+ "sensorClass": "ATC"
13
+ },
14
+ "paths": {
15
+ "RSSI": "sensors.{macAndName}.RSSI",
16
+ "batteryStrength": "sensors.{macAndName}.battery.strength",
17
+ "voltage": "sensors.{macAndName}.battery.voltage",
18
+ "temp": "environment.{zone}.temperature",
19
+ "humidity": "environment.{zone}.humidity"
20
+ },
21
+ "mac_address": "A4:C1:38:9F:F7:7E"
22
+ },
23
+ {
24
+ "active": true,
25
+ "discoveryTimeout": 30,
26
+ "params": {
27
+ "name": "tps",
28
+ "zone": "inside.refrigerator",
29
+ "sensorClass": "Inkbird"
30
+ },
31
+ "paths": {
32
+ "RSSI": "sensors.{macAndName}.RSSI",
33
+ "temp": "environment.{zone}.temperature",
34
+ "battery": "sensors.{macAndName}.battery.strength"
35
+ },
36
+ "mac_address": "49:22:05:17:2B:AE"
37
+ },
38
+ {
39
+ "active": true,
40
+ "discoveryTimeout": 30,
41
+ "params": {
42
+ "name": "Ruuvi BC7E",
43
+ "zone": "inside.navdesk",
44
+ "sensorClass": "RuuviTag"
45
+ },
46
+ "paths": {
47
+ "RSSI": "sensors.{macAndName}.RSSI",
48
+ "temp": "environment.{zone}.temperature",
49
+ "humidity": "environment.{zone}.humidity",
50
+ "pressure": "environment.{zone}.pressure",
51
+ "accX": "sensors.{macAndName}.accX",
52
+ "accY": "sensors.{macAndName}.accY",
53
+ "accZ": "sensors.{macAndName}.accZ",
54
+ "battV": "sensors.{macAndName}.battery.voltage",
55
+ "mc": "sensors.{macAndName}.movementCounter",
56
+ "msc": "sensors.{macAndName}.measurementSequenceCounter"
57
+ },
58
+ "mac_address": "F9:B0:6E:63:BC:7E"
59
+ },
60
+ {
61
+ "active": true,
62
+ "discoveryTimeout": 30,
63
+ "params": {
64
+ "name": "SBMO-003Z-db1b",
65
+ "zone": "inside",
66
+ "sensorClass": "ShellySBMO003Z"
67
+ },
68
+ "paths": {
69
+ "RSSI": "sensors.{macAndName}.RSSI",
70
+ "motion": "environment.{zone}.motion",
71
+ "illuminance": "environment.{zone}.illuminance",
72
+ "battery": "sensors.{macAndName}.battery.strength",
73
+ "button": "sensors.{macAndName}.button"
74
+ },
75
+ "mac_address": "E8:E0:7E:97:DB:1B"
76
+ },
77
+ {
78
+ "active": true,
79
+ "discoveryTimeout": 30,
80
+ "params": {
81
+ "name": "LYWSD03MMC",
82
+ "zone": "inside.vberth",
83
+ "encryptionKey": "3985f4ebc032f276cc316f1f6ecea085",
84
+ "sensorClass": "XiaomiMiBeacon"
85
+ },
86
+ "paths": {
87
+ "RSSI": "sensors.{macAndName}.RSSI",
88
+ "temp": "environment.{zone}.temperature",
89
+ "humidity": "environment.{zone}.humidity",
90
+ "batteryStrength": "sensors.{macAndName}.battery.strength",
91
+ "voltage": "sensors.{macAndName}.battery.voltage"
92
+ },
93
+ "gattParams": {
94
+ "useGATT": false
95
+ },
96
+ "mac_address": "A4:C1:38:3E:7E:94"
97
+ },
98
+ {
99
+ "active": true,
100
+ "discoveryTimeout": 30,
101
+ "params": {
102
+ "name": "SmartShunt HQ2204C2GHD",
103
+ "batteryID": "house",
104
+ "encryptionKey": "8cce8529307cf9dd0c85611c4fef42d9",
105
+ "sensorClass": "VictronBatteryMonitor"
106
+ },
107
+ "paths": {
108
+ "RSSI": "sensors.{macAndName}.RSSI",
109
+ "current": "electrical.batteries.{batteryID}.current",
110
+ "power": "electrical.batteries.{batteryID}.power",
111
+ "voltage": "electrical.batteries.{batteryID}.voltage",
112
+ "alarm": "electrical.batteries.{batteryID}.alarm",
113
+ "consumed": "electrical.batteries.{batteryID}.capacity.ampHoursConsumed",
114
+ "soc": "electrical.batteries.{batteryID}.capacity.stateOfCharge",
115
+ "ttg": "electrical.batteries.{batteryID}.capacity.timeRemaining",
116
+ "starterVoltage": "electrical.batteries.secondary.voltage"
117
+ },
118
+ "gattParams": {
119
+ "useGATT": false
120
+ },
121
+ "mac_address": "D4:50:46:39:38:C5"
122
+ },
123
+ {
124
+ "active": true,
125
+ "discoveryTimeout": 90,
126
+ "params": {
127
+ "name": "aft propane tank",
128
+ "medium": "PROPANE",
129
+ "tankHeight": "325",
130
+ "id": "propane",
131
+ "sensorClass": "MopekaTankSensor"
132
+ },
133
+ "paths": {
134
+ "RSSI": "sensors.{macAndName}.RSSI",
135
+ "battVolt": "sensors.{macAndName}.battery.voltage",
136
+ "battStrength": "sensors.{macAndName}.battery.strength",
137
+ "temp": "tanks.{id}.temperature",
138
+ "tankLevel": "tanks.{id}.currentLevel",
139
+ "readingQuality": "sensors.{macAndName}.readingQuality",
140
+ "accX": "sensors.{macAndName}.accelerationXAxis",
141
+ "accY": "sensors.{macAndName}.accelerationYAxis"
142
+ },
143
+ "mac_address": "D4:40:59:BE:2A:8C"
144
+ },
145
+ {
146
+ "active": true,
147
+ "discoveryTimeout": 30,
148
+ "params": {
149
+ "name": "SBHT-003C",
150
+ "zone": "outside.deck",
151
+ "sensorClass": "ShellySBHT003C"
152
+ },
153
+ "paths": {
154
+ "RSSI": "sensors.{macAndName}.RSSI",
155
+ "battery": "sensors.{macAndName}.battery.strength",
156
+ "temp": "environment.{zone}.temperature",
157
+ "humidity": "environment.{zone}.humidity",
158
+ "button": "sensors.{macAndName}.button"
159
+ },
160
+ "mac_address": "7C:C6:B6:AF:49:5F"
161
+ }
162
+ ],
163
+ "adapter": "hci0",
164
+ "transport": "le",
165
+ "duplicateData": false,
166
+ "discoveryTimeout": 30
167
+ },
168
+ "enabled": true,
169
+ "enableDebug": false
170
+ }
@@ -0,0 +1,121 @@
1
+ {
2
+ "configuration": {
3
+ "discoveryTimeout": 30,
4
+ "discoveryInterval": 0,
5
+ "peripherals": [
6
+ {
7
+ "active": true,
8
+ "mac_address": "D4:50:46:39:38:C5",
9
+ "discoveryTimeout": 30,
10
+ "params": {
11
+ "name": "Victron Smart Shunt",
12
+ "encryptionKey": "8cce8529307cf9dd0c85611c4fef42d9"
13
+ },
14
+ "paths": {
15
+ "RSSI": "sensors.smartshunt.rssi",
16
+ "current": "electrical.battery.house.current",
17
+ "power": "electrical.battery.house.power",
18
+ "voltage": "electrical.battery.house.voltage",
19
+ "alarm": "electrical.battery.house.alarm",
20
+ "consumed": "electrical.battery.house.consumedAh",
21
+ "soc": "electrical.battery.house.soc",
22
+ "ttg": "electrical.battery.house.ttg",
23
+ "starterVoltage": "electrical.battery.starter.voltage",
24
+ "__state__": "sensors.smartshunt.state"
25
+ },
26
+ "gattParams": {
27
+ "useGATT": false
28
+ }
29
+ },
30
+ {
31
+ "active": true,
32
+ "mac_address": "F9:B0:6E:63:BC:7E",
33
+ "discoveryTimeout": 30,
34
+ "params": {
35
+ "name": "Ruuvi sensor for cabin"
36
+ },
37
+ "paths": {
38
+ "RSSI": "sensors.ruuviBC7E.rssi",
39
+ "temp": "environment.cabin.temperature",
40
+ "humidity": "environment.cabin.humidity",
41
+ "pressure": "environment.cabin.pressure",
42
+ "battV": "sensors.ruuviBC7E.voltage",
43
+ "mc": "sensors.ruuviBC7E.movementCounter",
44
+ "battery": "sensors.temperature.reefer.batterystrength",
45
+ "__state__": "sensors.ruuviBC7E.state"
46
+ }
47
+ },
48
+ {
49
+ "active": true,
50
+ "mac_address": "49:22:05:17:2B:AE",
51
+ "discoveryTimeout": 120,
52
+ "params": {
53
+ "name": "Inkbird temperature sensor"
54
+ },
55
+ "paths": {
56
+ "RSSI": "sensors.inkbird-th2.rssi",
57
+ "temp": "environment.refrigerator.temperature",
58
+ "battery": "sensors.inkbird-th2.battery",
59
+ "__state__": "sensors.inkbird-th2.state"
60
+ }
61
+ },
62
+ {
63
+ "active": true,
64
+ "mac_address": "A4:C1:38:9F:F7:7E",
65
+ "discoveryTimeout": 300,
66
+ "params": {
67
+ "name": "ATC Temp/Humidity sensor for Deck",
68
+ "parser": "ATC-LE"
69
+ },
70
+ "paths": {
71
+ "RSSI": "sensors.ATC_9FF77E.rssi",
72
+ "temp": "environment.deck.temperature",
73
+ "humidity": "environment.deck.humidity",
74
+ "voltage": "sensors.ATC_9FF77E.voltage",
75
+ "batteryStrength": "sensors.ATC_9FF77E.batteryStrength",
76
+ "__state__": "sensors.ATC_9FF77E.state"
77
+ }
78
+ },
79
+ {
80
+ "active": true,
81
+ "mac_address": "D4:40:59:BE:2A:8C",
82
+ "discoveryTimeout": 30,
83
+ "params": {
84
+ "medium": "PROPANE",
85
+ "tankHeight": "304.8",
86
+ "name": "Galley propane level"
87
+ },
88
+ "paths": {
89
+ "RSSI": "sensors.mopeka-59be8c.rssi",
90
+ "battVolt": "sensors.mopeka-59be8c.battery.voltage",
91
+ "battStrength": "sensors.mopeka-59be8c.battery.strength",
92
+ "temp": "sensors.mopeka-59be8c.temperature",
93
+ "tankLevel": "sensors.mopeka-59be8c.tankLevel",
94
+ "readingQuality": "sensors.mopeka-59be8c.quality",
95
+ "__state__": "sensors.mopeka-59be8c.state"
96
+ }
97
+ },
98
+ {
99
+ "active": true,
100
+ "mac_address": "A4:C1:38:3E:7E:94",
101
+ "discoveryTimeout": 30,
102
+ "params": {
103
+ "encryptionKey": "3985f4ebc032f276cc316f1f6ecea085",
104
+ "__state__": "sensors.xiaomi.state"
105
+ },
106
+ "paths": {
107
+ "RSSI": "sensors.xiaomi.rssi",
108
+ "temp": "sensors.xiaomi.temp",
109
+ "humidity": "sensors.xiaomi.humidity",
110
+ "voltage": "sensors.xiaomi.voltage",
111
+ "__state__": "sensors.xiaomi.state"
112
+ },
113
+ "gattParams": {
114
+ "useGATT": false
115
+ }
116
+ }
117
+ ]
118
+ },
119
+ "enabled": true,
120
+ "enableDebug": true
121
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "delay":100,
3
+ "data":
4
+ {
5
+ "0x96": [
6
+ "55 aa eb 90 10 e0 ac d0 00 00 28 a0 00 00 5a a0 00 00 42 e0 00 00 78 d0 00 00 50 00 00 00 79 d0 00 00 50 a0 00 00 7a d0 00 00 16 d0 00 00 ba 90 00 00 20 bf 20 00 30 00 00 00 3c 00 00 00 20 bf 20 00 2c 10 00 00 3c 00 00 00 1e 00 00 00 d0 70 00 00 bc 20 00 00 58 20 00 00 bc 20 00 00 58 20 00 00 9c ff ff ff 00 00 00 00 20 30 00 00 bc 20 00 00 40 00 00 00 10 00 00 00 10 00 00 00 10 00 00 00 f0 ba 40 00 50 ","00 00 00 5c d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 20 a1 70 00 90 18 f6 00 18 fe ff ff ff 1f a9 6f e0 00 dd e2 00 7b" ],
7
+ "0x97":[
8
+ "55 aa eb 90 00 3 c4 4a 4b 5f 42 32 41 38 53 32 30 50 00 0 00 0 00 00 00 31 31 2e 58 57 00 00 00 31 31 2e 32 36 31 00 00 68 96 c1 03 18 00 00 00 48 42 31 5f 42 34 00 00 00 00 00 00 00 00 00 00 31 32 33 34 00 00 00 00 00 00 00 00 00 00 00 00 32 33 30 38 31 34 00 00 33 30 32 32 38 34 34 32 36 37 00 30 30 30 30 00 49 6e 70 75 74 20 55 73 65 72 64 61 74 61 00 00 31 32 33 33 32 31 00 00 00 00",
9
+ "00 00 00 00 00 00 49 6e 70 75 74 20 55 73 65 72 64 61 74 61 00 00",
10
+ "7c f8 ff ff 1f 0d 00 00 00 00 00 00 90 0f 00 00 00 00 c0 d8 03 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
11
+ "00 00 00 00 00 00 00 00 00 fe 2f 00 00 00 00 00 00 00 00 00 00 bf"
12
+ ]
13
+ }
14
+ }