Skip to content

Commit

Permalink
Fix qBittorrent torrent count when empty (home-assistant#106903)
Browse files Browse the repository at this point in the history
* Fix qbittorrent torrent cound when empty

* lint fix

* Change based on comment
  • Loading branch information
finder39 authored Jan 2, 2024
1 parent f66438b commit 7114987
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions homeassistant/components/qbittorrent/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down

0 comments on commit 7114987

Please sign in to comment.