Fix qbittorrent error when torrent count is 0 (#126146)

Fix handling of `NoneType` for torrents in `count_torrents_in_states` function

Added a check to handle cases where the 'torrents' data is None, avoiding a `TypeError` when attempting to get the length of a `NoneType` object. The function now returns 0 if 'torrents' is None, ensuring robust behavior when no torrent data is available.
This commit is contained in:
Arun Philip 2024-09-19 04:34:27 -04:00 committed by GitHub
parent 5d2f8319b1
commit 8ca3310401
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -177,8 +177,12 @@ def count_torrents_in_states(
# When torrents are not in the returned data, there are none, return 0.
try:
torrents = cast(Mapping[str, Mapping], coordinator.data.get("torrents"))
if torrents is None:
return 0
if not states:
return len(torrents)
return len(
[torrent for torrent in torrents.values() if torrent.get("state") in states]
)