Use Platform constant in tests (#145801)

* Use Platform constant in tests

* spelling

* Fix platform
This commit is contained in:
epenet 2025-05-28 15:51:37 +02:00 committed by GitHub
parent 1889f0ef66
commit c3ade400fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 107 additions and 57 deletions

View File

@ -1,8 +1,5 @@
"""The tests for Alarm control panel platforms."""
from homeassistant.components.alarm_control_panel import (
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
@ -13,7 +10,7 @@ async def help_async_setup_entry_init(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [ALARM_CONTROL_PANEL_DOMAIN]
config_entry, [Platform.ALARM_CONTROL_PANEL]
)
return True

View File

@ -12,6 +12,7 @@ from homeassistant.components.alarm_control_panel import (
)
from homeassistant.components.alarm_control_panel.const import CodeFormat
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er, frame
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -172,7 +173,7 @@ async def setup_alarm_control_panel_platform_test_entity(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [ALARM_CONTROL_PANEL_DOMAIN]
config_entry, [Platform.ALARM_CONTROL_PANEL]
)
return True

View File

@ -16,6 +16,7 @@ from homeassistant.components.assist_pipeline.select import (
)
from homeassistant.components.assist_pipeline.vad import VadSensitivity
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import DeviceInfo
@ -53,7 +54,9 @@ async def init_select(hass: HomeAssistant, init_components) -> ConfigEntry:
domain="assist_pipeline", state=ConfigEntryState.LOADED
)
config_entry.add_to_hass(hass)
await hass.config_entries.async_forward_entry_setups(config_entry, ["select"])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.SELECT]
)
return config_entry
@ -160,8 +163,12 @@ async def test_select_entity_changing_pipelines(
assert state.state == pipeline_2.name
# Reload config entry to test selected option persists
assert await hass.config_entries.async_forward_entry_unload(config_entry, "select")
await hass.config_entries.async_forward_entry_setups(config_entry, ["select"])
assert await hass.config_entries.async_forward_entry_unload(
config_entry, Platform.SELECT
)
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.SELECT]
)
state = hass.states.get("select.assist_pipeline_test_prefix_pipeline")
assert state is not None
@ -208,8 +215,12 @@ async def test_select_entity_changing_vad_sensitivity(
assert state.state == VadSensitivity.AGGRESSIVE.value
# Reload config entry to test selected option persists
assert await hass.config_entries.async_forward_entry_unload(config_entry, "select")
await hass.config_entries.async_forward_entry_setups(config_entry, ["select"])
assert await hass.config_entries.async_forward_entry_unload(
config_entry, Platform.SELECT
)
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.SELECT]
)
state = hass.states.get("select.assist_pipeline_test_vad_sensitivity")
assert state is not None

View File

