bt-sensors-plugin-sk 1.2.6-beta-5 → 1.2.6-beta-6a

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.
@@ -148,25 +148,19 @@ class ShenzhenLiONBMS extends BTSensor{
148
148
  this.getJSONSchema().properties.params.required=["batteryID", "numberOfCells" ]
149
149
  }
150
150
 
151
- async initGATTConnection(){
152
-
153
- return new Promise((resolve,reject )=>{
154
- this.deviceConnect().then(async ()=>{
155
- if (!this.gattServer) {
156
- this.gattServer = await this.device.gatt()
157
- this.service = await this.gattServer.getPrimaryService("0000ffe0-0000-1000-8000-00805f9b34fb")
158
- this.rxCharacteristic = await this.service.getCharacteristic("0000ffe1-0000-1000-8000-00805f9b34fb")
159
- this.txCharacteristic = await this.service.getCharacteristic("0000ffe2-0000-1000-8000-00805f9b34fb")
160
- }
161
- resolve(this)
162
- })})
151
+ async initGATTConnection(isReconnecting){
152
+
153
+ await super.initGATTConnection(isReconnecting)
154
+ const gattServer = await this.getGATTServer()
155
+ const service = await gattServer.getPrimaryService("0000ffe0-0000-1000-8000-00805f9b34fb")
156
+ this.txCharacteristic = await service.getCharacteristic("0000ffe2-0000-1000-8000-00805f9b34fb")
157
+ this.rxCharacteristic = await service.getCharacteristic("0000ffe1-0000-1000-8000-00805f9b34fb")
163
158
  }
164
159
 
165
160
  async initGATTInterval(){
166
161
  await this.initGATTNotifications()
167
162
  }
168
- emitGATT(){
169
-
163
+ emitGATT(){
170
164
  }
171
165
  async initGATTNotifications() {
172
166
  await this.rxCharacteristic.startNotifications()
@@ -180,15 +174,9 @@ class ShenzhenLiONBMS extends BTSensor{
180
174
  )
181
175
  }
182
176
 
183
- async stopListening(){
184
- super.stopListening() //clears IntervalID as it happens
185
- if (this.rxCharacteristic && await this.rxCharacteristic.isNotifying()) {
186
- await this.rxCharacteristic.stopNotifications()
187
- this.rxCharacteristic=null
188
- }
189
- if (await this.device.isConnected()){
190
- await this.device.disconnect()
191
- }
177
+ async deactivateGATT(){
178
+ await this.stopGATTNotifications(this.rxCharacteristic)
179
+ await super.deactivateGATT()
192
180
  }
193
181
  }
194
182
  module.exports=ShenzhenLiONBMS
@@ -52,53 +52,36 @@ class UltrasonicWindMeter extends BTSensor{
52
52
  .default='environment.wind.speedApparent'
53
53
  }
54
54
 
55
- initGATTConnection(){
56
- return new Promise((resolve,reject )=>{ this.deviceConnect().then(async ()=>{
57
- if (!this.gattServer) {
58
- this.gattServer = await this.device.gatt()
59
- this.battService = await this.gattServer.getPrimaryService("0000180f-0000-1000-8000-00805f9b34fb")
60
- this.battCharacteristic = await this.battService.getCharacteristic("00002a19-0000-1000-8000-00805f9b34fb")
61
- this.envService = await this.gattServer.getPrimaryService("0000181a-0000-1000-8000-00805f9b34fb")
62
- this.awsCharacteristic = await this.envService.getCharacteristic("00002a72-0000-1000-8000-00805f9b34fb")
63
- this.awaCharacteristic = await this.envService.getCharacteristic("00002a73-0000-1000-8000-00805f9b34fb") }
64
- resolve(this)
65
- }) .catch((e)=>{ reject(e.message) }) })
55
+ async initGATTConnection(isReconnecting){
56
+ await super.initGATTConnection(isReconnecting)
57
+ const gattServer = await this.getGATTServer()
58
+ const battService = await gattServer.getPrimaryService("0000180f-0000-1000-8000-00805f9b34fb")
59
+ this.battCharacteristic = await battService.getCharacteristic("00002a19-0000-1000-8000-00805f9b34fb")
60
+ const envService = await gattServer.getPrimaryService("0000181a-0000-1000-8000-00805f9b34fb")
61
+ this.awsCharacteristic = await envService.getCharacteristic("00002a72-0000-1000-8000-00805f9b34fb")
62
+ this.awaCharacteristic = await envService.getCharacteristic("00002a73-0000-1000-8000-00805f9b34fb")
66
63
  }
67
- initGATTNotifications() {
68
- Promise.resolve(this.battCharacteristic.startNotifications().then(()=>{
69
- this.battCharacteristic.on('valuechanged', buffer => {
70
- this.emitData("batt",buffer)
71
- })
72
- }))
73
- Promise.resolve(this.awaCharacteristic.startNotifications().then(()=>{
74
- this.awaCharacteristic.on('valuechanged', buffer => {
64
+ async initGATTNotifications() {
65
+ await this.battCharacteristic.startNotifications()
66
+ this.battCharacteristic.on('valuechanged', buffer => {
67
+ this.emitData("batt",buffer)
68
+ })
69
+
70
+ await this.awaCharacteristic.startNotifications()
71
+ this.awaCharacteristic.on('valuechanged', buffer => {
75
72
  this.emitData("awa", buffer)
76
- })
77
- }))
78
- Promise.resolve(this.awsCharacteristic.startNotifications().then(()=>{
79
- this.awsCharacteristic.on('valuechanged', buffer => {
73
+ })
74
+ await this.awsCharacteristic.startNotifications()
75
+ this.awsCharacteristic.on('valuechanged', buffer => {
80
76
  this.emitData("aws", buffer)
81
- })
82
- }))
83
- }
77
+ })
78
+ }
84
79
 
85
- async stopListening(){
86
- super.stopListening()
87
- if (this.battCharacteristic && await this.battCharacteristic.isNotifying()) {
88
- await this.battCharacteristic.stopNotifications()
89
- this.battCharacteristic=null
90
- }
91
- if (this.awaCharacteristic && await this.awaCharacteristic.isNotifying()) {
92
- await this.awaCharacteristic.stopNotifications()
93
- this.awaCharacteristic=null
94
- }
95
- if (this.awsCharacteristic && await this.awsCharacteristic.isNotifying()) {
96
- await this.awsCharacteristic.stopNotifications()
97
- this.awsCharacteristic=null
98
- }
99
- if (await this.device.isConnected()){
100
- await this.device.disconnect()
101
- }
80
+ async deactivateGATT(){
81
+ await this.stopGATTNotifications(this.battCharacteristic)
82
+ await this.stopGATTNotifications(this.awaCharacteristic)
83
+ await this.stopGATTNotifications(this.awsCharacteristic)
84
+ await super.deactivateGATT()
102
85
  }
103
86
  }
104
87
  module.exports=UltrasonicWindMeter
@@ -110,18 +110,11 @@ class XiaomiMiBeacon extends BTSensor{
110
110
  return ""
111
111
  }
112
112
 
113
- initGATTConnection(){
114
- return new Promise((resolve,reject )=>{
115
- this.deviceConnect().then(async ()=>{
116
- const gatt = await this.getGATTServer()
117
- this.gattService = await gatt.getPrimaryService("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6")
118
- this.gattCharacteristic = await this.gattService.getCharacteristic("ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6")
119
- resolve(this)
120
- })
121
- .catch((e)=>{
122
- reject(e.message)
123
- })
124
- })
113
+ async initGATTConnection(isReconnecting){
114
+ await super.initGATTConnection(isReconnecting)
115
+ const gatt = await this.getGATTServer()
116
+ const gattService = await gatt.getPrimaryService("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6")
117
+ this.gattCharacteristic = await gattService.getCharacteristic("ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6")
125
118
  }
126
119
 
127
120
  emitGATT(){
@@ -132,11 +125,10 @@ class XiaomiMiBeacon extends BTSensor{
132
125
  }
133
126
 
134
127
  async initGATTNotifications() {
135
- Promise.resolve(this.gattCharacteristic.startNotifications().then(()=>{
136
- this.gattCharacteristic.on('valuechanged', buffer => {
137
- this.emitValues(buffer)
138
- })
139
- }))
128
+ await this.gattCharacteristic.startNotifications()
129
+ this.gattCharacteristic.on('valuechanged', buffer => {
130
+ this.emitValues(buffer)
131
+ })
140
132
  }
141
133
 
142
134
  decryptV2and3(data){
@@ -244,20 +236,11 @@ class XiaomiMiBeacon extends BTSensor{
244
236
  return super.getName()
245
237
  else
246
238
  return this?.name??`${dt.name} ${dt.model}`
247
-
248
239
  }
249
240
 
250
241
  async deactivateGATT(){
251
- await this.disconnectGATTCharacteristic()
242
+ await this.stopGATTNotifications(this.gattCharacteristic)
252
243
  await super.deactivateGATT()
253
244
  }
254
-
255
- async disconnectGATTCharacteristic(){
256
- if (this.gattCharacteristic && await this.gattCharacteristic.isNotifying()) {
257
- this.gattCharacteristic.removeAllListeners()
258
- await this.gattCharacteristic.stopNotifications()
259
- this.gattCharacteristic=null
260
- }
261
- }
262
245
  }
263
246
  module.exports=XiaomiMiBeacon
@@ -133,7 +133,6 @@ async function fetchJSONData(path, data = {}) {
133
133
 
134
134
  }
135
135
 
136
-
137
136
  async function getSensorInfo(mac, sensorClass){
138
137
 
139
138
  const response = await fetchJSONData("getSensorInfo",{mac_address: mac, class: sensorClass})
@@ -387,7 +386,7 @@ function createListGroupItem(sensor){
387
386
  {`${sensor._changesMade?"*":""}${sensor.info.name} MAC: ${sensor.info.mac} RSSI: ${ifNullNaN(sensor.info.RSSI)}` }
388
387
  <div class="d-flex justify-content-between ">
389
388
  {
390
- sensor.info.state
389
+ `${sensor.info.state} ${sensor.info.error?" (ERROR)": "" }`
391
390
  }
392
391
  <div class="d-flex justify-content-between ">
393
392
  {