bt-sensors-plugin-sk 1.2.0-beta.0.1.3 → 1.2.0-beta.0.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/README.md CHANGED
@@ -2,11 +2,15 @@
2
2
 
3
3
  ## What's New
4
4
 
5
+
6
+ ## 1.2.0-beta-0.1.4
7
+
8
+ Added support for paired Shelly devices.
9
+
5
10
  ## 1.2.0-beta-0.1.3
6
11
 
7
12
  Added support for [Shelly Blu Motion sensor ](https://us.shelly.com/products/shelly-blu-motion)
8
13
 
9
-
10
14
  ## 1.2.0-beta-0.1.2.b
11
15
 
12
16
  Module load unfix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-sensors-plugin-sk",
3
- "version": "1.2.0-beta.0.1.3",
3
+ "version": "1.2.0-beta.0.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, Aranet4 environment sensors, SwitchBot temp and humidity sensors, KilovaultHLXPlus smart batteries, and Govee GVH51xx temp sensors",
5
5
  "main": "index.js",
6
6
  "dependencies": {
@@ -49,10 +49,16 @@ class AbstractBTHomeSensor extends BTSensor {
49
49
  static async identify(device) {
50
50
  if (
51
51
  (await this.hasBtHomeServiceData(device)) &&
52
- (await this.hasName(
52
+ ((await this.hasName(
53
53
  device,
54
54
  this.SHORTENED_LOCAL_NAME,
55
- ))
55
+ )) || (await this.hasNameAndAddress(
56
+ device,
57
+ this.SHORTENED_LOCAL_NAME,
58
+ )) || (await this.hasName(
59
+ device,
60
+ this.LOCAL_NAME,
61
+ )))
56
62
  ) {
57
63
  return this;
58
64
  }
@@ -111,6 +117,7 @@ class AbstractBTHomeSensor extends BTSensor {
111
117
  */
112
118
  static async hasName(device, name) {
113
119
  const deviceName = await this.getDeviceProp(device, "Name");
120
+
114
121
  if (deviceName) {
115
122
  if (deviceName === name) {
116
123
  return true;
@@ -118,7 +125,36 @@ class AbstractBTHomeSensor extends BTSensor {
118
125
  }
119
126
  return false;
120
127
  }
121
- /**
128
+
129
+ /**
130
+ * Returns whether the specified device has a given name plus the last two bytes of its address.
131
+ *
132
+ * This method can be included in the {@link BTSensor#identify} method of inheriting sensor classes.
133
+ *
134
+ * @example
135
+ * static async identify(device) {
136
+ * if (await this.hasNameAndAddress(device)) {
137
+ * // Additional checks, if required
138
+ * return YourSensorClass;
139
+ * }
140
+ * return null;
141
+ * }
142
+ * @see BTSensor#identify
143
+ * @param device The Bluetooth device to check the name.
144
+ * @param name {string} The name to be checked for.
145
+ * @returns {Promise<boolean>} Returns `true`, if the device exposes BTHome service data, or `false`,
146
+ * if not.
147
+ */
148
+ static async hasNameAndAddress(device, name) {
149
+ let deviceName = await this.getDeviceProp(device, "Name");
150
+ const address = (await this.getDeviceProp(device, "Address")).split(":")
151
+ if (deviceName) {
152
+ if (`${name}-${address[4]}${address[5]}`.localeCompare(deviceName, undefined, { sensitivity: 'base' } )==0)
153
+ return true;
154
+ }
155
+ return false;
156
+ }
157
+ /**
122
158
  * Returns measurement data for the given object ID from the given BTHomeData.
123
159
  *
124
160
  * @param btHomeData {BTHomeServiceData.BthomeServiceData}
@@ -159,7 +195,7 @@ class AbstractBTHomeSensor extends BTSensor {
159
195
  )?.temperature;
160
196
  if (tempCelsius) {
161
197
  return Number.parseFloat(
162
- (this.KELVIN_OFFSET + tempCelsius).toFixed(2),
198
+ (this.constructor.KELVIN_OFFSET + tempCelsius).toFixed(2),
163
199
  );
164
200
  }
165
201
  return null;
@@ -204,11 +240,23 @@ class AbstractBTHomeSensor extends BTSensor {
204
240
  parseMotion(btHomeData) {
205
241
  const motion = this.getSensorDataByObjectId(
206
242
  btHomeData,
207
- BTHomeServiceData.BthomeObjectId.BINARY_MOTION,
243
+ BTHomeServiceData.BthomeObjectId.BINARY_MOTION
208
244
  )?.motion;
209
245
  return motion.intValue==1
210
246
  }
211
247
 
248
+ /**
249
+ * Extracts packet ID from the given BTHome data.
250
+ *
251
+ * @param btHomeData {BTHomeServiceData.BthomeServiceData} The BTHome data provided by the device.
252
+ * @returns {Number|null} The packet ID.
253
+ */
254
+ parsePacketID(btHomeData) {
255
+ return this.getSensorDataByObjectId(
256
+ btHomeData,
257
+ BTHomeServiceData.BthomeObjectId.MISC_PACKET_ID,
258
+ ).packetId
259
+ }
212
260
 
213
261
  /**
214
262
  * Extracts button press event from the given BTHome data.
@@ -14,7 +14,7 @@ class ShellySBHT003C extends AbstractBTHomeSensor {
14
14
  * @type {string}
15
15
  */
16
16
  static SHORTENED_LOCAL_NAME = "SBHT-003C";
17
-
17
+ static LOCAL_NAME = "TBD"
18
18
 
19
19
  initSchema() {
20
20
  super.initSchema()
@@ -2,7 +2,7 @@ const BTHomeServiceData = require("./BTHome/BTHomeServiceData");
2
2
  const AbstractBTHomeSensor = require("./BTHome/AbstractBTHomeSensor");
3
3
 
4
4
  /**
5
- * Sensor class representing the Shelly BLU H&T.
5
+ * Sensor class representing the Shelly BLU Motion.
6
6
  *
7
7
  * This sensor is publishing data utilising the BTHome format and inherits from {@link AbstractBTHomeSensor}.
8
8
  */
@@ -10,11 +10,16 @@ class ShellySBMO003Z extends AbstractBTHomeSensor {
10
10
  static Domain = this.SensorDomains.environmental
11
11
 
12
12
  /**
13
- * The shortened local name as advertised by the Shelly BLU H&T.
13
+ * The shortened local name as advertised by the Shelly BLU Motion.
14
14
  * @type {string}
15
15
  */
16
16
  static SHORTENED_LOCAL_NAME = "SBMO-003Z";
17
17
 
18
+ /**
19
+ * The local name as advertised by the Shelly BLU Motion after pairing .
20
+ * @type {string}
21
+ */
22
+ static LOCAL_NAME="Shelly BLU Motion";
18
23
 
19
24
  initSchema() {
20
25
  super.initSchema()
@@ -52,6 +57,16 @@ class ShellySBMO003Z extends AbstractBTHomeSensor {
52
57
  )
53
58
  .default="sensors.{macAndName}.button"
54
59
 
60
+ /*
61
+ this.addMetadatum(
62
+ "packetID",
63
+ null,
64
+ "packetID from sensor",
65
+ this.parsePacketID.bind(this)
66
+ )
67
+ .default="sensors.{macAndName}.packetID"
68
+ */
69
+
55
70
  }
56
71
  }
57
72