Add test coverage for inkbird IBS-P02B (#144433)

Was reported not working in https://github.com/Bluetooth-Devices/inkbird-ble/issues/95#issuecomment-2860473798
but cannot reproduce the issue. The tests are still useful
This commit is contained in:
J. Nick Koston 2025-05-08 03:00:32 -05:00 committed by GitHub
parent 066d0f4143
commit ce4e51078f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 0 deletions

View File

@ -103,3 +103,13 @@ IAM_T1_SERVICE_INFO = _make_bluetooth_service_info(
service_data={},
source="local",
)
IBS_P02B_SERVICE_INFO = _make_bluetooth_service_info(
name="IBS-P02B",
manufacturer_data={9289: bytes.fromhex("111800656e0100005f00000100000000")},
service_uuids=["0000fff0-0000-1000-8000-00805f9b34fb"],
address="49:24:11:18:00:65",
rssi=-60,
service_data={},
source="local",
)

View File

@ -30,6 +30,7 @@ from homeassistant.util import dt as dt_util
from . import (
IAM_T1_SERVICE_INFO,
IBS_P02B_SERVICE_INFO,
SPS_PASSIVE_SERVICE_INFO,
SPS_SERVICE_INFO,
SPS_WITH_CORRUPT_NAME_SERVICE_INFO,
@ -256,3 +257,40 @@ async def test_notify_sensor(hass: HomeAssistant) -> None:
saved_device_data_changed_callback({"temp_unit": "C"})
assert entry.data[CONF_DEVICE_DATA] == {"temp_unit": "C"}
async def test_ibs_p02b_sensors(hass: HomeAssistant) -> None:
"""Test setting up creates the sensors for an IBS-P02B."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="49:24:11:18:00:65",
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
inject_bluetooth_service_info(hass, IBS_P02B_SERVICE_INFO)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 2
temp_sensor = hass.states.get("sensor.ibs_p02b_0065_battery")
temp_sensor_attribtes = temp_sensor.attributes
assert temp_sensor.state == "95"
assert temp_sensor_attribtes[ATTR_FRIENDLY_NAME] == "IBS-P02B 0065 Battery"
assert temp_sensor_attribtes[ATTR_UNIT_OF_MEASUREMENT] == "%"
assert temp_sensor_attribtes[ATTR_STATE_CLASS] == "measurement"
temp_sensor = hass.states.get("sensor.ibs_p02b_0065_temperature")
temp_sensor_attribtes = temp_sensor.attributes
assert temp_sensor.state == "36.6"
assert temp_sensor_attribtes[ATTR_FRIENDLY_NAME] == "IBS-P02B 0065 Temperature"
assert temp_sensor_attribtes[ATTR_UNIT_OF_MEASUREMENT] == "°C"
assert temp_sensor_attribtes[ATTR_STATE_CLASS] == "measurement"
# Make sure we remember the device type
# in case the name is corrupted later
assert entry.data[CONF_DEVICE_TYPE] == "IBS-P02B"
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()