Remove scan_interval from transmission (#98858)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
pull/102655/head
Rami Mosleh 2023-10-24 15:17:46 +03:00 committed by GitHub
parent 8cfb8cb084
commit fea15148a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 29 deletions

View File

@ -7,13 +7,7 @@ from typing import Any
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_SCAN_INTERVAL,
CONF_USERNAME,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
@ -25,7 +19,6 @@ from .const import (
DEFAULT_NAME,
DEFAULT_ORDER,
DEFAULT_PORT,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
SUPPORTED_ORDER_MODES,
)
@ -147,12 +140,6 @@ class TransmissionOptionsFlowHandler(config_entries.OptionsFlow):
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,
vol.Optional(
CONF_LIMIT,
default=self.config_entry.options.get(CONF_LIMIT, DEFAULT_LIMIT),

View File

@ -8,7 +8,7 @@ import transmission_rpc
from transmission_rpc.session import SessionStats
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_SCAN_INTERVAL
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
@ -48,14 +48,9 @@ class TransmissionDataUpdateCoordinator(DataUpdateCoordinator[SessionStats]):
hass,
name=f"{DOMAIN} - {self.host}",
logger=_LOGGER,
update_interval=timedelta(seconds=self.scan_interval),
update_interval=timedelta(seconds=DEFAULT_SCAN_INTERVAL),
)
@property
def scan_interval(self) -> float:
"""Return scan interval."""
return self.config_entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
@property
def limit(self) -> int:
"""Return limit."""

View File

@ -36,7 +36,7 @@ async def async_setup_entry(
config_entry.entry_id
]
dev = [
entities = [
TransmissionSpeedSensor(
coordinator,
"download_speed",
@ -79,7 +79,7 @@ async def async_setup_entry(
),
]
async_add_entities(dev, True)
async_add_entities(entities)
class TransmissionSensor(

View File

@ -27,11 +27,11 @@ async def async_setup_entry(
config_entry.entry_id
]
dev = []
entities = []
for switch_type, switch_name in SWITCH_TYPES.items():
dev.append(TransmissionSwitch(switch_type, switch_name, coordinator))
entities.append(TransmissionSwitch(switch_type, switch_name, coordinator))
async_add_entities(dev, True)
async_add_entities(entities)
class TransmissionSwitch(

View File

@ -76,7 +76,7 @@ async def test_options(hass: HomeAssistant) -> None:
entry = MockConfigEntry(
domain=transmission.DOMAIN,
data=MOCK_CONFIG_DATA,
options={"scan_interval": 120},
options={"limit": 10, "order": "oldest_first"},
)
entry.add_to_hass(hass)
@ -93,11 +93,12 @@ async def test_options(hass: HomeAssistant) -> None:
assert result["step_id"] == "init"
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={"scan_interval": 10}
result["flow_id"], user_input={"limit": 20}
)
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"]["scan_interval"] == 10
assert result["data"]["limit"] == 20
assert result["data"]["order"] == "oldest_first"
async def test_error_on_wrong_credentials(