buttplug 3.0.0-alpha.2 → 3.0.0-alpha.3
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
|
@@ -257,35 +257,49 @@ export class ButtplugClientDevice extends EventEmitter {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
public
|
|
260
|
+
public get hasBattery(): boolean {
|
|
261
261
|
const batteryAttrs = this.messageAttributes.SensorReadCmd?.filter(
|
|
262
262
|
(x) => x.SensorType === Messages.SensorType.Battery
|
|
263
263
|
);
|
|
264
|
-
|
|
264
|
+
return batteryAttrs !== undefined && batteryAttrs.length > 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
public async battery(): Promise<number> {
|
|
268
|
+
if (!this.hasBattery) {
|
|
265
269
|
throw new ButtplugDeviceException(
|
|
266
270
|
`Device ${this.name} has no Battery capabilities`
|
|
267
271
|
);
|
|
268
272
|
}
|
|
273
|
+
const batteryAttrs = this.messageAttributes.SensorReadCmd?.filter(
|
|
274
|
+
(x) => x.SensorType === Messages.SensorType.Battery
|
|
275
|
+
);
|
|
269
276
|
// Find the battery sensor, we'll need its index.
|
|
270
277
|
const result = await this.sensorRead(
|
|
271
|
-
batteryAttrs[0].Index,
|
|
278
|
+
batteryAttrs![0].Index,
|
|
272
279
|
Messages.SensorType.Battery
|
|
273
280
|
);
|
|
274
281
|
return result[0] / 100.0;
|
|
275
282
|
}
|
|
276
283
|
|
|
277
|
-
public
|
|
284
|
+
public get hasRssi(): boolean {
|
|
278
285
|
const rssiAttrs = this.messageAttributes.SensorReadCmd?.filter(
|
|
279
286
|
(x) => x.SensorType === Messages.SensorType.RSSI
|
|
280
287
|
);
|
|
281
|
-
|
|
288
|
+
return rssiAttrs !== undefined && rssiAttrs.length === 0;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
public async rssi(): Promise<number> {
|
|
292
|
+
if (!this.hasRssi) {
|
|
282
293
|
throw new ButtplugDeviceException(
|
|
283
294
|
`Device ${this.name} has no RSSI capabilities`
|
|
284
295
|
);
|
|
285
296
|
}
|
|
297
|
+
const rssiAttrs = this.messageAttributes.SensorReadCmd?.filter(
|
|
298
|
+
(x) => x.SensorType === Messages.SensorType.RSSI
|
|
299
|
+
);
|
|
286
300
|
// Find the battery sensor, we'll need its index.
|
|
287
301
|
const result = await this.sensorRead(
|
|
288
|
-
rssiAttrs[0].Index,
|
|
302
|
+
rssiAttrs![0].Index,
|
|
289
303
|
Messages.SensorType.RSSI
|
|
290
304
|
);
|
|
291
305
|
return result[0];
|