Skip to content

Commit

Permalink
Fix fraction of kkm sensos
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernst79 committed Mar 4, 2024
1 parent 7496e66 commit cb6ca99
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
7 changes: 2 additions & 5 deletions custom_components/ble_monitor/ble_parser/kkm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ def parse_kkm(self, data: bytes, mac: str):
">BBBHbBBBhhh", data[4:19]
)
if frame_type == 0x21 and version == 1:
if temp < 0:
temperature = -(temp + 128 + temp_frac / 100)
else:
temperature = temp + temp_frac / 100
humidity = humi + humi_frac / 100
temperature = temp + temp_frac / 256
humidity = humi + humi_frac / 256
result.update(
{
"temperature": temperature,
Expand Down
32 changes: 28 additions & 4 deletions custom_components/ble_monitor/test/test_kkm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestKKM:
"""Tests for the KKM parser"""
def test_kkm_k6(self):
"""Test KKM BLE parser for K6 sensors"""
data_string = "043E26020100016CD0060234DD1A0201060303AAFE1216AAFE21010F0E07192A224FFFFCFFEC03EBD3"
data_string = "043E26020100016CD0060234DD1A0201060303AAFE1216AAFE2101070e5b16531f95FFFCFFEC03EBD3"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
Expand All @@ -18,12 +18,36 @@ def test_kkm_k6(self):
assert sensor_msg["mac"] == "DD340206D06C"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["temperature"] == 25.42
assert sensor_msg["humidity"] == 34.79
assert sensor_msg["temperature"] == 22.32421875
assert sensor_msg["humidity"] == 31.58203125
assert sensor_msg["acceleration"] == 1003.2
assert sensor_msg["acceleration x"] == -4
assert sensor_msg["acceleration y"] == -20
assert sensor_msg["acceleration z"] == 1003
assert sensor_msg["voltage"] == 3.591
assert sensor_msg["voltage"] == 3.675
assert sensor_msg["battery"] == 100
assert sensor_msg["rssi"] == -45

def test_kkm_k6_neg_temp(self):
"""Test KKM BLE parser for K6 sensors with negative temperature"""
data_string = "043E26020100016CD0060234DD1A0201060303AAFE1216AAFE2101070e5bffc01f95FFFCFFEC03EBD3"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
ble_parser = BleParser()
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "KKM"
assert sensor_msg["type"] == "K6 Sensor Beacon"
assert sensor_msg["mac"] == "DD340206D06C"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["temperature"] == -0.25
assert sensor_msg["humidity"] == 31.58203125
assert sensor_msg["acceleration"] == 1003.2
assert sensor_msg["acceleration x"] == -4
assert sensor_msg["acceleration y"] == -20
assert sensor_msg["acceleration z"] == 1003
assert sensor_msg["voltage"] == 3.675
assert sensor_msg["battery"] == 100
assert sensor_msg["rssi"] == -45

0 comments on commit cb6ca99

Please sign in to comment.