Fix transmission torrent filtering and sorting (#44069)

pull/44175/head
J.P. Hutchins 2020-12-10 01:09:08 -08:00 committed by Paulus Schoutsen
parent 29e3fbe568
commit 6ea3c671e9
1 changed files with 5 additions and 7 deletions

View File

@ -145,12 +145,10 @@ class TransmissionTorrentsSensor(TransmissionSensor):
@property
def device_state_attributes(self):
"""Return the state attributes, if any."""
limit = self._tm_client.config_entry.options[CONF_LIMIT]
order = self._tm_client.config_entry.options[CONF_ORDER]
torrents = self._tm_client.api.torrents[0:limit]
info = _torrents_info(
torrents,
order=order,
torrents=self._tm_client.api.torrents,
order=self._tm_client.config_entry.options[CONF_ORDER],
limit=self._tm_client.config_entry.options[CONF_LIMIT],
statuses=self.SUBTYPE_MODES[self._sub_type],
)
return {
@ -173,11 +171,11 @@ def _filter_torrents(torrents, statuses=None):
]
def _torrents_info(torrents, order, statuses=None):
def _torrents_info(torrents, order, limit, statuses=None):
infos = {}
torrents = _filter_torrents(torrents, statuses)
torrents = SUPPORTED_ORDER_MODES[order](torrents)
for torrent in _filter_torrents(torrents, statuses):
for torrent in torrents[:limit]:
info = infos[torrent.name] = {
"added_date": torrent.addedDate,
"percent_done": f"{torrent.percentDone * 100:.2f}",