Remove NZBGet configurable scan interval (#98869)
This commit is contained in:
parent
d638efdcfc
commit
38e013a90e
6 changed files with 5 additions and 103 deletions
|
@ -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
|
||||
|
@ -12,7 +12,6 @@ from .const import (
|
|||
ATTR_SPEED,
|
||||
DATA_COORDINATOR,
|
||||
DATA_UNDO_UPDATE_LISTENER,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
DEFAULT_SPEED_LIMIT,
|
||||
DOMAIN,
|
||||
SERVICE_PAUSE,
|
||||
|
@ -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()
|
||||
|
|
|
@ -6,28 +6,19 @@ from typing import Any
|
|||
|
||||
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__)
|
||||
|
@ -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:
|
||||
|
@ -106,29 +91,3 @@ class NZBGetConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
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))
|
||||
|
|
|
@ -11,7 +11,6 @@ DATA_UNDO_UPDATE_LISTENER = "undo_update_listener"
|
|||
# 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
|
||||
|
|
|
@ -11,7 +11,6 @@ from homeassistant.const import (
|
|||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
|
@ -32,7 +31,6 @@ class NZBGetDataUpdateCoordinator(DataUpdateCoordinator):
|
|||
hass: HomeAssistant,
|
||||
*,
|
||||
config: Mapping[str, Any],
|
||||
options: Mapping[str, Any],
|
||||
) -> None:
|
||||
"""Initialize global NZBGet data updater."""
|
||||
self.nzbget = NZBGetAPI(
|
||||
|
@ -47,13 +45,8 @@ class NZBGetDataUpdateCoordinator(DataUpdateCoordinator):
|
|||
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):
|
||||
|
|
|
@ -23,15 +23,6 @@
|
|||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
"data": {
|
||||
"scan_interval": "Update frequency (seconds)"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"article_cache": {
|
||||
|
|
|
@ -5,7 +5,7 @@ from pynzbgetapi import NZBGetAPIException
|
|||
|
||||
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
|
||||
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue