Skip to content

Commit

Permalink
fix: some IBBQ2 identify with xBBQ (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Aug 8, 2022
1 parent 7e8369f commit 0ebc14c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/inkbird_ble/parser.py
Expand Up @@ -62,28 +62,29 @@ def _process_update(self, local_name: str, address: str, data: bytes) -> None:
"""Update from BLE advertisement data."""
_LOGGER.debug("Parsing INKBIRD BLE advertisement data: %s", data)
msg_length = len(data)
lower_name = local_name.lower()

if (device_type := INKBIRD_NAMES.get(local_name)) and msg_length == 9:
if (device_type := INKBIRD_NAMES.get(lower_name)) and msg_length == 9:
self.set_device_type(device_type)
self.set_device_name(f"{device_type} {short_address(address)}")
(temp, hum) = unpack("<hH", data[0:4])
bat = int.from_bytes(data[7:8], "little")
if local_name == "sps":
if lower_name == "sps":
self.update_predefined_sensor(
SensorLibrary.TEMPERATURE__CELSIUS, temp / 100
)
self.update_predefined_sensor(
SensorLibrary.HUMIDITY__PERCENTAGE, hum / 100
)
self.update_predefined_sensor(SensorLibrary.BATTERY__PERCENTAGE, bat)
elif local_name == "tps":
elif lower_name == "tps":
self.update_predefined_sensor(
SensorLibrary.TEMPERATURE__CELSIUS, temp / 100
)
self.update_predefined_sensor(SensorLibrary.BATTERY__PERCENTAGE, bat)
return

if "ibbq" in local_name.lower() and (
if ("xbbq" in lower_name or "ibbq" in lower_name) and (
bbq_data := BBQ_LENGTH_TO_TYPE.get(msg_length)
):
dev_type, unpack_str = bbq_data
Expand Down
60 changes: 60 additions & 0 deletions tests/test_parser.py
Expand Up @@ -234,3 +234,63 @@ def test_ibbq_4():
),
},
)


def test_ibt_2x():
parser = INKBIRDBluetoothDeviceData()
service_info = BluetoothServiceInfo(
name="xBBQ",
manufacturer_data={1: b"\x00\x00,\x11\x00\x00m\xd3\x14\x01\x11\x01"},
service_uuids=["0000fff0-0000-1000-8000-00805f9b34fb"],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
service_data={},
source="local",
)
result = parser.update(service_info)
assert result == SensorUpdate(
title=None,
devices={
None: SensorDeviceInfo(
name="xBBQ EEFF",
model="iBBQ-2",
manufacturer="INKBIRD",
sw_version=None,
hw_version=None,
)
},
entity_descriptions={
DeviceKey(key="temperature_probe_1", device_id=None): SensorDescription(
device_key=DeviceKey(key="temperature_probe_1", device_id=None),
device_class=DeviceClass.TEMPERATURE,
native_unit_of_measurement=Units.TEMP_CELSIUS,
),
DeviceKey(key="signal_strength", device_id=None): SensorDescription(
device_key=DeviceKey(key="signal_strength", device_id=None),
device_class=DeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
),
DeviceKey(key="temperature_probe_2", device_id=None): SensorDescription(
device_key=DeviceKey(key="temperature_probe_2", device_id=None),
device_class=DeviceClass.TEMPERATURE,
native_unit_of_measurement=Units.TEMP_CELSIUS,
),
},
entity_values={
DeviceKey(key="temperature_probe_1", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature_probe_1", device_id=None),
name="Temperature " "Probe " "1",
native_value=27.6,
),
DeviceKey(key="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
DeviceKey(key="temperature_probe_2", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature_probe_2", device_id=None),
name="Temperature " "Probe " "2",
native_value=27.3,
),
},
)

0 comments on commit 0ebc14c

Please sign in to comment.