* Add phone_modem integration * Use original domain * Add init tests for Modem Caller ID * Clean up tests * Clean up tests * apply suggestions * Fix tests * Make only one instance possible * Allow more than 1 device and remove hangup service * simplify already configured * Update sensor.py * Update config_flow.py * Fix manifest * More cleanup * Fix tests * Ue target * Clean up sensor.py * Minor tweaks * Close modem on restart and unload * Update requirements * fix tests * Bump phone_modem * rework * add typing * use async_setup_platform * typing * tweak * cleanup * fix init * preserve original name * remove callback line * use list of serial devices on host * tweak * rework * Rework for usb dicsovery * Update requirements_test_all.txt * Update config_flow.py * tweaks * tweak * move api out of try statement * suggested tweaks * clean up * typing * tweak * tweak * async name the service
63 lines
2 KiB
Python
63 lines
2 KiB
Python
"""Test Modem Caller ID integration."""
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from phone_modem import exceptions
|
|
|
|
from homeassistant.components.modem_callerid.const import DOMAIN
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import CONF_DATA, _patch_init_modem
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_setup_config(hass: HomeAssistant):
|
|
"""Test Modem Caller ID setup."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data=CONF_DATA,
|
|
)
|
|
entry.add_to_hass(hass)
|
|
mocked_modem = AsyncMock()
|
|
with _patch_init_modem(mocked_modem):
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
assert entry.state == ConfigEntryState.LOADED
|
|
|
|
|
|
async def test_async_setup_entry_not_ready(hass: HomeAssistant):
|
|
"""Test that it throws ConfigEntryNotReady when exception occurs during setup."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data=CONF_DATA,
|
|
)
|
|
entry.add_to_hass(hass)
|
|
|
|
with patch(
|
|
"homeassistant.components.modem_callerid.PhoneModem",
|
|
side_effect=exceptions.SerialError(),
|
|
):
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
assert entry.state == ConfigEntryState.SETUP_ERROR
|
|
assert not hass.data.get(DOMAIN)
|
|
|
|
|
|
async def test_unload_config_entry(hass: HomeAssistant):
|
|
"""Test unload."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
data=CONF_DATA,
|
|
)
|
|
entry.add_to_hass(hass)
|
|
mocked_modem = AsyncMock()
|
|
with _patch_init_modem(mocked_modem):
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
assert entry.state is ConfigEntryState.LOADED
|
|
|
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert entry.state is ConfigEntryState.NOT_LOADED
|
|
assert not hass.data.get(DOMAIN)
|