Skip to content

Commit e591eae

Browse files
authored
Discard sensor temperature alert status flags (#46)
Per [specification the broadcast message](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#meter-broadcast-message-format) byte 3 includes the device temperature and humidity alert status flags and the decimal temperature (in the last 4 bits). Therefore, only the last 4 bits should be considered to extract the temperature in Celsius. Without this fix, when the sensor is within the alert range the flags cause the temperature to interpreted incorrectly.
1 parent dbc9d52 commit e591eae

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

switchbot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _process_wosensorth(data: bytes) -> dict[str, object]:
8686
"""Process woSensorTH/Temp sensor services data."""
8787

8888
_temp_sign = 1 if data[4] & 0b10000000 else -1
89-
_temp_c = _temp_sign * ((data[4] & 0b01111111) + (data[3] / 10))
89+
_temp_c = _temp_sign * ((data[4] & 0b01111111) + ((data[3] & 0b00001111) / 10))
9090
_temp_f = (_temp_c * 9 / 5) + 32
9191
_temp_f = (_temp_f * 10) / 10
9292

0 commit comments

Comments
 (0)