Remove external library discovery call in Sonos (#61461)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
jjlawren 2021-12-10 15:28:47 -06:00 committed by GitHub
parent d4e5c1832e
commit 6d54261322
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 20 deletions

View file

@ -1,16 +1,26 @@
"""Tests for the Sonos config flow."""
from unittest.mock import patch
from homeassistant import config_entries, data_entry_flow
from homeassistant.components import sonos
from homeassistant import config_entries, core, data_entry_flow
from homeassistant.components import sonos, zeroconf
from homeassistant.setup import async_setup_component
async def test_creating_entry_sets_up_media_player(hass):
async def test_creating_entry_sets_up_media_player(
hass: core.HomeAssistant, zeroconf_payload: zeroconf.ZeroconfServiceInfo
):
"""Test setting up Sonos loads the media player."""
# Initiate a discovery to allow a user config flow
await hass.config_entries.flow.async_init(
sonos.DOMAIN,
context={"source": config_entries.SOURCE_ZEROCONF},
data=zeroconf_payload,
)
with patch(
"homeassistant.components.sonos.media_player.async_setup_entry",
) as mock_setup, patch("soco.discover", return_value=True):
) as mock_setup:
result = await hass.config_entries.flow.async_init(
sonos.DOMAIN, context={"source": config_entries.SOURCE_USER}
)
@ -26,12 +36,12 @@ async def test_creating_entry_sets_up_media_player(hass):
assert len(mock_setup.mock_calls) == 1
async def test_configuring_sonos_creates_entry(hass):
async def test_configuring_sonos_creates_entry(hass: core.HomeAssistant):
"""Test that specifying config will create an entry."""
with patch(
"homeassistant.components.sonos.async_setup_entry",
return_value=True,
) as mock_setup, patch("soco.discover", return_value=True):
) as mock_setup:
await async_setup_component(
hass,
sonos.DOMAIN,
@ -42,12 +52,12 @@ async def test_configuring_sonos_creates_entry(hass):
assert len(mock_setup.mock_calls) == 1
async def test_not_configuring_sonos_not_creates_entry(hass):
async def test_not_configuring_sonos_not_creates_entry(hass: core.HomeAssistant):
"""Test that no config will not create an entry."""
with patch(
"homeassistant.components.sonos.async_setup_entry",
return_value=True,
) as mock_setup, patch("soco.discover", return_value=True):
) as mock_setup:
await async_setup_component(hass, sonos.DOMAIN, {})
await hass.async_block_till_done()