1 """The Deluge integration."""
3 from __future__
import annotations
6 from ssl
import SSLError
8 from deluge_client.client
import DelugeRPCClient
21 from .const
import CONF_WEB_PORT
22 from .coordinator
import DelugeDataUpdateCoordinator
24 PLATFORMS = [Platform.SENSOR, Platform.SWITCH]
26 _LOGGER = logging.getLogger(__name__)
27 type DelugeConfigEntry = ConfigEntry[DelugeDataUpdateCoordinator]
31 """Set up Deluge from a config entry."""
32 host = entry.data[CONF_HOST]
33 port = entry.data[CONF_PORT]
34 username = entry.data[CONF_USERNAME]
35 password = entry.data[CONF_PASSWORD]
36 api = await hass.async_add_executor_job(
37 DelugeRPCClient, host, port, username, password
39 api.web_port = entry.data[CONF_WEB_PORT]
41 await hass.async_add_executor_job(api.connect)
42 except (ConnectionRefusedError, TimeoutError, SSLError)
as ex:
44 except Exception
as ex:
45 if type(ex).__name__ ==
"BadLoginError":
47 "Credentials for Deluge client are not valid"
49 _LOGGER.error(
"Unknown error connecting to Deluge: %s", ex)
52 await coordinator.async_config_entry_first_refresh()
53 entry.runtime_data = coordinator
54 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
60 """Unload a config entry."""
61 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, DelugeConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, DelugeConfigEntry entry)