From 711498793a370f3cd532f70ae4a709c5ab29fbef Mon Sep 17 00:00:00 2001 From: Joe Neuman Date: Tue, 2 Jan 2024 15:19:00 -0800 Subject: [PATCH] Fix qBittorrent torrent count when empty (#106903) * Fix qbittorrent torrent cound when empty * lint fix * Change based on comment --- homeassistant/components/qbittorrent/sensor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homeassistant/components/qbittorrent/sensor.py b/homeassistant/components/qbittorrent/sensor.py index 9373aec8544..78e8ba59d44 100644 --- a/homeassistant/components/qbittorrent/sensor.py +++ b/homeassistant/components/qbittorrent/sensor.py @@ -165,6 +165,10 @@ def count_torrents_in_states( coordinator: QBittorrentDataCoordinator, states: list[str] ) -> int: """Count the number of torrents in specified states.""" + # When torrents are not in the returned data, there are none, return 0. + if "torrents" not in coordinator.data: + return 0 + if not states: return len(coordinator.data["torrents"])