Fix lingering timer in sabnzbd (#92462)
This commit is contained in:
parent
88019d70fe
commit
71b86e9f97
3 changed files with 23 additions and 7 deletions
|
@ -237,7 +237,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
except SabnzbdApiException as err:
|
||||
_LOGGER.error(err)
|
||||
|
||||
async_track_time_interval(hass, async_update_sabnzbd, UPDATE_INTERVAL)
|
||||
entry.async_on_unload(
|
||||
async_track_time_interval(hass, async_update_sabnzbd, UPDATE_INTERVAL)
|
||||
)
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
|
|
14
tests/components/sabnzbd/conftest.py
Normal file
14
tests/components/sabnzbd/conftest.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
"""Configuration for Sabnzbd tests."""
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.sabnzbd.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
yield mock_setup_entry
|
|
@ -1,7 +1,8 @@
|
|||
"""Define tests for the Sabnzbd config flow."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from pysabnzbd import SabnzbdApiException
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.sabnzbd import DOMAIN
|
||||
|
@ -31,8 +32,10 @@ VALID_CONFIG_OLD = {
|
|||
CONF_SSL: False,
|
||||
}
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
async def test_create_entry(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_create_entry(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
||||
"""Test that the user step works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
|
@ -43,10 +46,7 @@ async def test_create_entry(hass: HomeAssistant) -> None:
|
|||
with patch(
|
||||
"homeassistant.components.sabnzbd.sab.SabnzbdApi.check_available",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.sabnzbd.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
VALID_CONFIG,
|
||||
|
|
Loading…
Add table
Reference in a new issue