@@ -47,6 +47,8 @@ class BTHome:
47
47
HUMIDITY_UINT8 = const (0x2E )
48
48
MOISTURE_UINT8 = const (0x2F )
49
49
COUNT_UINT16 = const (0x3D )
50
+ COUNT_UINT32 = const (0x3E )
51
+ ROTATION_SINT16 = const (0x3F )
50
52
51
53
# There is more than one way to represent most sensor properties. This
52
54
# dictionary maps the object id to the property name.
@@ -70,9 +72,12 @@ class BTHome:
70
72
MOISTURE_UINT16 : "moisture" ,
71
73
HUMIDITY_UINT8 : "humidity" ,
72
74
MOISTURE_UINT8 : "moisture" ,
73
- COUNT_UINT16 : "count"
75
+ COUNT_UINT16 : "count" ,
76
+ COUNT_UINT32 : "count" ,
77
+ ROTATION_SINT16 : "rotation" ,
74
78
}
75
79
80
+ # Properties below are updated externally when sensor values are read.
76
81
# See "Sensor Data" table at https://bthome.io/format/ Property column.
77
82
acceleration = 0
78
83
battery = 0
@@ -130,14 +135,18 @@ def pack_local_name(self):
130
135
return local_name_bytes
131
136
132
137
# Technically, the functions below could be static methods, but @staticmethod
133
- # on a dictionary of functions only works with Python >3.10, but MicroPython
138
+ # on a dictionary of functions only works with Python >3.10, and MicroPython
134
139
# is based on 3.4. Also, __func__ and __get()__ workarounds throw errors in
135
140
# MicroPython. [^4]
136
141
137
142
# 8-bit unsigned integer with scaling of 1 (no decimal places)
138
143
def _pack_uint8_x1 (self , object_id , value ):
139
144
return pack ("BB" , object_id , value )
140
145
146
+ # 16-bit signed integer with scalling of 10 (1 decimal place)
147
+ def _pack_sint16_x10 (self , object_id , value ):
148
+ return pack ("<Bh" , object_id , round (value * 10 ))
149
+
141
150
# 16-bit signed integer with scalling of 100 (2 decimal places)
142
151
def _pack_sint16_x100 (self , object_id , value ):
143
152
return pack ("<Bh" , object_id , round (value * 100 ))
@@ -162,6 +171,10 @@ def _pack_uint24_x100(self, object_id, value):
162
171
def _pack_uint24_x1000 (self , object_id , value ):
163
172
return pack ("<BL" , object_id , round (value * 1000 ))[:- 1 ]
164
173
174
+ # 32-bit unsigned integer with scaling of 1 (no decimal places)
175
+ def _pack_uint32_x1 (self , object_id , value ):
176
+ return pack ("<BL" , object_id , round (value ))
177
+
165
178
_object_id_functions = {
166
179
BATTERY_UINT8 : _pack_uint8_x1 ,
167
180
TEMPERATURE_SINT16 : _pack_sint16_x100 ,
@@ -182,7 +195,9 @@ def _pack_uint24_x1000(self, object_id, value):
182
195
MOISTURE_UINT16 : _pack_uint16_x100 ,
183
196
HUMIDITY_UINT8 : _pack_uint8_x1 ,
184
197
MOISTURE_UINT8 : _pack_uint8_x1 ,
185
- COUNT_UINT16 : _pack_uint16_x1
198
+ COUNT_UINT16 : _pack_uint16_x1 ,
199
+ COUNT_UINT32 : _pack_uint32_x1 ,
200
+ ROTATION_SINT16 : _pack_sint16_x10 ,
186
201
}
187
202
188
203
# Concatenate an arbitrary number of sensor readings using parameters
0 commit comments