2018-06-14 19:17:54 +00:00
|
|
|
"""Tests for the Sonos config flow."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
2018-08-13 09:27:18 +00:00
|
|
|
from homeassistant import config_entries, data_entry_flow
|
2018-07-23 13:08:03 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2018-06-14 19:17:54 +00:00
|
|
|
from homeassistant.components import sonos
|
|
|
|
|
|
|
|
from tests.common import mock_coro
|
|
|
|
|
|
|
|
|
|
|
|
async def test_creating_entry_sets_up_media_player(hass):
|
|
|
|
"""Test setting up Sonos loads the media player."""
|
2019-02-01 23:45:44 +00:00
|
|
|
with patch('homeassistant.components.sonos.media_player.async_setup_entry',
|
2018-06-14 19:17:54 +00:00
|
|
|
return_value=mock_coro(True)) as mock_setup, \
|
2018-09-20 21:50:11 +00:00
|
|
|
patch('pysonos.discover', return_value=True):
|
2018-08-13 09:27:18 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
sonos.DOMAIN, context={'source': config_entries.SOURCE_USER})
|
2018-09-21 14:34:37 +00:00
|
|
|
|
|
|
|
# Confirmation form
|
|
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
|
|
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
result['flow_id'], {})
|
2018-06-14 19:17:54 +00:00
|
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(mock_setup.mock_calls) == 1
|
2018-07-23 13:08:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_configuring_sonos_creates_entry(hass):
|
|
|
|
"""Test that specifying config will create an entry."""
|
|
|
|
with patch('homeassistant.components.sonos.async_setup_entry',
|
|
|
|
return_value=mock_coro(True)) as mock_setup, \
|
2018-09-20 21:50:11 +00:00
|
|
|
patch('pysonos.discover', return_value=True):
|
2018-07-23 13:08:03 +00:00
|
|
|
await async_setup_component(hass, sonos.DOMAIN, {
|
|
|
|
'sonos': {
|
2019-04-26 06:56:43 +00:00
|
|
|
'media_player': {
|
|
|
|
'interface_addr': '127.0.0.1',
|
|
|
|
}
|
2018-07-23 13:08:03 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(mock_setup.mock_calls) == 1
|
|
|
|
|
|
|
|
|
|
|
|
async def test_not_configuring_sonos_not_creates_entry(hass):
|
|
|
|
"""Test that no config will not create an entry."""
|
|
|
|
with patch('homeassistant.components.sonos.async_setup_entry',
|
|
|
|
return_value=mock_coro(True)) as mock_setup, \
|
2018-09-20 21:50:11 +00:00
|
|
|
patch('pysonos.discover', return_value=True):
|
2018-07-23 13:08:03 +00:00
|
|
|
await async_setup_component(hass, sonos.DOMAIN, {})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(mock_setup.mock_calls) == 0
|