bt-sensors-plugin-sk 1.1.0-beta.2.2.1.5 → 1.1.0-beta.2.2.2

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,39 @@
1
+ const BTSensor = require("../BTSensor");
2
+
3
+ class LancolVoltageMeter extends BTSensor{
4
+
5
+ static async identify(device){
6
+
7
+ const name = await this.getDeviceProp(device,"Name")
8
+ const regex = /^Lancol *[0-9]{1,3}\.[0-9]{1,2}V/
9
+
10
+ if (name && name.match(regex))
11
+ return this
12
+ else
13
+ return null
14
+
15
+ }
16
+
17
+ async init(){
18
+ await super.init()
19
+ this.addMetadatum('voltage','V', 'battery voltage')
20
+ }
21
+
22
+ getManufacturer(){
23
+ return "Lancol"
24
+ }
25
+ async propertiesChanged(props){
26
+ super.propertiesChanged(props)
27
+
28
+ if (props.Name) {
29
+ const regex = /[+-]?([0-9]*[.])?[0-9]+/
30
+ const r = this.valueIfVariant(props.Name).match(regex)
31
+ if (r) {
32
+ this.emit("voltage",parseFloat([...r][0]))
33
+ } else {
34
+ this.debug(`Unable to parse Name property for ${this.getName()}: ${props.Name}`)
35
+ }
36
+ }
37
+ }
38
+ }
39
+ module.exports=LancolVoltageMeter
@@ -0,0 +1,109 @@
1
+ const BTHomeServiceData = require("./BTHome/BTHomeServiceData");
2
+ const AbstractBTHomeSensor = require("./BTHome/AbstractBTHomeSensor");
3
+
4
+ /**
5
+ * Sensor class representing the Shelly BLU H&T.
6
+ *
7
+ * This sensor is publishing data utilising the BTHome format and inherits from {@link AbstractBTHomeSensor}.
8
+ */
9
+ class ShellySBHT003C extends AbstractBTHomeSensor {
10
+ /**
11
+ * The shortened local name as advertised by the Shelly BLU H&T.
12
+ * @type {string}
13
+ */
14
+ static SHORTENED_LOCAL_NAME = "SBHT-003C";
15
+
16
+ async init() {
17
+ await super.init();
18
+ this.initMetadata();
19
+ }
20
+
21
+ /**
22
+ * @typedef ButtonPressEvent {string}
23
+ */
24
+ /**
25
+ * The Shelly BLU H&T only supports single press and hold press options.
26
+ * @type {Readonly<{PRESS: string, HOLD_PRESS: string}>}
27
+ */
28
+ static ButtonPressEvent = Object.freeze({
29
+ PRESS: "press",
30
+ HOLD_PRESS: "hold_press",
31
+ });
32
+
33
+ /**
34
+ * Returns the `ShellySBHT003C` sensor class if the specified device has been identified as Shelly BLU H&T.
35
+ *
36
+ * @param device The Bluetooth device to be identified.
37
+ * @returns {Promise<ShellySBHT003C|null>} Returns the sensor class if the device has been identified, or null.
38
+ */
39
+ static async identify(device) {
40
+ if (
41
+ (await ShellySBHT003C.hasBtHomeServiceData(device)) &&
42
+ (await ShellySBHT003C.hasName(
43
+ device,
44
+ ShellySBHT003C.SHORTENED_LOCAL_NAME,
45
+ ))
46
+ ) {
47
+ return ShellySBHT003C;
48
+ }
49
+ return null;
50
+ }
51
+
52
+ /**
53
+ * Parses the relevant button press events for the Shelly BLU H&T from the specified BTHome data. This device only
54
+ * uses a subset of all available BTHome button press events.
55
+ *
56
+ * @param btHomeData {BTHomeServiceData.BthomeServiceData} The BTHome data provided by the device.
57
+ * @returns {ShellySBHT003C.ButtonPressEvent|null} The device's button state.
58
+ * @see https://shelly-api-docs.shelly.cloud/docs-ble/Devices/ht/#button-press-events
59
+ * @see https://bthome.io/format/
60
+ */
61
+ static parseShellySBHT003CButton(btHomeData) {
62
+ const buttonEvent = ShellySBHT003C.parseButton(btHomeData);
63
+ if (buttonEvent) {
64
+ if (buttonEvent === BTHomeServiceData.ButtonEventType.PRESS) {
65
+ return ShellySBHT003C.ButtonPressEvent.PRESS;
66
+ /*
67
+ * Prior to firmware version 1.0.20, the hold press event is indicated by 0xFE, which does
68
+ * not conform with the BTHome standard.
69
+ */
70
+ }
71
+ if (
72
+ buttonEvent === BTHomeServiceData.ButtonEventType.HOLD_PRESS ||
73
+ buttonEvent === 0xfe
74
+ ) {
75
+ return ShellySBHT003C.ButtonPressEvent.HOLD_PRESS;
76
+ }
77
+ }
78
+ return null;
79
+ }
80
+
81
+ initMetadata() {
82
+ this.addMetadatum(
83
+ "battery",
84
+ "ratio",
85
+ "battery level",
86
+ ShellySBHT003C.parseBatteryLevel,
87
+ );
88
+ this.addMetadatum(
89
+ "temp",
90
+ "K",
91
+ "temperature",
92
+ ShellySBHT003C.parseTemperature,
93
+ );
94
+ this.addMetadatum(
95
+ "humidity",
96
+ "ratio",
97
+ "humidity",
98
+ ShellySBHT003C.parseHumidity,
99
+ );
100
+ this.addMetadatum(
101
+ "button",
102
+ "enum",
103
+ "button",
104
+ ShellySBHT003C.parseShellySBHT003CButton,
105
+ );
106
+ }
107
+ }
108
+
109
+ module.exports = ShellySBHT003C;
@@ -78,13 +78,13 @@ class VictronBatteryMonitor extends VictronSensor{
78
78
  break;
79
79
  case VC.AuxMode.MIDPOINT_VOLTAGE:
80
80
  this.addMetadatum('midpointVoltage','V', 'midpoint battery voltage',
81
- (buff,offset=0)=>{return buff.readInt16LE(offset)/100},
81
+ (buff,offset=0)=>{return buff.readUInt16LE(offset)/100},
82
82
  '6597ed7d-4bda-4c1e-af4b-551c4cf74769')
83
83
  break;
84
84
 
85
85
  case VC.AuxMode.TEMPERATURE:
86
86
  this.addMetadatum('temperature','K', 'House battery temperature',
87
- (buff,offset=0)=>{return (buff.readInt16LE(offset)/1000)+273.15},
87
+ (buff,offset=0)=>{return (buff.readUInt16LE(offset)/100)},
88
88
  '6597ed7d-4bda-4c1e-af4b-551c4cf74769')
89
89
  break;
90
90
  default:
@@ -114,7 +114,7 @@ class VictronBatteryMonitor extends VictronSensor{
114
114
  default:
115
115
  break
116
116
  }
117
- this.emit("current", (this.NaNif(int24.readInt24LE(decData, 8)>>2,0x3FFFFF))/1000)
117
+ this.emit("current", (this.NaNif(int24.readInt24LE(decData, 8)>>2,0x1FFFFF))/1000)
118
118
  this.emit("consumed",(this.NaNif(int24.readInt24LE(decData, 11)&0xFFFFF,0xFFFFF)) / 10) ;
119
119
  this.emit("soc", this.NaNif(((decData.readUInt16LE(13)& 0x3FFF)>>4),0x3FF)/1000)
120
120