From 7337c1374745844110e37114c0d2d7f7cf4153af Mon Sep 17 00:00:00 2001 From: Rami Mosleh Date: Fri, 7 Jun 2024 02:44:21 +0400 Subject: [PATCH] Use torrent id to identify torrents that should trigger events (#118897) --- .../components/transmission/coordinator.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/transmission/coordinator.py b/homeassistant/components/transmission/coordinator.py index 1c379685c1c..d6b5b695656 100644 --- a/homeassistant/components/transmission/coordinator.py +++ b/homeassistant/components/transmission/coordinator.py @@ -93,16 +93,14 @@ class TransmissionDataUpdateCoordinator(DataUpdateCoordinator[SessionStats]): def check_completed_torrent(self) -> None: """Get completed torrent functionality.""" - old_completed_torrent_names = { - torrent.name for torrent in self._completed_torrents - } + old_completed_torrents = {torrent.id for torrent in self._completed_torrents} current_completed_torrents = [ torrent for torrent in self.torrents if torrent.status == "seeding" ] for torrent in current_completed_torrents: - if torrent.name not in old_completed_torrent_names: + if torrent.id not in old_completed_torrents: self.hass.bus.fire( EVENT_DOWNLOADED_TORRENT, {"name": torrent.name, "id": torrent.id} ) @@ -111,14 +109,14 @@ class TransmissionDataUpdateCoordinator(DataUpdateCoordinator[SessionStats]): def check_started_torrent(self) -> None: """Get started torrent functionality.""" - old_started_torrent_names = {torrent.name for torrent in self._started_torrents} + old_started_torrents = {torrent.id for torrent in self._started_torrents} current_started_torrents = [ torrent for torrent in self.torrents if torrent.status == "downloading" ] for torrent in current_started_torrents: - if torrent.name not in old_started_torrent_names: + if torrent.id not in old_started_torrents: self.hass.bus.fire( EVENT_STARTED_TORRENT, {"name": torrent.name, "id": torrent.id} ) @@ -127,10 +125,10 @@ class TransmissionDataUpdateCoordinator(DataUpdateCoordinator[SessionStats]): def check_removed_torrent(self) -> None: """Get removed torrent functionality.""" - current_torrent_names = {torrent.name for torrent in self.torrents} + current_torrents = {torrent.id for torrent in self.torrents} for torrent in self._all_torrents: - if torrent.name not in current_torrent_names: + if torrent.id not in current_torrents: self.hass.bus.fire( EVENT_REMOVED_TORRENT, {"name": torrent.name, "id": torrent.id} )