Skip to content

Commit b3cbda4

Browse files
sheldonipbdraco
andauthored
Add support for data with zero values from WoSensorTH (#230)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 9a36e4e commit b3cbda4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

switchbot/adv_parsers/meter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ def process_wosensorth(data: bytes | None, mfr_data: bytes | None) -> dict[str,
2626
)
2727
_temp_f = (_temp_c * 9 / 5) + 32
2828
_temp_f = (_temp_f * 10) / 10
29+
humidity = temp_data[2] & 0b01111111
30+
31+
if _temp_c == 0 and humidity == 0 and battery == 0:
32+
return {}
2933

3034
_wosensorth_data = {
3135
# Data should be flat, but we keep the original structure for now
3236
"temp": {"c": _temp_c, "f": _temp_f},
3337
"temperature": _temp_c,
3438
"fahrenheit": bool(temp_data[2] & 0b10000000),
35-
"humidity": temp_data[2] & 0b01111111,
39+
"humidity": humidity,
3640
"battery": battery,
3741
}
3842

tests/test_adv_parser.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,29 @@ def test_wosensor_passive_only():
940940
)
941941

942942

943+
def test_wosensor_active_zero_data():
944+
"""Test parsing wosensor with active data but all values are zero."""
945+
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
946+
adv_data = generate_advertisement_data(
947+
manufacturer_data={},
948+
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"T\x00\x00\x00\x00\x00"},
949+
tx_power=-127,
950+
rssi=-50,
951+
)
952+
result = parse_advertisement_data(ble_device, adv_data)
953+
assert result == SwitchBotAdvertisement(
954+
address="aa:bb:cc:dd:ee:ff",
955+
data={
956+
"data": {},
957+
"isEncrypted": False,
958+
"model": "T",
959+
"rawAdvData": b"T\x00\x00\x00\x00\x00",
960+
},
961+
device=ble_device,
962+
rssi=-50,
963+
active=True,
964+
)
965+
943966
def test_woiosensor_passive_and_active():
944967
"""Test parsing woiosensor as passive with active data as well."""
945968
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")

0 commit comments

Comments
 (0)