Add missing moisture sensor to xiaomi_ble (#78160)

pull/78169/head
Jc2k 2022-09-10 03:31:51 +01:00 committed by Paulus Schoutsen
parent 78802c8480
commit 258791626e
2 changed files with 48 additions and 0 deletions

View File

@ -39,6 +39,9 @@ BINARY_SENSOR_DESCRIPTIONS = {
key=XiaomiBinarySensorDeviceClass.SMOKE,
device_class=BinarySensorDeviceClass.SMOKE,
),
XiaomiBinarySensorDeviceClass.MOISTURE: BinarySensorEntityDescription(
key=XiaomiBinarySensorDeviceClass.MOISTURE,
),
}

View File

@ -52,3 +52,48 @@ async def test_smoke_sensor(hass):
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
async def test_moisture(hass):
"""Make sure that formldehyde sensors are correctly mapped."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="C4:7C:8D:6A:3E:7A",
)
entry.add_to_hass(hass)
saved_callback = None
def _async_register_callback(_hass, _callback, _matcher, _mode):
nonlocal saved_callback
saved_callback = _callback
return lambda: None
with patch(
"homeassistant.components.bluetooth.update_coordinator.async_register_callback",
_async_register_callback,
):
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
# WARNING: This test data is synthetic, rather than captured from a real device
# obj type is 0x1014, payload len is 0x2 and payload is 0xf400
saved_callback(
make_advertisement(
"C4:7C:8D:6A:3E:7A", b"q \x5d\x01iz>j\x8d|\xc4\r\x14\x10\x02\xf4\x00"
),
BluetoothChange.ADVERTISEMENT,
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1
sensor = hass.states.get("binary_sensor.smart_flower_pot_6a3e7a_moisture")
sensor_attr = sensor.attributes
assert sensor.state == "on"
assert sensor_attr[ATTR_FRIENDLY_NAME] == "Smart Flower Pot 6A3E7A Moisture"
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()