Make Withings test sensors from entity registry (#102025)
Test entities from entity registry
This commit is contained in:
parent
0eb4567364
commit
dc19290271
1 changed files with 8 additions and 21 deletions
|
@ -7,15 +7,11 @@ from freezegun.api import FrozenDateTimeFactory
|
|||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.withings.const import DOMAIN
|
||||
from homeassistant.components.withings.sensor import MEASUREMENT_SENSORS, SLEEP_SENSORS
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.const import STATE_UNAVAILABLE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import setup_integration
|
||||
from .conftest import USER_ID
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
|
@ -24,19 +20,6 @@ from tests.common import (
|
|||
)
|
||||
|
||||
|
||||
async def async_get_entity_id(
|
||||
hass: HomeAssistant,
|
||||
key: str,
|
||||
user_id: int,
|
||||
platform: str,
|
||||
) -> str | None:
|
||||
"""Get an entity id for a user's attribute."""
|
||||
entity_registry = er.async_get(hass)
|
||||
unique_id = f"withings_{user_id}_{key}"
|
||||
|
||||
return entity_registry.async_get_entity_id(platform, DOMAIN, unique_id)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_all_entities(
|
||||
hass: HomeAssistant,
|
||||
|
@ -46,10 +29,14 @@ async def test_all_entities(
|
|||
) -> None:
|
||||
"""Test all entities."""
|
||||
await setup_integration(hass, polling_config_entry)
|
||||
entity_registry = er.async_get(hass)
|
||||
entities = er.async_entries_for_config_entry(
|
||||
entity_registry, polling_config_entry.entry_id
|
||||
)
|
||||
|
||||
for sensor in MEASUREMENT_SENSORS + SLEEP_SENSORS:
|
||||
entity_id = await async_get_entity_id(hass, sensor.key, USER_ID, SENSOR_DOMAIN)
|
||||
assert hass.states.get(entity_id) == snapshot
|
||||
for entity in entities:
|
||||
if entity.platform == Platform.SENSOR:
|
||||
assert hass.states.get(entity.entity_id) == snapshot
|
||||
|
||||
|
||||
async def test_update_failed(
|
||||
|
|
Loading…
Add table
Reference in a new issue