Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(conductivity): add 0x56 for 16-bit Conductivity measurement type #142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading