hass-core/tests/components/anthemav/test_init.py
Alex Henry f5c6a6be3a
Add config flow to AnthemAV integration (#53268)
* Add config flow to AnthemAV integration

* Add importing of existing configuration

* Change setting to optional and add default value

* Use entity attribute

* Reduce changes by removing additional media player properties

* Remove title from translation

* Refactor config flow and fix PR comments

* Fix a failing test because of wrong renaming

* Add typing and use existing class and enum

* Bump dependency to v1.3.1

* Remove unecessary async_reload_entry

* Fix requirements_test_all after rebase

* Add const for timeout and remove async_block in test

* Reapply CodeOwner and configflow after rebase

* Remove name from configflow

* Fix manifest prettier failure

* Simplify code and avoid catching broad exception

* Removed unused strings and translations

* Avoid asserting hass.data
2022-06-30 07:13:08 -07:00

65 lines
2.2 KiB
Python

"""Test the Anthem A/V Receivers config flow."""
from unittest.mock import ANY, AsyncMock, patch
from homeassistant import config_entries
from homeassistant.components.anthemav.const import CONF_MODEL, DOMAIN
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def test_load_unload_config_entry(
hass: HomeAssistant, mock_connection_create: AsyncMock, mock_anthemav: AsyncMock
) -> None:
"""Test load and unload AnthemAv component."""
mock_config_entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_HOST: "1.1.1.1",
CONF_PORT: 14999,
CONF_NAME: "Anthem AV",
CONF_MAC: "aabbccddeeff",
CONF_MODEL: "MRX 520",
},
)
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
# assert avr is created
mock_connection_create.assert_called_with(
host="1.1.1.1", port=14999, update_callback=ANY
)
assert mock_config_entry.state == config_entries.ConfigEntryState.LOADED
# unload
await hass.config_entries.async_unload(mock_config_entry.entry_id)
await hass.async_block_till_done()
# assert unload and avr is closed
assert mock_config_entry.state == config_entries.ConfigEntryState.NOT_LOADED
mock_anthemav.close.assert_called_once()
async def test_config_entry_not_ready(hass: HomeAssistant) -> None:
"""Test AnthemAV configuration entry not ready."""
mock_config_entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_HOST: "1.1.1.1",
CONF_PORT: 14999,
CONF_NAME: "Anthem AV",
CONF_MAC: "aabbccddeeff",
CONF_MODEL: "MRX 520",
},
)
with patch(
"anthemav.Connection.create",
side_effect=OSError,
):
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert mock_config_entry.state is config_entries.ConfigEntryState.SETUP_RETRY