mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Complete ESPHome media_player coverage (#114352)
This commit is contained in:
parent
ee535ee611
commit
dee99c764b
@ -1,6 +1,6 @@
|
||||
"""Test ESPHome media_players."""
|
||||
|
||||
from unittest.mock import AsyncMock, Mock, call
|
||||
from unittest.mock import AsyncMock, Mock, call, patch
|
||||
|
||||
from aioesphomeapi import (
|
||||
APIClient,
|
||||
@ -152,6 +152,8 @@ async def test_media_player_entity_with_source(
|
||||
mock_generic_device_entry,
|
||||
) -> None:
|
||||
"""Test a generic media_player entity media source."""
|
||||
await async_setup_component(hass, "media_source", {"media_source": {}})
|
||||
await hass.async_block_till_done()
|
||||
esphome_platform_mock = Mock(
|
||||
async_get_media_browser_root_object=AsyncMock(
|
||||
return_value=[
|
||||
@ -221,6 +223,33 @@ async def test_media_player_entity_with_source(
|
||||
)
|
||||
|
||||
mock_client.media_player_command.reset_mock()
|
||||
|
||||
play_media = media_source.PlayMedia(
|
||||
url="http://www.example.com/xy.mp3",
|
||||
mime_type="audio/mp3",
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.media_source.async_resolve_media",
|
||||
return_value=play_media,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
MEDIA_PLAYER_DOMAIN,
|
||||
SERVICE_PLAY_MEDIA,
|
||||
{
|
||||
ATTR_ENTITY_ID: "media_player.test_mymedia_player",
|
||||
ATTR_MEDIA_CONTENT_TYPE: "audio/mp3",
|
||||
ATTR_MEDIA_CONTENT_ID: "media-source://local/xy",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mock_client.media_player_command.assert_has_calls(
|
||||
[call(1, media_url="http://www.example.com/xy.mp3")]
|
||||
)
|
||||
|
||||
client = await hass_ws_client()
|
||||
await client.send_json(
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user