@ -15,6 +15,7 @@ from homeassistant.components.assist_satellite import (
AssistSatelliteWakeWord,
)
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.setup import async_setup_component
@ -144,14 +145,18 @@ async def init_components(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [AS_DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.ASSIST_SATELLITE]
)
return True
async def async_unload_entry_init(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Unload test config entry."""
await hass.config_entries.async_forward_entry_unload(config_entry, AS_DOMAIN)
await hass.config_entries.async_forward_entry_unload(
config_entry, Platform.ASSIST_SATELLITE
)
return True
mock_integration(

View File

@ -7,7 +7,7 @@ import pytest
from homeassistant.components import binary_sensor
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import STATE_OFF, STATE_ON, EntityCategory
from homeassistant.const import STATE_OFF, STATE_ON, EntityCategory, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -62,7 +62,7 @@ async def test_name(hass: HomeAssistant) -> None:
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [binary_sensor.DOMAIN]
config_entry, [Platform.BINARY_SENSOR]
)
return True
@ -142,7 +142,7 @@ async def test_entity_category_config_raises_error(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [binary_sensor.DOMAIN]
config_entry, [Platform.BINARY_SENSOR]
)
return True

View File

@ -20,6 +20,7 @@ from homeassistant.const import (
CONF_PLATFORM,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -136,7 +137,9 @@ async def test_name(hass: HomeAssistant) -> None:
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.BUTTON]
)
return True
mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View File

@ -120,7 +120,9 @@ def mock_setup_integration(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.CALENDAR]
)
return True
async def async_unload_entry_init(

View File

@ -201,7 +201,7 @@ async def mock_test_webrtc_cameras(hass: HomeAssistant) -> None:
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [camera.DOMAIN]
config_entry, [Platform.CAMERA]
)
return True
@ -210,7 +210,7 @@ async def mock_test_webrtc_cameras(hass: HomeAssistant) -> None:
) -> bool:
"""Unload test config entry."""
await hass.config_entries.async_forward_entry_unload(
config_entry, camera.DOMAIN
config_entry, Platform.CAMERA
)
return True

View File

@ -4,7 +4,6 @@ from collections.abc import Generator
import pytest
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
@ -45,7 +44,7 @@ def register_test_integration(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [CLIMATE_DOMAIN]
config_entry, [Platform.CLIMATE]
)
return True

View File

@ -59,7 +59,9 @@ def mock_setup_integration(hass: HomeAssistant) -> None:
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.CLIMATE]
)
return True
async def async_unload_entry_init(

View File

@ -15,7 +15,7 @@ from homeassistant.components.event import (
EventEntityDescription,
)
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import CONF_PLATFORM, STATE_UNKNOWN
from homeassistant.const import CONF_PLATFORM, STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.restore_state import STORAGE_KEY as RESTORE_STATE_KEY
@ -254,7 +254,9 @@ async def test_name(hass: HomeAssistant) -> None:
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.EVENT]
)
return True
mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View File

@ -40,7 +40,7 @@ from homeassistant.components.go2rtc.const import (
RECOMMENDED_VERSION,
)
from homeassistant.config_entries import ConfigEntry, ConfigEntryState, ConfigFlow
from homeassistant.const import CONF_URL
from homeassistant.const import CONF_URL, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.typing import ConfigType
@ -166,7 +166,7 @@ async def init_test_integration(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [CAMERA_DOMAIN]
config_entry, [Platform.CAMERA]
)
return True
@ -175,7 +175,7 @@ async def init_test_integration(
) -> bool:
"""Unload test config entry."""
await hass.config_entries.async_forward_entry_unload(
config_entry, CAMERA_DOMAIN
config_entry, Platform.CAMERA
)
return True

View File

@ -32,7 +32,7 @@ from homeassistant.components.homeassistant_hardware.util import (
)
from homeassistant.components.update import UpdateDeviceClass
from homeassistant.config_entries import ConfigEntry, ConfigEntryState, ConfigFlow
from homeassistant.const import EVENT_STATE_CHANGED, EntityCategory
from homeassistant.const import EVENT_STATE_CHANGED, EntityCategory, Platform
from homeassistant.core import (
Event,
EventStateChangedData,
@ -173,7 +173,9 @@ async def mock_async_setup_entry(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, ["update"])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.UPDATE]
)
return True

View File

@ -4,7 +4,6 @@ from collections.abc import Generator
import pytest
from homeassistant.components.humidifier import DOMAIN as HUMIDIFIER_DOMAIN
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
@ -45,7 +44,7 @@ def register_test_integration(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [HUMIDIFIER_DOMAIN]
config_entry, [Platform.HUMIDIFIER]
)
return True

View File

@ -6,6 +6,7 @@ import pytest
from homeassistant.components import image
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import (
AddConfigEntryEntitiesCallback,
@ -176,7 +177,7 @@ async def mock_image_config_entry_fixture(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [image.DOMAIN]
config_entry, [Platform.IMAGE]
)
return True
@ -184,7 +185,7 @@ async def mock_image_config_entry_fixture(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Unload test config entry."""
await hass.config_entries.async_unload_platforms(config_entry, [image.DOMAIN])
await hass.config_entries.async_unload_platforms(config_entry, [Platform.IMAGE])
return True
mock_integration(

View File

@ -61,7 +61,7 @@ def mock_setup_integration(hass: HomeAssistant) -> None:
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [CLIMATE_DOMAIN]
config_entry, [Platform.CLIMATE]
)
return True

View File

@ -12,6 +12,7 @@ from homeassistant.components.lock import (
LockEntityFeature,
)
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -99,7 +100,7 @@ async def setup_lock_platform_test_entity(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [LOCK_DOMAIN]
config_entry, [Platform.LOCK]
)
return True

View File

@ -5,6 +5,7 @@ from typing import Any
from aiohttp.test_utils import TestClient
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
@ -110,9 +111,11 @@ async def test_restoring_location(
config_entry = hass.config_entries.async_entries("mobile_app")[1]
# mobile app doesn't support unloading, so we just reload device tracker
await hass.config_entries.async_forward_entry_unload(config_entry, "device_tracker")
await hass.config_entries.async_forward_entry_unload(
config_entry, Platform.DEVICE_TRACKER
)
await hass.config_entries.async_forward_entry_setups(
config_entry, ["device_tracker"]
config_entry, [Platform.DEVICE_TRACKER]
)
await hass.async_block_till_done()

View File

@ -56,7 +56,9 @@ async def help_async_setup_entry_init(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.NOTIFY]
)
return True

View File

@ -32,6 +32,7 @@ from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_UNIT_OF_MEASUREMENT,
CONF_PLATFORM,
Platform,
UnitOfTemperature,
UnitOfVolumeFlowRate,
)
@ -935,7 +936,9 @@ async def test_name(hass: HomeAssistant) -> None:
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.NUMBER]
)
return True
mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View File

