Skip to content

Commit

Permalink
feat(conductivity): add 0x56 for 16-bit Conductivity measurement type
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael-SOWNet committed Aug 20, 2024
1 parent 07f4729 commit be7b68f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bthome_ble/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,8 @@ class ExtendedSensorLibrary(SensorLibrary):
data_length=4,
factor=0.001,
),
0x56: MeasTypes(
meas_format=SensorLibrary.CONDUCTIVITY__CONDUCTIVITY,
data_length=2,
),
}
43 changes: 43 additions & 0 deletions tests/test_parser_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
KEY_VOLUME_FLOW_RATE = DeviceKey(key="volume_flow_rate", device_id=None)
KEY_VOLUME_STORAGE = DeviceKey(key="volume_storage", device_id=None)
KEY_WATER = DeviceKey(key="water", device_id=None)
KEY_CONDUCTIVITY = DeviceKey(key="conductivity", device_id=None)


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -1745,6 +1746,48 @@ def test_bthome_moisture(caplog):
)


def test_bthome_conductivity(caplog):
"""Test BTHome parser for conductivity reading from SenseNL sensor."""
data_string = b"\x40\x56\xe8\x03"
advertisement = bytes_to_service_info(
data_string, local_name="TEST DEVICE", address="A4:C1:38:8D:18:B2"
)

device = BTHomeBluetoothDeviceData()
assert device.update(advertisement) == SensorUpdate(
title="TEST DEVICE 18B2",
devices={
None: SensorDeviceInfo(
name="TEST DEVICE 18B2",
manufacturer=None,
model="BTHome sensor",
sw_version="BTHome BLE v2",
hw_version=None,
)
},
entity_descriptions={
KEY_CONDUCTIVITY: SensorDescription(
device_key=KEY_CONDUCTIVITY,
device_class=SensorDeviceClass.CONDUCTIVITY,
native_unit_of_measurement=Units.CONDUCTIVITY,
),
KEY_SIGNAL_STRENGTH: SensorDescription(
device_key=KEY_SIGNAL_STRENGTH,
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
),
},
entity_values={
KEY_CONDUCTIVITY: SensorValue(
device_key=KEY_CONDUCTIVITY, name="Conductivity", native_value=1000
),
KEY_SIGNAL_STRENGTH: SensorValue(
device_key=KEY_SIGNAL_STRENGTH, name="Signal Strength", native_value=-60
),
},
)


def test_bthome_event_button_long_press(caplog):
"""Test BTHome parser for an event of a long press on a button without encryption."""
data_string = b"\x40\x3A\x04"
Expand Down

0 comments on commit be7b68f

Please sign in to comment.