From b15d92edfdba0062e05900bf5c76374467427726 Mon Sep 17 00:00:00 2001 From: "J.P. Hutchins" <34154542+JPHutchins@users.noreply.github.com> Date: Thu, 10 Dec 2020 01:09:08 -0800 Subject: [PATCH] Fix transmission torrent filtering and sorting (#44069) --- homeassistant/components/transmission/sensor.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/transmission/sensor.py b/homeassistant/components/transmission/sensor.py index ef1e68e2d0a..ea62de71e8d 100644 --- a/homeassistant/components/transmission/sensor.py +++ b/homeassistant/components/transmission/sensor.py @@ -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}",