@ -31,6 +31,7 @@ from homeassistant.const import (
PERCENTAGE,
STATE_UNKNOWN,
EntityCategory,
Platform,
UnitOfApparentPower,
UnitOfArea,
UnitOfBloodGlucoseConcentration,
@ -2704,7 +2705,7 @@ async def test_name(hass: HomeAssistant) -> None:
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [SENSOR_DOMAIN]
config_entry, [Platform.SENSOR]
)
return True

View File

@ -15,6 +15,7 @@ from homeassistant.components.stt import (
async_get_speech_to_text_engine,
)
from homeassistant.config_entries import ConfigEntry, ConfigEntryState, ConfigFlow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.setup import async_setup_component
@ -122,14 +123,16 @@ async def mock_config_entry_setup(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.STT]
)
return True
async def async_unload_entry_init(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Unload up test config entry."""
await hass.config_entries.async_forward_entry_unload(config_entry, DOMAIN)
await hass.config_entries.async_forward_entry_unload(config_entry, Platform.STT)
return True
mock_integration(

View File

@ -6,7 +6,6 @@ from unittest.mock import AsyncMock
import pytest
from homeassistant.components.todo import (
DOMAIN,
TodoItem,
TodoItemStatus,
TodoListEntity,
@ -38,7 +37,9 @@ def mock_setup_integration(hass: HomeAssistant) -> None:
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.TODO]
)
return True
async def async_unload_entry_init(

View File

@ -25,6 +25,7 @@ from homeassistant.components.tts import (
_get_cache_files,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -230,14 +231,16 @@ async def mock_config_entry_setup(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [TTS_DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.TTS]
)
return True
async def async_unload_entry_init(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Unload test config entry."""
await hass.config_entries.async_forward_entry_unload(config_entry, TTS_DOMAIN)
await hass.config_entries.async_forward_entry_unload(config_entry, Platform.TTS)
return True
mock_integration(

View File

@ -40,6 +40,7 @@ from homeassistant.const import (
STATE_ON,
STATE_UNKNOWN,
EntityCategory,
Platform,
)
from homeassistant.core import HomeAssistant, State, callback
from homeassistant.exceptions import HomeAssistantError
@ -818,7 +819,9 @@ async def test_name(hass: HomeAssistant) -> None:
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.UPDATE]
)
return True
mock_platform(hass, f"{TEST_DOMAIN}.config_flow")

View File

@ -3,7 +3,6 @@
from typing import Any
from homeassistant.components.vacuum import (
DOMAIN,
StateVacuumEntity,
VacuumActivity,
VacuumEntityFeature,
@ -67,7 +66,9 @@ async def help_async_setup_entry_init(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.VACUUM]
)
return True

View File

@ -7,6 +7,7 @@ import pytest
from homeassistant.components.vacuum import DOMAIN as VACUUM_DOMAIN, VacuumEntityFeature
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er, frame
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -68,7 +69,7 @@ async def setup_vacuum_platform_test_entity(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [VACUUM_DOMAIN]
config_entry, [Platform.VACUUM]
)
return True

View File

@ -11,7 +11,7 @@ import pytest
from homeassistant.components import wake_word
from homeassistant.config_entries import ConfigEntry, ConfigEntryState, ConfigFlow
from homeassistant.const import EntityCategory
from homeassistant.const import EntityCategory, Platform
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.setup import async_setup_component
@ -118,7 +118,7 @@ async def mock_config_entry_setup(
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(
config_entry, [wake_word.DOMAIN]
config_entry, [Platform.WAKE_WORD]
)
return True
@ -127,7 +127,7 @@ async def mock_config_entry_setup(
) -> bool:
"""Unload up test config entry."""
await hass.config_entries.async_forward_entry_unload(
config_entry, wake_word.DOMAIN
config_entry, Platform.WAKE_WORD
)
return True

View File

@ -19,7 +19,7 @@ from homeassistant.components.water_heater import (
WaterHeaterEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfTemperature
from homeassistant.const import Platform, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import config_validation as cv
@ -139,7 +139,9 @@ async def test_operation_mode_validation(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.WATER_HEATER]
)
return True
async def async_setup_entry_water_heater_platform(

View File

@ -16,10 +16,10 @@ from homeassistant.components.weather import (
ATTR_FORECAST_NATIVE_WIND_SPEED,
ATTR_FORECAST_UV_INDEX,
ATTR_FORECAST_WIND_BEARING,
DOMAIN,
Forecast,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -84,7 +84,9 @@ async def create_entity(
hass: HomeAssistant, config_entry: ConfigEntry
) -> bool:
"""Set up test config entry."""
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
await hass.config_entries.async_forward_entry_setups(
config_entry, [Platform.WEATHER]
)
return True
async def async_setup_entry_weather_platform(