mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
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:
parent
5d2f8319b1
commit
8ca3310401
@ -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]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user