Code cleanup for transmission integration (#103078)
This commit is contained in:
parent
85d49a2920
commit
61a1245a84
4 changed files with 8 additions and 23 deletions
|
@ -1,7 +1,6 @@
|
|||
"""Support for the Transmission BitTorrent client API."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from functools import partial
|
||||
import logging
|
||||
import re
|
||||
|
@ -22,7 +21,6 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_USERNAME,
|
||||
Platform,
|
||||
)
|
||||
|
@ -69,7 +67,7 @@ MIGRATION_NAME_TO_KEY = {
|
|||
|
||||
SERVICE_BASE_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Exclusive(CONF_ENTRY_ID, "identifier"): selector.ConfigEntrySelector(),
|
||||
vol.Required(CONF_ENTRY_ID): selector.ConfigEntrySelector(),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -135,7 +133,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = coordinator
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
config_entry.add_update_listener(async_options_updated)
|
||||
|
||||
async def add_torrent(service: ServiceCall) -> None:
|
||||
"""Add new torrent to download."""
|
||||
|
@ -244,10 +241,3 @@ async def get_api(
|
|||
except TransmissionError as error:
|
||||
_LOGGER.error(error)
|
||||
raise UnknownError from error
|
||||
|
||||
|
||||
async def async_options_updated(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Triggered by config entry options updates."""
|
||||
coordinator: TransmissionDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator.update_interval = timedelta(seconds=entry.options[CONF_SCAN_INTERVAL])
|
||||
await coordinator.async_request_refresh()
|
||||
|
|
|
@ -55,12 +55,9 @@ class TransmissionFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors = {}
|
||||
|
||||
if user_input is not None:
|
||||
for entry in self._async_current_entries():
|
||||
if (
|
||||
entry.data[CONF_HOST] == user_input[CONF_HOST]
|
||||
and entry.data[CONF_PORT] == user_input[CONF_PORT]
|
||||
):
|
||||
return self.async_abort(reason="already_configured")
|
||||
self._async_abort_entries_match(
|
||||
{CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]}
|
||||
)
|
||||
try:
|
||||
await get_api(self.hass, user_input)
|
||||
|
||||
|
|
|
@ -71,12 +71,12 @@ class TransmissionDataUpdateCoordinator(DataUpdateCoordinator[SessionStats]):
|
|||
data = self.api.session_stats()
|
||||
self.torrents = self.api.get_torrents()
|
||||
self._session = self.api.get_session()
|
||||
except transmission_rpc.TransmissionError as err:
|
||||
raise UpdateFailed("Unable to connect to Transmission client") from err
|
||||
|
||||
self.check_completed_torrent()
|
||||
self.check_started_torrent()
|
||||
self.check_removed_torrent()
|
||||
except transmission_rpc.TransmissionError as err:
|
||||
raise UpdateFailed("Unable to connect to Transmission client") from err
|
||||
|
||||
return data
|
||||
|
||||
|
|
|
@ -30,9 +30,7 @@
|
|||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
"title": "Configure options for Transmission",
|
||||
"data": {
|
||||
"scan_interval": "Update frequency",
|
||||
"limit": "Limit",
|
||||
"order": "Order"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue