Skip to content

Commit

Permalink
Remove NZBGet configurable scan interval (#98869)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Sep 13, 2023
1 parent d638efd commit 38e013a
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 103 deletions.
12 changes: 1 addition & 11 deletions homeassistant/components/nzbget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_SCAN_INTERVAL, Platform
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
Expand All @@ -12,7 +12,6 @@
ATTR_SPEED,
DATA_COORDINATOR,
DATA_UNDO_UPDATE_LISTENER,
DEFAULT_SCAN_INTERVAL,
DEFAULT_SPEED_LIMIT,
DOMAIN,
SERVICE_PAUSE,
Expand All @@ -34,18 +33,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up NZBGet from a config entry."""
hass.data.setdefault(DOMAIN, {})

if not entry.options:
options = {
CONF_SCAN_INTERVAL: entry.data.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
}
hass.config_entries.async_update_entry(entry, options=options)

coordinator = NZBGetDataUpdateCoordinator(
hass,
config=entry.data,
options=entry.options,
)

await coordinator.async_config_entry_first_refresh()
Expand Down
45 changes: 2 additions & 43 deletions homeassistant/components/nzbget/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,19 @@

import voluptuous as vol

from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
CONF_PASSWORD,
CONF_PORT,
CONF_SCAN_INTERVAL,
CONF_SSL,
CONF_USERNAME,
CONF_VERIFY_SSL,
)
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult

from .const import (
DEFAULT_NAME,
DEFAULT_PORT,
DEFAULT_SCAN_INTERVAL,
DEFAULT_SSL,
DEFAULT_VERIFY_SSL,
DOMAIN,
)
from .const import DEFAULT_NAME, DEFAULT_PORT, DEFAULT_SSL, DEFAULT_VERIFY_SSL, DOMAIN
from .coordinator import NZBGetAPI, NZBGetAPIException

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -55,12 +46,6 @@ class NZBGetConfigFlow(ConfigFlow, domain=DOMAIN):

VERSION = 1

@staticmethod
@callback
def async_get_options_flow(config_entry: ConfigEntry) -> NZBGetOptionsFlowHandler:
"""Get the options flow for this handler."""
return NZBGetOptionsFlowHandler(config_entry)

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
Expand Down Expand Up @@ -106,29 +91,3 @@ async def async_step_user(
data_schema=vol.Schema(data_schema),
errors=errors or {},
)


class NZBGetOptionsFlowHandler(OptionsFlow):
"""Handle NZBGet client options."""

def __init__(self, config_entry: ConfigEntry) -> None:
"""Initialize options flow."""
self.config_entry = config_entry

async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Manage NZBGet options."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

options = {
vol.Optional(
CONF_SCAN_INTERVAL,
default=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
): int,
}

return self.async_show_form(step_id="init", data_schema=vol.Schema(options))
1 change: 0 additions & 1 deletion homeassistant/components/nzbget/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# Defaults
DEFAULT_NAME = "NZBGet"
DEFAULT_PORT = 6789
DEFAULT_SCAN_INTERVAL = 5 # time in seconds
DEFAULT_SPEED_LIMIT = 1000 # 1 Megabyte/Sec
DEFAULT_SSL = False
DEFAULT_VERIFY_SSL = False
Expand Down
9 changes: 1 addition & 8 deletions homeassistant/components/nzbget/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_SCAN_INTERVAL,
CONF_SSL,
CONF_USERNAME,
CONF_VERIFY_SSL,
Expand All @@ -32,7 +31,6 @@ def __init__(
hass: HomeAssistant,
*,
config: Mapping[str, Any],
options: Mapping[str, Any],
) -> None:
"""Initialize global NZBGet data updater."""
self.nzbget = NZBGetAPI(
Expand All @@ -47,13 +45,8 @@ def __init__(
self._completed_downloads_init = False
self._completed_downloads = set[tuple]()

update_interval = timedelta(seconds=options[CONF_SCAN_INTERVAL])

super().__init__(
hass,
_LOGGER,
name=DOMAIN,
update_interval=update_interval,
hass, _LOGGER, name=DOMAIN, update_interval=timedelta(seconds=5)
)

def _check_completed_downloads(self, history):
Expand Down
9 changes: 0 additions & 9 deletions homeassistant/components/nzbget/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
"unknown": "[%key:common::config_flow::error::unknown%]"
}
},
"options": {
"step": {
"init": {
"data": {
"scan_interval": "Update frequency (seconds)"
}
}
}
},
"entity": {
"sensor": {
"article_cache": {
Expand Down
32 changes: 1 addition & 31 deletions tests/components/nzbget/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from homeassistant.components.nzbget.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_VERIFY_SSL
from homeassistant.const import CONF_VERIFY_SSL
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType

Expand Down Expand Up @@ -122,33 +122,3 @@ async def test_user_form_single_instance_allowed(hass: HomeAssistant) -> None:
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"


async def test_options_flow(hass: HomeAssistant, nzbget_api) -> None:
"""Test updating options."""
entry = MockConfigEntry(
domain=DOMAIN,
data=ENTRY_CONFIG,
options={CONF_SCAN_INTERVAL: 5},
)
entry.add_to_hass(hass)

with patch("homeassistant.components.nzbget.PLATFORMS", []):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert entry.options[CONF_SCAN_INTERVAL] == 5

result = await hass.config_entries.options.async_init(entry.entry_id)
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "init"

with _patch_async_setup_entry():
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={CONF_SCAN_INTERVAL: 15},
)
await hass.async_block_till_done()

assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"][CONF_SCAN_INTERVAL] == 15

0 comments on commit 38e013a

Please sign in to comment.