mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix transmission torrent filtering and sorting (#44069)
This commit is contained in:
parent
e09234ffae
commit
b15d92edfd
@ -145,12 +145,10 @@ class TransmissionTorrentsSensor(TransmissionSensor):
|
|||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the state attributes, if any."""
|
"""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(
|
info = _torrents_info(
|
||||||
torrents,
|
torrents=self._tm_client.api.torrents,
|
||||||
order=order,
|
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],
|
statuses=self.SUBTYPE_MODES[self._sub_type],
|
||||||
)
|
)
|
||||||
return {
|
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 = {}
|
infos = {}
|
||||||
torrents = _filter_torrents(torrents, statuses)
|
torrents = _filter_torrents(torrents, statuses)
|
||||||
torrents = SUPPORTED_ORDER_MODES[order](torrents)
|
torrents = SUPPORTED_ORDER_MODES[order](torrents)
|
||||||
for torrent in _filter_torrents(torrents, statuses):
|
for torrent in torrents[:limit]:
|
||||||
info = infos[torrent.name] = {
|
info = infos[torrent.name] = {
|
||||||
"added_date": torrent.addedDate,
|
"added_date": torrent.addedDate,
|
||||||
"percent_done": f"{torrent.percentDone * 100:.2f}",
|
"percent_done": f"{torrent.percentDone * 100:.2f}",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user