Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ homeassistant/components/tplink/* @rytilahti
homeassistant/components/traccar/* @ludeeus
homeassistant/components/tradfri/* @ggravlingen
homeassistant/components/trafikverket_train/* @endor-force
homeassistant/components/transmission/* @engrbm87
homeassistant/components/transmission/* @engrbm87 @JPHutchins
homeassistant/components/tts/* @robbiet480
homeassistant/components/twentemilieu/* @frenck
homeassistant/components/twilio_call/* @robbiet480
Expand Down
27 changes: 27 additions & 0 deletions homeassistant/components/transmission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def __init__(self, hass, config, api):
self._api = api
self.completed_torrents = []
self.started_torrents = []
self.started_torrent_dict = {}

@property
def host(self):
Expand All @@ -250,6 +251,7 @@ def update(self):
self.torrents = self._api.get_torrents()
self.session = self._api.get_session()

self.check_started_torrent_info()
self.check_completed_torrent()
self.check_started_torrent()
_LOGGER.debug("Torrent Data for %s Updated", self.host)
Expand Down Expand Up @@ -301,6 +303,31 @@ def check_started_torrent(self):
self.hass.bus.fire("transmission_started_torrent", {"name": var})
self.started_torrents = actual_started_torrents

def check_started_torrent_info(self):
"""Get started torrent info functionality."""
all_torrents = self._api.get_torrents()
current_down = {}

for torrent in all_torrents:
if torrent.status == "downloading":
info = self.started_torrent_dict[torrent.name] = {
"added_date": torrent.addedDate,
"percent_done": f"{torrent.percentDone * 100:.2f}",
}
try:
info["eta"] = str(torrent.eta)
except ValueError:
info["eta"] = "unknown"

current_down[torrent.name] = True

elif torrent.name in self.started_torrent_dict:
self.started_torrent_dict.pop(torrent.name)

for torrent in list(self.started_torrent_dict):
if torrent not in current_down:
self.started_torrent_dict.pop(torrent)

def get_started_torrent_count(self):
"""Get the number of started torrents."""
return len(self.started_torrents)
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/transmission/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DEFAULT_PORT = 9091
DEFAULT_SCAN_INTERVAL = 120

STATE_ATTR_TORRENT_INFO = "torrent_info"
ATTR_TORRENT = "torrent"
SERVICE_ADD_TORRENT = "add_torrent"

Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/transmission/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"dependencies": [],
"codeowners": [
"@engrbm87"
"@engrbm87",
"@JPHutchins"
]
}
}
10 changes: 9 additions & 1 deletion homeassistant/components/transmission/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity

from .const import DOMAIN, SENSOR_TYPES
from .const import DOMAIN, SENSOR_TYPES, STATE_ATTR_TORRENT_INFO


_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -82,6 +83,13 @@ def available(self):
"""Could the device be accessed during the last update call."""
return self._tm_client.api.available

@property
def device_state_attributes(self):
"""Return the state attributes, if any."""
if self._tm_client.api.started_torrent_dict and self.type == "started_torrents":
return {STATE_ATTR_TORRENT_INFO: self._tm_client.api.started_torrent_dict}
return None

Comment thread
JPHutchins marked this conversation as resolved.
async def async_added_to_hass(self):
"""Handle entity which will be added."""
async_dispatcher_connect(
Expand Down