1 """Support for monitoring the qBittorrent API."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
16 from .const
import DOMAIN
17 from .coordinator
import QBittorrentDataCoordinator
20 @dataclass(frozen=True, kw_only=True)
22 """Describes qBittorren switch."""
24 is_on_func: Callable[[QBittorrentDataCoordinator], bool]
25 turn_on_fn: Callable[[QBittorrentDataCoordinator],
None]
26 turn_off_fn: Callable[[QBittorrentDataCoordinator],
None]
27 toggle_func: Callable[[QBittorrentDataCoordinator],
None]
30 SWITCH_TYPES: tuple[QBittorrentSwitchEntityDescription, ...] = (
32 key=
"alternative_speed",
33 translation_key=
"alternative_speed",
34 icon=
"mdi:speedometer-slow",
35 is_on_func=
lambda coordinator: coordinator.get_alt_speed_enabled(),
36 turn_on_fn=
lambda coordinator: coordinator.set_alt_speed_enabled(
True),
37 turn_off_fn=
lambda coordinator: coordinator.set_alt_speed_enabled(
False),
38 toggle_func=
lambda coordinator: coordinator.toggle_alt_speed_enabled(),
45 config_entry: ConfigEntry,
46 async_add_entities: AddEntitiesCallback,
48 """Set up qBittorrent switch entries."""
50 coordinator: QBittorrentDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
54 for description
in SWITCH_TYPES
59 """Representation of a qBittorrent switch."""
61 _attr_has_entity_name =
True
62 entity_description: QBittorrentSwitchEntityDescription
66 coordinator: QBittorrentDataCoordinator,
67 config_entry: ConfigEntry,
68 entity_description: QBittorrentSwitchEntityDescription,
70 """Initialize qBittorrent switch."""
73 self.
_attr_unique_id_attr_unique_id = f
"{config_entry.entry_id}-{entity_description.key}"
75 entry_type=DeviceEntryType.SERVICE,
76 identifiers={(DOMAIN, config_entry.entry_id)},
77 manufacturer=
"QBittorrent",
82 """Return true if device is on."""
86 """Turn on this switch."""
87 await self.
hasshasshass.async_add_executor_job(
93 """Turn off this switch."""
94 await self.
hasshasshass.async_add_executor_job(
100 """Toggle the device."""
101 await self.
hasshasshass.async_add_executor_job(
None async_turn_off(self, **Any kwargs)
None async_toggle(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None __init__(self, QBittorrentDataCoordinator coordinator, ConfigEntry config_entry, QBittorrentSwitchEntityDescription entity_description)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)