Ensure entity platform in universal tests (#135727)

This commit is contained in:
G Johansson 2025-01-17 09:10:09 +01:00 committed by GitHub
parent 0f8785d8bc
commit 8e39c65759
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,7 +27,7 @@ from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.event import async_track_state_change_event from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import async_mock_service, get_fixture_path from tests.common import MockEntityPlatform, async_mock_service, get_fixture_path
CONFIG_CHILDREN_ONLY = { CONFIG_CHILDREN_ONLY = {
"name": "test", "name": "test",
@ -74,6 +74,7 @@ class MockMediaPlayer(media_player.MediaPlayerEntity):
self._shuffle = False self._shuffle = False
self._sound_mode = None self._sound_mode = None
self._repeat = None self._repeat = None
self.platform = MockEntityPlatform(hass)
self.service_calls = { self.service_calls = {
"turn_on": async_mock_service( "turn_on": async_mock_service(
@ -361,26 +362,10 @@ async def test_config_bad_key(hass: HomeAssistant) -> None:
async def test_platform_setup(hass: HomeAssistant) -> None: async def test_platform_setup(hass: HomeAssistant) -> None:
"""Test platform setup.""" """Test platform setup."""
config = {"name": "test", "platform": "universal"} config = {"name": "test", "platform": "universal"}
bad_config = {"platform": "universal"} assert await async_setup_component(hass, "media_player", {"media_player": config})
entities = [] await hass.async_block_till_done()
assert hass.states.async_all() != []
def add_entities(new_entities): assert hass.states.get("media_player.test") is not None
"""Add devices to list."""
entities.extend(new_entities)
setup_ok = True
try:
await universal.async_setup_platform(
hass, validate_config(bad_config), add_entities
)
except MultipleInvalid:
setup_ok = False
assert not setup_ok
assert len(entities) == 0
await universal.async_setup_platform(hass, validate_config(config), add_entities)
assert len(entities) == 1
assert entities[0].name == "test"
async def test_master_state(hass: HomeAssistant) -> None: async def test_master_state(hass: HomeAssistant) -> None:
@ -461,11 +446,10 @@ async def test_active_child_state(hass: HomeAssistant, mock_states) -> None:
async def test_name(hass: HomeAssistant) -> None: async def test_name(hass: HomeAssistant) -> None:
"""Test name property.""" """Test name property."""
config = validate_config(CONFIG_CHILDREN_ONLY) assert await async_setup_component(
hass, "media_player", {"media_player": CONFIG_CHILDREN_ONLY}
ump = universal.UniversalMediaPlayer(hass, config) )
assert hass.states.get("media_player.test") is not None
assert config["name"] == ump.name
async def test_polling(hass: HomeAssistant) -> None: async def test_polling(hass: HomeAssistant) -> None: