Catch exception when user has no lastfm friends (#94235)

This commit is contained in:
Joost Lekkerkerker 2023-06-08 16:08:18 +02:00 committed by GitHub
parent 758eb5e510
commit 20449d1f01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Any
from pylast import LastFMNetwork, User, WSError
from pylast import LastFMNetwork, PyLastError, User, WSError
import voluptuous as vol
from homeassistant.config_entries import (
@ -135,7 +135,7 @@ class LastFmConfigFlowHandler(ConfigFlow, domain=DOMAIN):
SelectOptionDict(value=friend.name, label=friend.get_name(True))
for friend in friends_response
]
except WSError:
except PyLastError:
friends = []
return self.async_show_form(
step_id="friends",
@ -207,7 +207,7 @@ class LastFmOptionsFlowHandler(OptionsFlowWithConfigEntry):
SelectOptionDict(value=friend.name, label=friend.get_name(True))
for friend in friends_response
]
except WSError:
except PyLastError:
friends = []
else:
friends = []

View file

@ -1,7 +1,7 @@
"""The tests for lastfm."""
from unittest.mock import patch
from pylast import Track, WSError
from pylast import PyLastError, Track
from homeassistant.components.lastfm.const import CONF_MAIN_USER, CONF_USERS
from homeassistant.const import CONF_API_KEY
@ -65,7 +65,7 @@ class MockUser:
def get_friends(self):
"""Get mock friends."""
if self._has_friends is False:
raise WSError("network", "status", "Page not found")
raise PyLastError("network", "status", "Page not found")
return [MockUser(None, None, True, USERNAME_2)]