core/tests/components/bluemaestro/test_sensor.py

47 lines
1.5 KiB
Python

"""Test the BlueMaestro sensors."""
import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.bluemaestro.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import BLUEMAESTRO_SERVICE_INFO
from tests.common import MockConfigEntry
from tests.components.bluetooth import inject_bluetooth_service_info
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_sensors(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test setting up creates the sensors."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="aa:bb:cc:dd:ee:ff",
)
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("sensor")) == 0
inject_bluetooth_service_info(hass, BLUEMAESTRO_SERVICE_INFO)
await hass.async_block_till_done()
assert len(hass.states.async_all("sensor")) == 5
entity_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
assert entity_entries
for entity_entry in entity_entries:
assert hass.states.get(entity_entry.entity_id) == snapshot(
name=f"{entity_entry.entity_id}-state"
)
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()