Update a* tests to use device & entity registry fixtures (#103711)

pull/103706/head^2
Franck Nijhof 2023-11-09 20:46:20 +01:00 committed by GitHub
parent b81f15725f
commit 04e0e2bd75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 321 additions and 262 deletions

View File

@ -24,10 +24,11 @@ from .common import setup_platform
DEVICE_ID = "alarm_control_panel.abode_alarm"
async def test_entity_registry(hass: HomeAssistant) -> None:
async def test_entity_registry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, ALARM_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(DEVICE_ID)
# Abode alarm device unique_id is the MAC address

View File

@ -17,10 +17,11 @@ from homeassistant.helpers import entity_registry as er
from .common import setup_platform
async def test_entity_registry(hass: HomeAssistant) -> None:
async def test_entity_registry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, BINARY_SENSOR_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("binary_sensor.front_door")
assert entry.unique_id == "2834013428b6035fba7d4054aa7b25a3"

View File

@ -10,10 +10,11 @@ from homeassistant.helpers import entity_registry as er
from .common import setup_platform
async def test_entity_registry(hass: HomeAssistant) -> None:
async def test_entity_registry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, CAMERA_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("camera.test_cam")
assert entry.unique_id == "d0a3a1c316891ceb00c20118aae2a133"

View File

@ -18,10 +18,11 @@ from .common import setup_platform
DEVICE_ID = "cover.garage_door"
async def test_entity_registry(hass: HomeAssistant) -> None:
async def test_entity_registry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, COVER_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(DEVICE_ID)
assert entry.unique_id == "61cbz3b542d2o33ed2fz02721bda3324"

View File

@ -27,10 +27,11 @@ from .common import setup_platform
DEVICE_ID = "light.living_room_lamp"
async def test_entity_registry(hass: HomeAssistant) -> None:
async def test_entity_registry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, LIGHT_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(DEVICE_ID)
assert entry.unique_id == "741385f4388b2637df4c6b398fe50581"

View File

@ -18,10 +18,11 @@ from .common import setup_platform
DEVICE_ID = "lock.test_lock"
async def test_entity_registry(hass: HomeAssistant) -> None:
async def test_entity_registry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, LOCK_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(DEVICE_ID)
assert entry.unique_id == "51cab3b545d2o34ed7fz02731bda5324"

View File

@ -14,10 +14,11 @@ from homeassistant.helpers import entity_registry as er
from .common import setup_platform
async def test_entity_registry(hass: HomeAssistant) -> None:
async def test_entity_registry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, SENSOR_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("sensor.environment_sensor_humidity")
assert entry.unique_id == "13545b21f4bdcd33d9abd461f8443e65-humidity"

View File

@ -24,10 +24,11 @@ DEVICE_ID = "switch.test_switch"
DEVICE_UID = "0012a4d3614cb7e2b8c9abea31d2fb2a"
async def test_entity_registry(hass: HomeAssistant) -> None:
async def test_entity_registry(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Tests that the devices are registered in the entity registry."""
await setup_platform(hass, SWITCH_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get(AUTOMATION_ID)
assert entry.unique_id == AUTOMATION_UID

View File

@ -117,11 +117,11 @@ async def test_update_interval_forecast(hass: HomeAssistant) -> None:
assert mock_forecast.call_count == 1
async def test_remove_ozone_sensors(hass: HomeAssistant) -> None:
async def test_remove_ozone_sensors(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test remove ozone sensors from registry."""
registry = er.async_get(hass)
registry.async_get_or_create(
entity_registry.async_get_or_create(
SENSOR_PLATFORM,
DOMAIN,
"0123456-ozone-0",
@ -131,5 +131,5 @@ async def test_remove_ozone_sensors(hass: HomeAssistant) -> None:
await init_integration(hass)
entry = registry.async_get("sensor.home_ozone_0d")
entry = entity_registry.async_get("sensor.home_ozone_0d")
assert entry is None

View File

@ -42,11 +42,12 @@ from tests.common import (
async def test_sensor_without_forecast(
hass: HomeAssistant, entity_registry_enabled_by_default: None
hass: HomeAssistant,
entity_registry_enabled_by_default: None,
entity_registry: er.EntityRegistry,
) -> None:
"""Test states of the sensor without forecast."""
await init_integration(hass)
registry = er.async_get(hass)
state = hass.states.get("sensor.home_cloud_ceiling")
assert state
@ -57,7 +58,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DISTANCE
entry = registry.async_get("sensor.home_cloud_ceiling")
entry = entity_registry.async_get("sensor.home_cloud_ceiling")
assert entry
assert entry.unique_id == "0123456-ceiling"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -78,7 +79,7 @@ async def test_sensor_without_forecast(
== SensorDeviceClass.PRECIPITATION_INTENSITY
)
entry = registry.async_get("sensor.home_precipitation")
entry = entity_registry.async_get("sensor.home_precipitation")
assert entry
assert entry.unique_id == "0123456-precipitation"
@ -91,7 +92,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_STATE_CLASS) is None
assert state.attributes.get(ATTR_OPTIONS) == ["falling", "rising", "steady"]
entry = registry.async_get("sensor.home_pressure_tendency")
entry = entity_registry.async_get("sensor.home_pressure_tendency")
assert entry
assert entry.unique_id == "0123456-pressuretendency"
assert entry.translation_key == "pressure_tendency"
@ -104,7 +105,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_realfeel_temperature")
entry = entity_registry.async_get("sensor.home_realfeel_temperature")
assert entry
assert entry.unique_id == "0123456-realfeeltemperature"
@ -116,7 +117,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get("level") == "High"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_uv_index")
entry = entity_registry.async_get("sensor.home_uv_index")
assert entry
assert entry.unique_id == "0123456-uvindex"
@ -128,7 +129,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_apparent_temperature")
entry = entity_registry.async_get("sensor.home_apparent_temperature")
assert entry
assert entry.unique_id == "0123456-apparenttemperature"
@ -140,7 +141,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_ICON) == "mdi:weather-cloudy"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_cloud_cover")
entry = entity_registry.async_get("sensor.home_cloud_cover")
assert entry
assert entry.unique_id == "0123456-cloudcover"
@ -152,7 +153,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_dew_point")
entry = entity_registry.async_get("sensor.home_dew_point")
assert entry
assert entry.unique_id == "0123456-dewpoint"
@ -164,7 +165,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_realfeel_temperature_shade")
entry = entity_registry.async_get("sensor.home_realfeel_temperature_shade")
assert entry
assert entry.unique_id == "0123456-realfeeltemperatureshade"
@ -176,7 +177,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_wet_bulb_temperature")
entry = entity_registry.async_get("sensor.home_wet_bulb_temperature")
assert entry
assert entry.unique_id == "0123456-wetbulbtemperature"
@ -188,7 +189,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_wind_chill_temperature")
entry = entity_registry.async_get("sensor.home_wind_chill_temperature")
assert entry
assert entry.unique_id == "0123456-windchilltemperature"
@ -204,7 +205,7 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.WIND_SPEED
entry = registry.async_get("sensor.home_wind_gust_speed")
entry = entity_registry.async_get("sensor.home_wind_gust_speed")
assert entry
assert entry.unique_id == "0123456-windgust"
@ -220,17 +221,18 @@ async def test_sensor_without_forecast(
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.WIND_SPEED
entry = registry.async_get("sensor.home_wind_speed")
entry = entity_registry.async_get("sensor.home_wind_speed")
assert entry
assert entry.unique_id == "0123456-wind"
async def test_sensor_with_forecast(
hass: HomeAssistant, entity_registry_enabled_by_default: None
hass: HomeAssistant,
entity_registry_enabled_by_default: None,
entity_registry: er.EntityRegistry,
) -> None:
"""Test states of the sensor with forecast."""
await init_integration(hass, forecast=True)
registry = er.async_get(hass)
state = hass.states.get("sensor.home_hours_of_sun_today")
assert state
@ -240,7 +242,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTime.HOURS
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_hours_of_sun_today")
entry = entity_registry.async_get("sensor.home_hours_of_sun_today")
assert entry
assert entry.unique_id == "0123456-hoursofsun-0"
@ -252,7 +254,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_realfeel_temperature_max_today")
entry = entity_registry.async_get("sensor.home_realfeel_temperature_max_today")
assert entry
state = hass.states.get("sensor.home_realfeel_temperature_min_today")
@ -263,7 +265,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_realfeel_temperature_min_today")
entry = entity_registry.async_get("sensor.home_realfeel_temperature_min_today")
assert entry
assert entry.unique_id == "0123456-realfeeltemperaturemin-0"
@ -275,7 +277,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_thunderstorm_probability_today")
entry = entity_registry.async_get("sensor.home_thunderstorm_probability_today")
assert entry
assert entry.unique_id == "0123456-thunderstormprobabilityday-0"
@ -287,7 +289,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_thunderstorm_probability_tonight")
entry = entity_registry.async_get("sensor.home_thunderstorm_probability_tonight")
assert entry
assert entry.unique_id == "0123456-thunderstormprobabilitynight-0"
@ -300,7 +302,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get("level") == "moderate"
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_uv_index_today")
entry = entity_registry.async_get("sensor.home_uv_index_today")
assert entry
assert entry.unique_id == "0123456-uvindex-0"
@ -327,7 +329,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_ICON) == "mdi:weather-cloudy"
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_cloud_cover_today")
entry = entity_registry.async_get("sensor.home_cloud_cover_today")
assert entry
assert entry.unique_id == "0123456-cloudcoverday-0"
@ -339,7 +341,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_ICON) == "mdi:weather-cloudy"
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_cloud_cover_tonight")
entry = entity_registry.async_get("sensor.home_cloud_cover_tonight")
assert entry
state = hass.states.get("sensor.home_grass_pollen_today")
@ -354,7 +356,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_ICON) == "mdi:grass"
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_grass_pollen_today")
entry = entity_registry.async_get("sensor.home_grass_pollen_today")
assert entry
assert entry.unique_id == "0123456-grass-0"
@ -369,7 +371,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get("level") == "low"
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
entry = registry.async_get("sensor.home_mold_pollen_today")
entry = entity_registry.async_get("sensor.home_mold_pollen_today")
assert entry
assert entry.unique_id == "0123456-mold-0"
@ -384,7 +386,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get("level") == "low"
assert state.attributes.get(ATTR_ICON) == "mdi:sprout"
entry = registry.async_get("sensor.home_ragweed_pollen_today")
entry = entity_registry.async_get("sensor.home_ragweed_pollen_today")
assert entry
assert entry.unique_id == "0123456-ragweed-0"
@ -396,7 +398,9 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_realfeel_temperature_shade_max_today")
entry = entity_registry.async_get(
"sensor.home_realfeel_temperature_shade_max_today"
)
assert entry
assert entry.unique_id == "0123456-realfeeltemperatureshademax-0"
@ -407,7 +411,9 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTemperature.CELSIUS
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
entry = registry.async_get("sensor.home_realfeel_temperature_shade_min_today")
entry = entity_registry.async_get(
"sensor.home_realfeel_temperature_shade_min_today"
)
assert entry
assert entry.unique_id == "0123456-realfeeltemperatureshademin-0"
@ -423,7 +429,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_ICON) == "mdi:tree-outline"
assert state.attributes.get(ATTR_STATE_CLASS) is None
entry = registry.async_get("sensor.home_tree_pollen_today")
entry = entity_registry.async_get("sensor.home_tree_pollen_today")
assert entry
assert entry.unique_id == "0123456-tree-0"
@ -439,7 +445,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_ICON) is None
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.WIND_SPEED
entry = registry.async_get("sensor.home_wind_speed_today")
entry = entity_registry.async_get("sensor.home_wind_speed_today")
assert entry
assert entry.unique_id == "0123456-windday-0"
@ -456,7 +462,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_STATE_CLASS) is None
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.WIND_SPEED
entry = registry.async_get("sensor.home_wind_speed_tonight")
entry = entity_registry.async_get("sensor.home_wind_speed_tonight")
assert entry
assert entry.unique_id == "0123456-windnight-0"
@ -473,7 +479,7 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_STATE_CLASS) is None
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.WIND_SPEED
entry = registry.async_get("sensor.home_wind_gust_speed_today")
entry = entity_registry.async_get("sensor.home_wind_gust_speed_today")
assert entry
assert entry.unique_id == "0123456-windgustday-0"
@ -490,11 +496,11 @@ async def test_sensor_with_forecast(
assert state.attributes.get(ATTR_STATE_CLASS) is None
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.WIND_SPEED
entry = registry.async_get("sensor.home_wind_gust_speed_tonight")
entry = entity_registry.async_get("sensor.home_wind_gust_speed_tonight")
assert entry
assert entry.unique_id == "0123456-windgustnight-0"
entry = registry.async_get("sensor.home_air_quality_today")
entry = entity_registry.async_get("sensor.home_air_quality_today")
assert entry
assert entry.unique_id == "0123456-airquality-0"
@ -508,7 +514,7 @@ async def test_sensor_with_forecast(
== UnitOfIrradiance.WATTS_PER_SQUARE_METER
)
entry = registry.async_get("sensor.home_solar_irradiance_today")
entry = entity_registry.async_get("sensor.home_solar_irradiance_today")
assert entry
assert entry.unique_id == "0123456-solarirradianceday-0"
@ -522,7 +528,7 @@ async def test_sensor_with_forecast(
== UnitOfIrradiance.WATTS_PER_SQUARE_METER
)
entry = registry.async_get("sensor.home_solar_irradiance_tonight")
entry = entity_registry.async_get("sensor.home_solar_irradiance_tonight")
assert entry
assert entry.unique_id == "0123456-solarirradiancenight-0"
@ -534,7 +540,7 @@ async def test_sensor_with_forecast(
)
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
entry = registry.async_get("sensor.home_condition_today")
entry = entity_registry.async_get("sensor.home_condition_today")
assert entry
assert entry.unique_id == "0123456-longphraseday-0"
@ -543,7 +549,7 @@ async def test_sensor_with_forecast(
assert state.state == "Partly cloudy"
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
entry = registry.async_get("sensor.home_condition_tonight")
entry = entity_registry.async_get("sensor.home_condition_tonight")
assert entry
assert entry.unique_id == "0123456-longphrasenight-0"

View File

@ -55,10 +55,11 @@ from tests.common import (
from tests.typing import WebSocketGenerator
async def test_weather_without_forecast(hass: HomeAssistant) -> None:
async def test_weather_without_forecast(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the weather without forecast."""
await init_integration(hass)
registry = er.async_get(hass)
state = hass.states.get("weather.home")
assert state
@ -78,15 +79,16 @@ async def test_weather_without_forecast(hass: HomeAssistant) -> None:
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
assert ATTR_SUPPORTED_FEATURES not in state.attributes
entry = registry.async_get("weather.home")
entry = entity_registry.async_get("weather.home")
assert entry
assert entry.unique_id == "0123456"
async def test_weather_with_forecast(hass: HomeAssistant) -> None:
async def test_weather_with_forecast(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of the weather with forecast."""
await init_integration(hass, forecast=True)
registry = er.async_get(hass)
state = hass.states.get("weather.home")
assert state
@ -120,7 +122,7 @@ async def test_weather_with_forecast(hass: HomeAssistant) -> None:
assert forecast.get(ATTR_FORECAST_WIND_GUST_SPEED) == 29.6
assert forecast.get(ATTR_WEATHER_UV_INDEX) == 5
entry = registry.async_get("weather.home")
entry = entity_registry.async_get("weather.home")
assert entry
assert entry.unique_id == "0123456"

View File

@ -20,7 +20,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_binary_sensor_async_setup_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test binary sensor setup."""
@ -34,8 +36,6 @@ async def test_binary_sensor_async_setup_entry(
)
await add_mock_config(hass)
registry = er.async_get(hass)
assert len(aioclient_mock.mock_calls) == 1
# Test First Air Filter
@ -44,7 +44,7 @@ async def test_binary_sensor_async_setup_entry(
assert state
assert state.state == STATE_OFF
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-filter"
@ -54,7 +54,7 @@ async def test_binary_sensor_async_setup_entry(
assert state
assert state.state == STATE_ON
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac2-filter"
@ -64,7 +64,7 @@ async def test_binary_sensor_async_setup_entry(
assert state
assert state.state == STATE_ON
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z01-motion"
@ -74,7 +74,7 @@ async def test_binary_sensor_async_setup_entry(
assert state
assert state.state == STATE_OFF
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z02-motion"
@ -83,7 +83,7 @@ async def test_binary_sensor_async_setup_entry(
assert not hass.states.get(entity_id)
registry.async_update_entity(entity_id=entity_id, disabled_by=None)
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done()
async_fire_time_changed(
@ -96,7 +96,7 @@ async def test_binary_sensor_async_setup_entry(
assert state
assert state.state == STATE_ON
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z01-myzone"
@ -105,7 +105,7 @@ async def test_binary_sensor_async_setup_entry(
assert not hass.states.get(entity_id)
registry.async_update_entity(entity_id=entity_id, disabled_by=None)
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done()
async_fire_time_changed(
@ -118,6 +118,6 @@ async def test_binary_sensor_async_setup_entry(
assert state
assert state.state == STATE_OFF
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z02-myzone"

View File

@ -49,7 +49,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_climate_async_setup_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test climate platform."""
@ -63,8 +65,6 @@ async def test_climate_async_setup_entry(
)
await add_mock_config(hass)
registry = er.async_get(hass)
# Test MyZone Climate Entity
entity_id = "climate.myzone"
state = hass.states.get(entity_id)
@ -75,7 +75,7 @@ async def test_climate_async_setup_entry(
assert state.attributes.get(ATTR_TEMPERATURE) == 24
assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 25
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1"
@ -173,7 +173,7 @@ async def test_climate_async_setup_entry(
assert state.attributes.get(ATTR_TEMPERATURE) == 24
assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 25
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z01"
@ -227,7 +227,7 @@ async def test_climate_async_setup_entry(
assert state.attributes.get(ATTR_TARGET_TEMP_LOW) == 20
assert state.attributes.get(ATTR_TARGET_TEMP_HIGH) == 24
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac3"

View File

@ -30,7 +30,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_ac_cover(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test cover platform."""
@ -45,8 +47,6 @@ async def test_ac_cover(
await add_mock_config(hass)
registry = er.async_get(hass)
# Test Cover Zone Entity
entity_id = "cover.myauto_zone_y"
state = hass.states.get(entity_id)
@ -55,7 +55,7 @@ async def test_ac_cover(
assert state.attributes.get("device_class") == CoverDeviceClass.DAMPER
assert state.attributes.get("current_position") == 100
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac3-z01"
@ -144,7 +144,9 @@ async def test_ac_cover(
async def test_things_cover(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test cover platform."""
@ -159,8 +161,6 @@ async def test_things_cover(
await add_mock_config(hass)
registry = er.async_get(hass)
# Test Blind 1 Entity
entity_id = "cover.blind_1"
thing_id = "200"
@ -169,7 +169,7 @@ async def test_things_cover(
assert state.state == STATE_OPEN
assert state.attributes.get("device_class") == CoverDeviceClass.BLIND
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-200"

View File

@ -27,7 +27,11 @@ from . import (
from tests.test_util.aiohttp import AiohttpClientMocker
async def test_light(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
async def test_light(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test light setup."""
aioclient_mock.get(
@ -41,8 +45,6 @@ async def test_light(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -
await add_mock_config(hass)
registry = er.async_get(hass)
# Test Light Entity
entity_id = "light.light_a"
light_id = "100"
@ -50,7 +52,7 @@ async def test_light(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -
assert state
assert state.state == STATE_OFF
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == f"uniqueid-{light_id}"
@ -86,7 +88,7 @@ async def test_light(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -
entity_id = "light.light_b"
light_id = "101"
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == f"uniqueid-{light_id}"
@ -121,7 +123,9 @@ async def test_light(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -
async def test_things_light(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test things lights."""
@ -136,8 +140,6 @@ async def test_things_light(
await add_mock_config(hass)
registry = er.async_get(hass)
# Test Switch Entity
entity_id = "light.thing_light_dimmable"
light_id = "204"
@ -145,7 +147,7 @@ async def test_things_light(
assert state
assert state.state == STATE_ON
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-204"

View File

@ -22,7 +22,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_select_async_setup_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test select platform."""
@ -37,8 +39,6 @@ async def test_select_async_setup_entry(
await add_mock_config(hass)
registry = er.async_get(hass)
assert len(aioclient_mock.mock_calls) == 1
# Test MyZone Select Entity
@ -47,7 +47,7 @@ async def test_select_async_setup_entry(
assert state
assert state.state == "Zone open with Sensor"
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-myzone"

View File

@ -26,7 +26,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_sensor_platform(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test sensor platform."""
@ -40,8 +42,6 @@ async def test_sensor_platform(
)
await add_mock_config(hass)
registry = er.async_get(hass)
assert len(aioclient_mock.mock_calls) == 1
# Test First TimeToOn Sensor
@ -50,7 +50,7 @@ async def test_sensor_platform(
assert state
assert int(state.state) == 0
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-timetoOn"
@ -75,7 +75,7 @@ async def test_sensor_platform(
assert state
assert int(state.state) == 10
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-timetoOff"
@ -100,7 +100,7 @@ async def test_sensor_platform(
assert state
assert int(state.state) == 100
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z01-vent"
@ -110,7 +110,7 @@ async def test_sensor_platform(
assert state
assert int(state.state) == 0
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z02-vent"
@ -120,7 +120,7 @@ async def test_sensor_platform(
assert state
assert int(state.state) == 40
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z01-signal"
@ -130,7 +130,7 @@ async def test_sensor_platform(
assert state
assert int(state.state) == 10
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z02-signal"
@ -139,7 +139,7 @@ async def test_sensor_platform(
assert not hass.states.get(entity_id)
registry.async_update_entity(entity_id=entity_id, disabled_by=None)
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
await hass.async_block_till_done()
async_fire_time_changed(
@ -152,6 +152,6 @@ async def test_sensor_platform(
assert state
assert int(state.state) == 25
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-z01-temp"

View File

@ -27,7 +27,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_cover_async_setup_entry(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test switch platform."""
@ -42,15 +44,13 @@ async def test_cover_async_setup_entry(
await add_mock_config(hass)
registry = er.async_get(hass)
# Test Switch Entity
entity_id = "switch.myzone_fresh_air"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_OFF
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-freshair"
@ -82,7 +82,9 @@ async def test_cover_async_setup_entry(
async def test_things_switch(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test things switches."""
@ -97,8 +99,6 @@ async def test_things_switch(
await add_mock_config(hass)
registry = er.async_get(hass)
# Test Switch Entity
entity_id = "switch.relay"
thing_id = "205"
@ -106,7 +106,7 @@ async def test_things_switch(
assert state
assert state.state == STATE_ON
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-205"

View File

@ -10,7 +10,9 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_update_platform(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test update platform."""
@ -20,13 +22,11 @@ async def test_update_platform(
)
await add_mock_config(hass)
registry = er.async_get(hass)
entity_id = "update.testname_app"
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON
entry = registry.async_get(entity_id)
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid"

View File

@ -81,11 +81,11 @@ async def test_aemet_weather(
async def test_aemet_weather_legacy(
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
entity_registry: er.EntityRegistry,
) -> None:
"""Test states of legacy weather."""
registry = er.async_get(hass)
registry.async_get_or_create(
entity_registry.async_get_or_create(
WEATHER_DOMAIN,
DOMAIN,
"None hourly",

View File

@ -232,12 +232,12 @@ async def test_migrate_device_entry(
async def test_remove_air_quality_entities(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test remove air_quality entities from registry."""
registry = er.async_get(hass)
registry.async_get_or_create(
entity_registry.async_get_or_create(
AIR_QUALITY_PLATFORM,
DOMAIN,
"123-456",
@ -247,5 +247,5 @@ async def test_remove_air_quality_entities(
await init_integration(hass, aioclient_mock)
entry = registry.async_get("air_quality.home")
entry = entity_registry.async_get("air_quality.home")
assert entry is None

View File

@ -33,10 +33,13 @@ from tests.common import async_fire_time_changed, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
async def test_sensor(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test states of the sensor."""
await init_integration(hass, aioclient_mock)
registry = er.async_get(hass)
state = hass.states.get("sensor.home_common_air_quality_index")
assert state
@ -45,7 +48,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "CAQI"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get("sensor.home_common_air_quality_index")
entry = entity_registry.async_get("sensor.home_common_air_quality_index")
assert entry
assert entry.unique_id == "123-456-caqi"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -58,7 +61,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.HUMIDITY
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_humidity")
entry = entity_registry.async_get("sensor.home_humidity")
assert entry
assert entry.unique_id == "123-456-humidity"
assert entry.options["sensor"] == {"suggested_display_precision": 1}
@ -74,7 +77,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PM1
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_pm1")
entry = entity_registry.async_get("sensor.home_pm1")
assert entry
assert entry.unique_id == "123-456-pm1"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -90,7 +93,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PM25
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_pm2_5")
entry = entity_registry.async_get("sensor.home_pm2_5")
assert entry
assert entry.unique_id == "123-456-pm25"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -106,7 +109,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PM10
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_pm10")
entry = entity_registry.async_get("sensor.home_pm10")
assert entry
assert entry.unique_id == "123-456-pm10"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -122,7 +125,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert entry.options["sensor"] == {"suggested_display_precision": 0}
entry = registry.async_get("sensor.home_carbon_monoxide")
entry = entity_registry.async_get("sensor.home_carbon_monoxide")
assert entry
assert entry.unique_id == "123-456-co"
@ -137,7 +140,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.NITROGEN_DIOXIDE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_nitrogen_dioxide")
entry = entity_registry.async_get("sensor.home_nitrogen_dioxide")
assert entry
assert entry.unique_id == "123-456-no2"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -153,7 +156,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.OZONE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_ozone")
entry = entity_registry.async_get("sensor.home_ozone")
assert entry
assert entry.unique_id == "123-456-o3"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -169,7 +172,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.SULPHUR_DIOXIDE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_sulphur_dioxide")
entry = entity_registry.async_get("sensor.home_sulphur_dioxide")
assert entry
assert entry.unique_id == "123-456-so2"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -182,7 +185,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PRESSURE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_pressure")
entry = entity_registry.async_get("sensor.home_pressure")
assert entry
assert entry.unique_id == "123-456-pressure"
assert entry.options["sensor"] == {"suggested_display_precision": 0}
@ -195,7 +198,7 @@ async def test_sensor(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TEMPERATURE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.home_temperature")
entry = entity_registry.async_get("sensor.home_temperature")
assert entry
assert entry.unique_id == "123-456-temperature"
assert entry.options["sensor"] == {"suggested_display_precision": 1}

View File

@ -99,7 +99,9 @@ async def test_migration_1_2(hass: HomeAssistant, mock_pyairvisual) -> None:
}
async def test_migration_2_3(hass: HomeAssistant, mock_pyairvisual) -> None:
async def test_migration_2_3(
hass: HomeAssistant, mock_pyairvisual, device_registry: dr.DeviceRegistry
) -> None:
"""Test migrating from version 2 to 3."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -113,7 +115,6 @@ async def test_migration_2_3(hass: HomeAssistant, mock_pyairvisual) -> None:
)
entry.add_to_hass(hass)
device_registry = dr.async_get(hass)
device_registry.async_get_or_create(
name="192.168.1.100",
config_entry_id=entry.entry_id,

View File

@ -14,11 +14,11 @@ from .util import CONFIG, HVAC_MOCK, HVAC_VERSION_MOCK, HVAC_WEBSERVER_MOCK
from tests.common import MockConfigEntry
async def test_unique_id_migrate(hass: HomeAssistant) -> None:
async def test_unique_id_migrate(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test unique id migration."""
entity_registry = er.async_get(hass)
config_entry = MockConfigEntry(domain=DOMAIN, data=CONFIG)
config_entry.add_to_hass(hass)

View File

@ -25,9 +25,10 @@ async def test_unsupported_domain(hass: HomeAssistant) -> None:
assert not msg["payload"]["endpoints"]
async def test_categorized_hidden_entities(hass: HomeAssistant) -> None:
async def test_categorized_hidden_entities(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Discovery ignores hidden and categorized entities."""
entity_registry = er.async_get(hass)
request = get_new_request("Alexa.Discovery", "Discover")
entity_entry1 = entity_registry.async_get_or_create(

View File

@ -5,15 +5,16 @@ from homeassistant.helpers import entity_registry as er
from . import MOCK_STATUS, async_init_integration
async def test_binary_sensor(hass: HomeAssistant) -> None:
async def test_binary_sensor(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test states of binary sensor."""
await async_init_integration(hass, status=MOCK_STATUS)
registry = er.async_get(hass)
state = hass.states.get("binary_sensor.ups_online_status")
assert state
assert state.state == "on"
entry = registry.async_get("binary_sensor.ups_online_status")
entry = entity_registry.async_get("binary_sensor.ups_online_status")
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_statflag"

View File

@ -42,19 +42,19 @@ async def test_async_setup_entry(hass: HomeAssistant, status: OrderedDict) -> No
MOCK_STATUS,
),
)
async def test_device_entry(hass: HomeAssistant, status: OrderedDict) -> None:
async def test_device_entry(
hass: HomeAssistant, status: OrderedDict, device_registry: dr.DeviceRegistry
) -> None:
"""Test successful setup of device entries."""
await async_init_integration(hass, status=status)
# Verify device info is properly set up.
device_entries = dr.async_get(hass)
if "SERIALNO" not in status:
assert len(device_entries.devices) == 0
assert len(device_registry.devices) == 0
return
assert len(device_entries.devices) == 1
entry = device_entries.async_get_device({(DOMAIN, status["SERIALNO"])})
assert len(device_registry.devices) == 1
entry = device_registry.async_get_device({(DOMAIN, status["SERIALNO"])})
assert entry is not None
# Specify the mapping between field name and the expected fields in device entry.
fields = {

View File

@ -19,16 +19,15 @@ from homeassistant.helpers import entity_registry as er
from . import MOCK_STATUS, async_init_integration
async def test_sensor(hass: HomeAssistant) -> None:
async def test_sensor(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
"""Test states of sensor."""
await async_init_integration(hass, status=MOCK_STATUS)
registry = er.async_get(hass)
# Test a representative string sensor.
state = hass.states.get("sensor.ups_mode")
assert state
assert state.state == "Stand Alone"
entry = registry.async_get("sensor.ups_mode")
entry = entity_registry.async_get("sensor.ups_mode")
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_upsmode"
@ -41,7 +40,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
)
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.VOLTAGE
entry = registry.async_get("sensor.ups_input_voltage")
entry = entity_registry.async_get("sensor.ups_input_voltage")
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_linev"
@ -53,7 +52,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
)
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.VOLTAGE
entry = registry.async_get("sensor.ups_battery_voltage")
entry = entity_registry.async_get("sensor.ups_battery_voltage")
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_battv"
@ -62,7 +61,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state
assert state.state == "7"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfTime.DAYS
entry = registry.async_get("sensor.ups_self_test_interval")
entry = entity_registry.async_get("sensor.ups_self_test_interval")
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_stesti"
@ -72,7 +71,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.state == "14.0"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.ups_load")
entry = entity_registry.async_get("sensor.ups_load")
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_loadpct"
@ -82,24 +81,25 @@ async def test_sensor(hass: HomeAssistant) -> None:
assert state.state == "330"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
entry = registry.async_get("sensor.ups_nominal_output_power")
entry = entity_registry.async_get("sensor.ups_nominal_output_power")
assert entry
assert entry.unique_id == "XXXXXXXXXXXX_nompower"
async def test_sensor_disabled(hass: HomeAssistant) -> None:
async def test_sensor_disabled(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test sensor disabled by default."""
await async_init_integration(hass)
registry = er.async_get(hass)
# Test a representative integration-disabled sensor.
entry = registry.async_get("sensor.ups_model")
entry = entity_registry.async_get("sensor.ups_model")
assert entry.disabled
assert entry.unique_id == "XXXXXXXXXXXX_model"
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
# Test enabling entity.
updated_entry = registry.async_update_entity(
updated_entry = entity_registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)

View File

@ -102,10 +102,10 @@ async def test_select_entity_registering_device(
hass: HomeAssistant,
init_select: ConfigEntry,
pipeline_data: PipelineData,
device_registry: dr.DeviceRegistry,
) -> None:
"""Test entity registering as an assist device."""
dev_reg = dr.async_get(hass)
device = dev_reg.async_get_device(identifiers={("test", "test")})
device = device_registry.async_get_device(identifiers={("test", "test")})
assert device is not None
# Test device is registered

View File

@ -33,11 +33,12 @@ CLIMATE_ID = f"{Platform.CLIMATE}.{DOMAIN}"
async def test_climate(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test the creation and values of Atag climate device."""
await init_integration(hass, aioclient_mock)
entity_registry = er.async_get(hass)
assert entity_registry.async_is_registered(CLIMATE_ID)
entity = entity_registry.async_get(CLIMATE_ID)

View File

@ -9,14 +9,15 @@ from tests.test_util.aiohttp import AiohttpClientMocker
async def test_sensors(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test the creation of ATAG sensors."""
entry = await init_integration(hass, aioclient_mock)
registry = er.async_get(hass)
for item in SENSORS:
sensor_id = "_".join(f"sensor.{item}".lower().split())
assert registry.async_is_registered(sensor_id)
entry = registry.async_get(sensor_id)
assert entity_registry.async_is_registered(sensor_id)
entry = entity_registry.async_get(sensor_id)
assert entry.unique_id in [f"{UID}-{v}" for v in SENSORS.values()]

View File

@ -18,15 +18,16 @@ WATER_HEATER_ID = f"{Platform.WATER_HEATER}.{DOMAIN}"
async def test_water_heater(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
entity_registry: er.EntityRegistry,
) -> None:
"""Test the creation of Atag water heater."""
with patch("pyatag.entities.DHW.status"):
entry = await init_integration(hass, aioclient_mock)
registry = er.async_get(hass)
assert registry.async_is_registered(WATER_HEATER_ID)
entry = registry.async_get(WATER_HEATER_ID)
assert entity_registry.async_is_registered(WATER_HEATER_ID)
entry = entity_registry.async_get(WATER_HEATER_ID)
assert entry.unique_id == f"{UID}-{Platform.WATER_HEATER}"

View File

@ -293,13 +293,13 @@ async def test_doorbell_update_via_pubnub(hass: HomeAssistant) -> None:
assert binary_sensor_k98gidt45gul_name_ding.state == STATE_OFF
async def test_doorbell_device_registry(hass: HomeAssistant) -> None:
async def test_doorbell_device_registry(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test creation of a lock with doorsense and bridge ands up in the registry."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json")
await _create_august_with_devices(hass, [doorbell_one])
device_registry = dr.async_get(hass)
reg_device = device_registry.async_get_device(identifiers={("august", "tmt100")})
assert reg_device.model == "hydra1"
assert reg_device.name == "tmt100 Name"

View File

@ -19,7 +19,6 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.entity_registry import EntityRegistry
from homeassistant.setup import async_setup_component
from .mocks import (
@ -400,16 +399,17 @@ async def remove_device(ws_client, device_id, config_entry_id):
async def test_device_remove_devices(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we can only remove a device that no longer exists."""
assert await async_setup_component(hass, "config", {})
august_operative_lock = await _mock_operative_august_lock_detail(hass)
config_entry = await _create_august_with_devices(hass, [august_operative_lock])
registry: EntityRegistry = er.async_get(hass)
entity = registry.entities["lock.a6697750d607098bae8d6baa11ef8063_name"]
entity = entity_registry.entities["lock.a6697750d607098bae8d6baa11ef8063_name"]
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get(entity.device_id)
assert (
await remove_device(

View File

@ -35,13 +35,13 @@ from .mocks import (
from tests.common import async_fire_time_changed
async def test_lock_device_registry(hass: HomeAssistant) -> None:
async def test_lock_device_registry(
hass: HomeAssistant, device_registry: dr.DeviceRegistry
) -> None:
"""Test creation of a lock with doorsense and bridge ands up in the registry."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
await _create_august_with_devices(hass, [lock_one])
device_registry = dr.async_get(hass)
reg_device = device_registry.async_get_device(
identifiers={("august", "online_with_doorsense")}
)
@ -106,7 +106,9 @@ async def test_state_jammed(hass: HomeAssistant) -> None:
assert lock_online_with_doorsense_name.state == STATE_JAMMED
async def test_one_lock_operation(hass: HomeAssistant) -> None:
async def test_one_lock_operation(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test creation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
await _create_august_with_devices(hass, [lock_one])
@ -141,7 +143,6 @@ async def test_one_lock_operation(hass: HomeAssistant) -> None:
assert lock_online_with_doorsense_name.state == STATE_LOCKED
# No activity means it will be unavailable until the activity feed has data
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
@ -152,7 +153,9 @@ async def test_one_lock_operation(hass: HomeAssistant) -> None:
)
async def test_one_lock_operation_pubnub_connected(hass: HomeAssistant) -> None:
async def test_one_lock_operation_pubnub_connected(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test lock and unlock operations are async when pubnub is connected."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
assert lock_one.pubsub_channel == "pubsub"
@ -217,7 +220,6 @@ async def test_one_lock_operation_pubnub_connected(hass: HomeAssistant) -> None:
assert lock_online_with_doorsense_name.state == STATE_LOCKED
# No activity means it will be unavailable until the activity feed has data
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)

View File

@ -36,11 +36,12 @@ async def test_create_doorbell(hass: HomeAssistant) -> None:
)
async def test_create_doorbell_offline(hass: HomeAssistant) -> None:
async def test_create_doorbell_offline(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test creation of a doorbell that is offline."""
doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json")
await _create_august_with_devices(hass, [doorbell_one])
entity_registry = er.async_get(hass)
sensor_tmt100_name_battery = hass.states.get("sensor.tmt100_name_battery")
assert sensor_tmt100_name_battery.state == "81"
@ -62,11 +63,12 @@ async def test_create_doorbell_hardwired(hass: HomeAssistant) -> None:
assert sensor_tmt100_name_battery is None
async def test_create_lock_with_linked_keypad(hass: HomeAssistant) -> None:
async def test_create_lock_with_linked_keypad(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test creation of a lock with a linked keypad that both have a battery."""
lock_one = await _mock_lock_from_fixture(hass, "get_lock.doorsense_init.json")
await _create_august_with_devices(hass, [lock_one])
entity_registry = er.async_get(hass)
sensor_a6697750d607098bae8d6baa11ef8063_name_battery = hass.states.get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
@ -92,11 +94,12 @@ async def test_create_lock_with_linked_keypad(hass: HomeAssistant) -> None:
assert entry.unique_id == "5bc65c24e6ef2a263e1450a8_linked_keypad_battery"
async def test_create_lock_with_low_battery_linked_keypad(hass: HomeAssistant) -> None:
async def test_create_lock_with_low_battery_linked_keypad(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test creation of a lock with a linked keypad that both have a battery."""
lock_one = await _mock_lock_from_fixture(hass, "get_lock.low_keypad_battery.json")
await _create_august_with_devices(hass, [lock_one])
entity_registry = er.async_get(hass)
sensor_a6697750d607098bae8d6baa11ef8063_name_battery = hass.states.get(
"sensor.a6697750d607098bae8d6baa11ef8063_name_battery"
@ -135,7 +138,9 @@ async def test_create_lock_with_low_battery_linked_keypad(hass: HomeAssistant) -
)
async def test_lock_operator_bluetooth(hass: HomeAssistant) -> None:
async def test_lock_operator_bluetooth(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
@ -144,7 +149,6 @@ async def test_lock_operator_bluetooth(hass: HomeAssistant) -> None:
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
@ -160,7 +164,9 @@ async def test_lock_operator_bluetooth(hass: HomeAssistant) -> None:
assert state.attributes["method"] == "mobile"
async def test_lock_operator_keypad(hass: HomeAssistant) -> None:
async def test_lock_operator_keypad(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
@ -169,7 +175,6 @@ async def test_lock_operator_keypad(hass: HomeAssistant) -> None:
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
@ -185,14 +190,15 @@ async def test_lock_operator_keypad(hass: HomeAssistant) -> None:
assert state.attributes["method"] == "keypad"
async def test_lock_operator_remote(hass: HomeAssistant) -> None:
async def test_lock_operator_remote(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
activities = await _mock_activities_from_fixture(hass, "get_activity.lock.json")
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
@ -208,7 +214,9 @@ async def test_lock_operator_remote(hass: HomeAssistant) -> None:
assert state.attributes["method"] == "remote"
async def test_lock_operator_manual(hass: HomeAssistant) -> None:
async def test_lock_operator_manual(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
@ -217,7 +225,6 @@ async def test_lock_operator_manual(hass: HomeAssistant) -> None:
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
@ -232,7 +239,9 @@ async def test_lock_operator_manual(hass: HomeAssistant) -> None:
assert state.attributes["method"] == "manual"
async def test_lock_operator_autorelock(hass: HomeAssistant) -> None:
async def test_lock_operator_autorelock(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test operation of a lock with doorsense and bridge."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
@ -241,7 +250,6 @@ async def test_lock_operator_autorelock(hass: HomeAssistant) -> None:
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
@ -257,7 +265,9 @@ async def test_lock_operator_autorelock(hass: HomeAssistant) -> None:
assert state.attributes["method"] == "autorelock"
async def test_unlock_operator_manual(hass: HomeAssistant) -> None:
async def test_unlock_operator_manual(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test operation of a lock manually."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
@ -266,7 +276,6 @@ async def test_unlock_operator_manual(hass: HomeAssistant) -> None:
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)
@ -282,7 +291,9 @@ async def test_unlock_operator_manual(hass: HomeAssistant) -> None:
assert state.attributes["method"] == "manual"
async def test_unlock_operator_tag(hass: HomeAssistant) -> None:
async def test_unlock_operator_tag(
hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None:
"""Test operation of a lock with a tag."""
lock_one = await _mock_doorsense_enabled_august_lock_detail(hass)
@ -291,7 +302,6 @@ async def test_unlock_operator_tag(hass: HomeAssistant) -> None:
)
await _create_august_with_devices(hass, [lock_one], activities=activities)
entity_registry = er.async_get(hass)
lock_operator_sensor = entity_registry.async_get(
"sensor.online_with_doorsense_name_operator"
)

View File

@ -9,14 +9,13 @@ from .const import LOCAL_CONFIG, LOCAL_UNIQUE_ID
async def test_local_awair_sensors(
hass: HomeAssistant, local_devices, local_data
hass: HomeAssistant, local_devices, local_data, device_registry: dr.DeviceRegistry
) -> None:
"""Test expected sensors on a local Awair."""
fixtures = [local_devices, local_data]
entry = await setup_awair(hass, fixtures, LOCAL_UNIQUE_ID, LOCAL_CONFIG)
dev_reg = dr.async_get(hass)
device_entry = dr.async_entries_for_config_entry(dev_reg, entry.entry_id)[0]
device_entry = dr.async_entries_for_config_entry(device_registry, entry.entry_id)[0]
assert device_entry.name == "Mock Title"
@ -24,5 +23,5 @@ async def test_local_awair_sensors(
hass.config_entries.async_update_entry(entry, title="Hello World")
await hass.async_block_till_done()
device_entry = dev_reg.async_get(device_entry.id)
device_entry = device_registry.async_get(device_entry.id)
assert device_entry.name == "Hello World"

View File

@ -65,17 +65,20 @@ def assert_expected_properties(
async def test_awair_gen1_sensors(
hass: HomeAssistant, user, cloud_devices, gen1_data
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
user,
cloud_devices,
gen1_data,
) -> None:
"""Test expected sensors on a 1st gen Awair."""
fixtures = [user, cloud_devices, gen1_data]
await setup_awair(hass, fixtures, CLOUD_UNIQUE_ID, CLOUD_CONFIG)
registry = er.async_get(hass)
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_score",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"88",
@ -84,7 +87,7 @@ async def test_awair_gen1_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_temperature",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_TEMP].unique_id_tag}",
"21.8",
@ -93,7 +96,7 @@ async def test_awair_gen1_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_humidity",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_HUMID].unique_id_tag}",
"41.59",
@ -102,7 +105,7 @@ async def test_awair_gen1_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_carbon_dioxide",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_CO2].unique_id_tag}",
"654.0",
@ -114,7 +117,7 @@ async def test_awair_gen1_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_vocs",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_VOC].unique_id_tag}",
"366",
@ -126,7 +129,7 @@ async def test_awair_gen1_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_pm2_5",
# gen1 unique_id should be awair_12345-DUST, which matches old integration behavior
f"{AWAIR_UUID}_DUST",
@ -139,7 +142,7 @@ async def test_awair_gen1_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_pm10",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_PM10].unique_id_tag}",
"14.3",
@ -159,17 +162,20 @@ async def test_awair_gen1_sensors(
async def test_awair_gen2_sensors(
hass: HomeAssistant, user, cloud_devices, gen2_data
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
user,
cloud_devices,
gen2_data,
) -> None:
"""Test expected sensors on a 2nd gen Awair."""
fixtures = [user, cloud_devices, gen2_data]
await setup_awair(hass, fixtures, CLOUD_UNIQUE_ID, CLOUD_CONFIG)
registry = er.async_get(hass)
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_score",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"97",
@ -178,7 +184,7 @@ async def test_awair_gen2_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_pm2_5",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_PM25].unique_id_tag}",
"2.0",
@ -194,17 +200,16 @@ async def test_awair_gen2_sensors(
async def test_local_awair_sensors(
hass: HomeAssistant, local_devices, local_data
hass: HomeAssistant, entity_registry: er.EntityRegistry, local_devices, local_data
) -> None:
"""Test expected sensors on a local Awair."""
fixtures = [local_devices, local_data]
await setup_awair(hass, fixtures, LOCAL_UNIQUE_ID, LOCAL_CONFIG)
registry = er.async_get(hass)
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.mock_title_score",
f"{local_devices['device_uuid']}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"94",
@ -213,17 +218,20 @@ async def test_local_awair_sensors(
async def test_awair_mint_sensors(
hass: HomeAssistant, user, cloud_devices, mint_data
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
user,
cloud_devices,
mint_data,
) -> None:
"""Test expected sensors on an Awair mint."""
fixtures = [user, cloud_devices, mint_data]
await setup_awair(hass, fixtures, CLOUD_UNIQUE_ID, CLOUD_CONFIG)
registry = er.async_get(hass)
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_score",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"98",
@ -232,7 +240,7 @@ async def test_awair_mint_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_pm2_5",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_PM25].unique_id_tag}",
"1.0",
@ -244,7 +252,7 @@ async def test_awair_mint_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_illuminance",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_LUX].unique_id_tag}",
"441.7",
@ -256,17 +264,20 @@ async def test_awair_mint_sensors(
async def test_awair_glow_sensors(
hass: HomeAssistant, user, cloud_devices, glow_data
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
user,
cloud_devices,
glow_data,
) -> None:
"""Test expected sensors on an Awair glow."""
fixtures = [user, cloud_devices, glow_data]
await setup_awair(hass, fixtures, CLOUD_UNIQUE_ID, CLOUD_CONFIG)
registry = er.async_get(hass)
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_score",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"93",
@ -278,17 +289,20 @@ async def test_awair_glow_sensors(
async def test_awair_omni_sensors(
hass: HomeAssistant, user, cloud_devices, omni_data
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
user,
cloud_devices,
omni_data,
) -> None:
"""Test expected sensors on an Awair omni."""
fixtures = [user, cloud_devices, omni_data]
await setup_awair(hass, fixtures, CLOUD_UNIQUE_ID, CLOUD_CONFIG)
registry = er.async_get(hass)
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_score",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"99",
@ -297,7 +311,7 @@ async def test_awair_omni_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_sound_level",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SPL_A].unique_id_tag}",
"47.0",
@ -306,7 +320,7 @@ async def test_awair_omni_sensors(
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_illuminance",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_LUX].unique_id_tag}",
"804.9",
@ -335,17 +349,21 @@ async def test_awair_offline(
async def test_awair_unavailable(
hass: HomeAssistant, user, cloud_devices, gen1_data, awair_offline
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
user,
cloud_devices,
gen1_data,
awair_offline,
) -> None:
"""Test expected behavior when an Awair becomes offline later."""
fixtures = [user, cloud_devices, gen1_data]
await setup_awair(hass, fixtures, CLOUD_UNIQUE_ID, CLOUD_CONFIG)
registry = er.async_get(hass)
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_score",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"88",
@ -356,7 +374,7 @@ async def test_awair_unavailable(
await async_update_entity(hass, "sensor.living_room_score")
assert_expected_properties(
hass,
registry,
entity_registry,
"sensor.living_room_score",
f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
STATE_UNAVAILABLE,

View File

@ -41,7 +41,11 @@ def hass_mock_forward_entry_setup(hass):
async def test_device_setup(
hass: HomeAssistant, forward_entry_setup, config, setup_config_entry
hass: HomeAssistant,
forward_entry_setup,
config,
setup_config_entry,
device_registry: dr.DeviceRegistry,
) -> None:
"""Successful setup."""
device = hass.data[AXIS_DOMAIN][setup_config_entry.entry_id]
@ -62,7 +66,6 @@ async def test_device_setup(
assert device.name == config[CONF_NAME]
assert device.unique_id == FORMATTED_MAC
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get_device(
identifiers={(AXIS_DOMAIN, device.unique_id)}
)